diff --git a/src/kernel/objects/event.cpp b/src/kernel/objects/event.cpp index 0867193..de4014b 100644 --- a/src/kernel/objects/event.cpp +++ b/src/kernel/objects/event.cpp @@ -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 diff --git a/src/kernel/wait_queue.cpp b/src/kernel/wait_queue.cpp index faa812d..1c9ea79 100644 --- a/src/kernel/wait_queue.cpp +++ b/src/kernel/wait_queue.cpp @@ -38,31 +38,24 @@ wait_queue::pop_exited() } obj::thread * -wait_queue::get_next_unlocked() +wait_queue::pop_next() { pop_exited(); if (m_threads.empty()) return nullptr; - return m_threads.first(); -} -obj::thread * -wait_queue::pop_next_unlocked() -{ - pop_exited(); - if (m_threads.empty()) - return nullptr; - return m_threads.pop_front(); + obj::thread *t = m_threads.pop_front(); + kassert(t, "Null thread in wait_queue"); + t->handle_release(); + return t; } void wait_queue::clear(uint64_t value) { - util::scoped_lock lock {m_lock}; - while (!m_threads.empty()) { - obj::thread *t = pop_next_unlocked(); - kassert(t, "Null thread in the wait queue"); - if (!t->exited()) t->wake(value); - t->handle_release(); + obj::thread *t = pop_next(); + while (t) { + t->wake(value); + t = pop_next(); } } diff --git a/src/kernel/wait_queue.h b/src/kernel/wait_queue.h index 2b12498..6daec4d 100644 --- a/src/kernel/wait_queue.h +++ b/src/kernel/wait_queue.h @@ -15,30 +15,14 @@ public: /// Wake all threads when destructing ~wait_queue(); - /// Add the given thread to the queue. Locks the - /// queue lock. + /// Add the given thread to the queue. void add_thread(obj::thread *t); /// Block the current thread on the queue. void wait(); /// Pops the next waiting thread off the queue. - /// Locks the queue lock. - inline obj::thread * pop_next() { - util::scoped_lock lock {m_lock}; - return pop_next_unlocked(); - } - - /// Get the next waiting thread. Does not lock the - /// queue lock. - obj::thread * get_next_unlocked(); - - /// Pop the next thread off the queue. Does not - /// lock the queue lock. - obj::thread * pop_next_unlocked(); - - /// Get the spinlock to lock this queue - util::spinlock & get_lock() { return m_lock; } + obj::thread * pop_next(); /// Wake and clear out all threads. /// \arg value The value passed to thread::wake