Skip to content
Snippets Groups Projects
Commit 6542bc76 authored by Avi Kivity's avatar Avi Kivity
Browse files

sched: prevent concurrent wakeups

parent 492e38d6
No related branches found
No related tags found
No related merge requests found
...@@ -110,16 +110,14 @@ void thread::prepare_wait() ...@@ -110,16 +110,14 @@ void thread::prepare_wait()
void thread::wake() void thread::wake()
{ {
// prevent two concurrent wakeups
if (!_waiting.exchange(false)) {
return;
}
irq_save_lock_type irq_lock; irq_save_lock_type irq_lock;
with_lock(irq_lock, [this] { with_lock(irq_lock, [this] {
if (!_waiting) { _on_runqueue = true;
return; _cpu->runqueue.push_back(*this);
}
_waiting = false;
if (!_on_runqueue) {
_on_runqueue = true;
_cpu->runqueue.push_back(*this);
}
}); });
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <boost/intrusive/set.hpp> #include <boost/intrusive/set.hpp>
#include <boost/intrusive/list.hpp> #include <boost/intrusive/list.hpp>
#include "mutex.hh" #include "mutex.hh"
#include <atomic>
extern "C" { extern "C" {
void smp_main(); void smp_main();
...@@ -63,7 +64,7 @@ private: ...@@ -63,7 +64,7 @@ private:
thread_state _state; thread_state _state;
thread_control_block* _tcb; thread_control_block* _tcb;
bool _on_runqueue; bool _on_runqueue;
bool _waiting; std::atomic_bool _waiting;
stack_info _stack; stack_info _stack;
cpu* _cpu; cpu* _cpu;
friend void thread_main_c(thread* t); friend void thread_main_c(thread* t);
......
...@@ -128,7 +128,7 @@ class thread_context(object): ...@@ -128,7 +128,7 @@ class thread_context(object):
self.new_frame = gdb.newest_frame() self.new_frame = gdb.newest_frame()
self.new_frame.select() self.new_frame.select()
self.running = (not long(thread['_on_runqueue']) self.running = (not long(thread['_on_runqueue'])
and not long(thread['_waiting'])) and not long(thread['_waiting']['_M_base']['_M_i']))
self.old_rsp = ulong(gdb.parse_and_eval('$rsp').cast(ulong_type)) self.old_rsp = ulong(gdb.parse_and_eval('$rsp').cast(ulong_type))
self.old_rip = ulong(gdb.parse_and_eval('$rip').cast(ulong_type)) self.old_rip = ulong(gdb.parse_and_eval('$rip').cast(ulong_type))
self.old_rbp = ulong(gdb.parse_and_eval('$rbp').cast(ulong_type)) self.old_rbp = ulong(gdb.parse_and_eval('$rbp').cast(ulong_type))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment