[*] Update LoopQueue semantics. Pending NT port

This commit is contained in:
Reece Wilson 2022-04-15 12:45:47 +01:00
parent 499aaeedab
commit 2ce106d8a9
3 changed files with 62 additions and 22 deletions

View File

@ -23,7 +23,7 @@ namespace Aurora::Loop
* @brief called under Wait[All/Any[Ex]] once an object is signaled
* @return should pop from ILoopQueue
*/
AUI_METHOD(bool, OnFinished, (const AuSPtr<ILoopSource> &, source)),
AUI_METHOD(bool, OnFinished, (const AuSPtr<ILoopSource> &, source, AuUInt8, position)),
/**
* @brief called under Wait[All/Any[Ex]] once an object timesout before being evicted

View File

@ -53,6 +53,8 @@ namespace Aurora::IPC
return false;
}
this->word = 0;
this->flags[0] = in[0] == 'Y';
this->flags[1] = in[1] == 'Y';
this->flags[2] = in[2] == 'Y';

View File

@ -825,6 +825,7 @@ namespace Aurora::Loop
AuPair<bool, bool> LoopQueue::SourceExtended::DoWork(int fd)
{
bool bShouldRemove {true};
AuUInt8 uPosition {};
if (!this->bHasCommited)
{
@ -839,33 +840,77 @@ namespace Aurora::Loop
}
}
for (const auto &handler : this->subscribers)
bool bOverload {};
if ((this->subscribers.empty()) &&
(this->subscriberExs.empty()))
{
bOverload = true;
}
// Notify callbacks...
for (auto itr = this->subscriberExs.begin();
itr != this->subscriberExs.end(); )
{
bool result;
auto handler = *itr;
try
{
bShouldRemove &= handler->OnFinished(this->source);
result = handler->OnFinished(this->source, uPosition++);
}
catch (...)
{
SysPushErrorCatch();
}
bShouldRemove &= result;
if (result)
{
itr = this->subscriberExs.erase(itr);
}
else
{
itr++;
}
}
if (bShouldRemove)
{
for (const auto &handler : this->subscriberExs)
for (auto itr = this->subscribers.begin();
itr != this->subscribers.end(); )
{
bool result;
auto handler = *itr;
try
{
bShouldRemove &= handler->OnFinished(this->source);
result = handler->OnFinished(this->source);
}
catch (...)
{
SysPushErrorCatch();
}
bShouldRemove &= result;
if (result)
{
itr = this->subscribers.erase(itr);
}
else
{
itr++;
}
}
// Evict when subs count hit zero, not when sub count started off at zero
if (bOverload)
{
bShouldRemove = false;
}
// Notify global subscribers, allowing them to preempt removal
if (bShouldRemove)
{
AU_LOCK_GUARD(this->parent->globalLockMutex_);
@ -881,13 +926,6 @@ namespace Aurora::Loop
}
}
}
if ((this->subscribers.empty()) &&
(this->subscriberExs.empty()))
{
bShouldRemove = false;
}
return AuMakePair(true, bShouldRemove);
}