mirror of
https://github.com/justinian/jsix.git
synced 2025-12-09 16:04:32 -08:00
[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:
@@ -76,6 +76,7 @@ void
|
|||||||
channel::close()
|
channel::close()
|
||||||
{
|
{
|
||||||
util::scoped_lock lock {m_close_lock};
|
util::scoped_lock lock {m_close_lock};
|
||||||
|
m_queue.clear();
|
||||||
g_kernel_buffers.return_section(m_data);
|
g_kernel_buffers.return_section(m_data);
|
||||||
m_closed = true;
|
m_closed = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ mailbox::close()
|
|||||||
|
|
||||||
for (auto &p : m_pending) {
|
for (auto &p : m_pending) {
|
||||||
delete p.val.msg;
|
delete p.val.msg;
|
||||||
p.val.sender->wake(no_message);
|
|
||||||
}
|
}
|
||||||
|
m_queue.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -1,14 +1,7 @@
|
|||||||
#include "objects/thread.h"
|
#include "objects/thread.h"
|
||||||
#include "wait_queue.h"
|
#include "wait_queue.h"
|
||||||
|
|
||||||
wait_queue::~wait_queue()
|
wait_queue::~wait_queue() { clear(); }
|
||||||
{
|
|
||||||
util::scoped_lock lock {m_lock};
|
|
||||||
for (auto *t : m_threads) {
|
|
||||||
if (!t->exited()) t->wake();
|
|
||||||
t->handle_release();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
wait_queue::add_thread(obj::thread *t)
|
wait_queue::add_thread(obj::thread *t)
|
||||||
@@ -23,7 +16,7 @@ wait_queue::pop_exited()
|
|||||||
{
|
{
|
||||||
while (!m_threads.empty()) {
|
while (!m_threads.empty()) {
|
||||||
obj::thread *t = m_threads.first();
|
obj::thread *t = m_threads.first();
|
||||||
if (!t->exited())
|
if (!t->exited() && !t->ready())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
m_threads.pop_front();
|
m_threads.pop_front();
|
||||||
@@ -48,3 +41,13 @@ wait_queue::pop_next_unlocked()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
return m_threads.pop_front();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public:
|
|||||||
/// Get the spinlock to lock this queue
|
/// Get the spinlock to lock this queue
|
||||||
util::spinlock & get_lock() { return m_lock; }
|
util::spinlock & get_lock() { return m_lock; }
|
||||||
|
|
||||||
|
/// Wake and clear out all threads.
|
||||||
|
void clear();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Get rid of any exited threads that are next
|
/// Get rid of any exited threads that are next
|
||||||
/// in the queue. Caller must hold the queue lock.
|
/// in the queue. Caller must hold the queue lock.
|
||||||
|
|||||||
Reference in New Issue
Block a user