[kernel] Add clear() method to wait_queue

Allow objects to clear out the wait_queue earlier than waiting for the
destructor by moving that functionality into wait_queue::clear().
This commit is contained in:
Justin C. Miller
2022-02-28 20:06:49 -08:00
parent 19105542e5
commit 446025fb65
4 changed files with 17 additions and 10 deletions

View File

@@ -1,14 +1,7 @@
#include "objects/thread.h"
#include "wait_queue.h"
wait_queue::~wait_queue()
{
util::scoped_lock lock {m_lock};
for (auto *t : m_threads) {
if (!t->exited()) t->wake();
t->handle_release();
}
}
wait_queue::~wait_queue() { clear(); }
void
wait_queue::add_thread(obj::thread *t)
@@ -23,7 +16,7 @@ wait_queue::pop_exited()
{
while (!m_threads.empty()) {
obj::thread *t = m_threads.first();
if (!t->exited())
if (!t->exited() && !t->ready())
break;
m_threads.pop_front();
@@ -48,3 +41,13 @@ wait_queue::pop_next_unlocked()
return nullptr;
return m_threads.pop_front();
}
void
wait_queue::clear()
{
util::scoped_lock lock {m_lock};
for (auto *t : m_threads) {
if (!t->exited()) t->wake();
t->handle_release();
}
}