wait_object: Refactor to allow waking up a single thread.
This commit is contained in:
parent
bc77a7580e
commit
0f6fbdb963
|
@ -67,8 +67,10 @@ SharedPtr<Thread> WaitObject::GetHighestPriorityReadyThread() {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WaitObject::WakeupAllWaitingThreads() {
|
void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {
|
||||||
while (auto thread = GetHighestPriorityReadyThread()) {
|
if (!thread)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!thread->IsSleepingOnWaitAll()) {
|
if (!thread->IsSleepingOnWaitAll()) {
|
||||||
Acquire(thread.get());
|
Acquire(thread.get());
|
||||||
} else {
|
} else {
|
||||||
|
@ -86,6 +88,11 @@ void WaitObject::WakeupAllWaitingThreads() {
|
||||||
thread->wait_objects.clear();
|
thread->wait_objects.clear();
|
||||||
|
|
||||||
thread->ResumeFromWait();
|
thread->ResumeFromWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaitObject::WakeupAllWaitingThreads() {
|
||||||
|
while (auto thread = GetHighestPriorityReadyThread()) {
|
||||||
|
WakeupWaitingThread(thread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,12 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual void WakeupAllWaitingThreads();
|
virtual void WakeupAllWaitingThreads();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wakes up a single thread waiting on this object.
|
||||||
|
* @param thread Thread that is waiting on this object to wakeup.
|
||||||
|
*/
|
||||||
|
void WakeupWaitingThread(SharedPtr<Thread> thread);
|
||||||
|
|
||||||
/// Obtains the highest priority thread that is ready to run from this object's waiting list.
|
/// Obtains the highest priority thread that is ready to run from this object's waiting list.
|
||||||
SharedPtr<Thread> GetHighestPriorityReadyThread();
|
SharedPtr<Thread> GetHighestPriorityReadyThread();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue