[*] d3587dbf
cont
This commit is contained in:
parent
d3587dbf08
commit
3adb019cf1
@ -435,6 +435,24 @@ namespace Aurora::Async
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadPool::DoThing(ThreadState *pState)
|
||||
{
|
||||
auto uState = pState->cvHasWork;
|
||||
auto uMin = AuMin<AuUInt32>(uState, pState->pendingWorkItems.size());
|
||||
if (!uMin) uMin = 1;
|
||||
|
||||
while (uState &&
|
||||
AuAtomicCompareExchange(&pState->cvHasWork, uState - uMin, uState) != uState)
|
||||
{
|
||||
uState = pState->cvHasWork;
|
||||
|
||||
if (uState < uMin)
|
||||
{
|
||||
uMin = uState;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ThreadPool::PollInternal(AuSPtr<ThreadState> state, bool block, AuUInt32 &uCount)
|
||||
{
|
||||
if (!state)
|
||||
@ -455,6 +473,8 @@ namespace Aurora::Async
|
||||
{
|
||||
group->workQueue.Dequeue(state->pendingWorkItems, state->multipopCount, state->id.second);
|
||||
|
||||
this->DoThing(state.get());
|
||||
|
||||
// Consider blocking for more work
|
||||
if (!block)
|
||||
{
|
||||
@ -497,23 +517,10 @@ namespace Aurora::Async
|
||||
AuAtomicSub(&state->cvSleepCount, 1u);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
while (state->pendingWorkItems.empty() && block);
|
||||
|
||||
{
|
||||
auto uState = state->cvHasWork;
|
||||
|
||||
while (uState &&
|
||||
AuAtomicCompareExchange(&state->cvHasWork, uState - 1, uState) != uState)
|
||||
{
|
||||
uState = state->cvHasWork;
|
||||
|
||||
if (uState == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!block && // quick hack: is worthy of io reset by virtue of having polled externally (most likely)?
|
||||
group->workQueue.IsEmpty(this, state->id))
|
||||
@ -617,7 +624,6 @@ namespace Aurora::Async
|
||||
state->pendingWorkItems.clear();
|
||||
state->cvVariable->Broadcast();
|
||||
state->eventLs->Set();
|
||||
state->pendingWorkItems.clear();
|
||||
}
|
||||
|
||||
// Account for
|
||||
|
@ -97,6 +97,7 @@ namespace Aurora::Async
|
||||
|
||||
bool InternalRunOne(AuSPtr<ThreadState>, bool block, AuUInt32 &uCount);
|
||||
bool PollInternal(AuSPtr<ThreadState>, bool block, AuUInt32 &uCount);
|
||||
void DoThing(ThreadState *pState);
|
||||
|
||||
size_t GetThreadWorkersCount(ThreadGroup_t group);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user