mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Simplify event and wait_queue
Previously event tried to read its value in event::wake_observer, which required jumping through some hoops in how wait_queue was designed, so that a value wouldn't be wasted if the wait_queue was empty. Now, read the event value in event::wait after returning from the thread::block call instead, which simplifies the whole process and lets us simplify the wait_queue API as well.
This commit is contained in:
@@ -28,22 +28,15 @@ event::wait()
|
||||
// Wait for event::signal() to wake us with a value
|
||||
thread ¤t = thread::current();
|
||||
m_queue.add_thread(¤t);
|
||||
return current.block();
|
||||
current.block();
|
||||
return read();
|
||||
}
|
||||
|
||||
void
|
||||
event::wake_observer()
|
||||
{
|
||||
util::scoped_lock lock {m_queue.get_lock()};
|
||||
thread *t = m_queue.get_next_unlocked();
|
||||
if (!t) return;
|
||||
|
||||
uint64_t value = read();
|
||||
if (value) {
|
||||
m_queue.pop_next_unlocked();
|
||||
lock.release();
|
||||
t->wake(value);
|
||||
}
|
||||
thread *t = m_queue.pop_next();
|
||||
if (t) t->wake();
|
||||
}
|
||||
|
||||
} // namespace obj
|
||||
|
||||
Reference in New Issue
Block a user