[*] Remove redundant sync primitive from AuFuture

[*] Amend AwaitableVoid
This commit is contained in:
Reece Wilson 2023-07-08 12:58:40 +01:00
parent 730d338c17
commit 69a5bb8061

View File

@ -188,12 +188,6 @@ protected:
return value;
}
bool WaitOn()
{
this->event->Wait();
return this->bComplete;
}
bool IsFinished()
{
return this->bComplete || this->bFailed;
@ -204,11 +198,6 @@ protected:
return this->bFailed;
}
AuThreading::IWaitable *GetWaitOnInterface()
{
return this->event.AsPointer();
}
private:
void ExchangeDone()
@ -235,8 +224,6 @@ private:
{
if (AuAsync::GetCurrentWorkerPId() == this->pid)
{
this->event->Set();
if (!this->onFailure && !this->callback)
{
DoWaterFalls();
@ -319,23 +306,20 @@ private:
AuDebug::DecMemoryCrunch();
}
AuFuture() :
event(false, false, true)
AuFuture()
{
this->pid = AuAsync::GetCurrentWorkerPId();
}
AuFuture(AuConsumer<Move_t> callback) :
callback(callback),
event(false, false, true)
callback(callback)
{
this->pid = AuAsync::GetCurrentWorkerPId();
}
AuFuture(AuConsumer<Move_t> callback, ErrorCallback_f onFailure) :
callback(callback),
onFailure(onFailure),
event(false, false, true)
onFailure(onFailure)
{
this->pid = AuAsync::GetCurrentWorkerPId();
}
@ -344,7 +328,6 @@ private:
ErrorStore_t errorValue;
AuThreadPrimitives::Mutex mutex;
AuThreadPrimitives::Event event;
CompleteCallback_f callback;
ErrorCallback_f onFailure;
@ -352,7 +335,6 @@ private:
AuOptionalEx<AuAsync::WorkerPId_t> pid; // todo: make weak?
AuList<AuConsumer<bool, bool>> waterfall;
AuUInt8 bComplete {};
AuUInt8 bFailed {};
AuUInt8 bDone {};
@ -614,12 +596,6 @@ namespace __detail
return future.GetValue();
}
template<typename A, typename B>
static bool WaitOn(AuFuture<A, B> &future)
{
return future.GetValue();
}
template<typename A, typename B>
static bool IsFinished(AuFuture<A, B> &future)
{
@ -631,12 +607,6 @@ namespace __detail
{
return future.IsFailed();
}
template<typename A, typename B>
static AuThreading::IWaitable *GetWaitOnInterface(AuFuture<A, B> &future)
{
return future.event.AsPointer();
}
};
}
@ -792,14 +762,25 @@ namespace __detail
h.resume();
});
pFuture->OnFailure([=]()
if constexpr (!AuIsVoid_v<B>)
{
h.resume();
});
pFuture->OnFailure([=](const B &)
{
h.resume();
});
}
else
{
pFuture->OnFailure([=]()
{
h.resume();
});
}
}
void await_resume()
bool await_resume()
{
return !__detail::FutureAccessor::IsFailed(*pFuture.get());
}
};
}