core: switch to spsc_queue for interthread communication

It's much faster than a normal queue.
This commit is contained in:
Avi Kivity
2014-10-06 21:30:49 +03:00
parent daca47af67
commit 4a080eb008
2 changed files with 7 additions and 5 deletions

View File

@@ -347,8 +347,8 @@ reactor::signal_handler::signal_handler(int signo)
}
inter_thread_work_queue::inter_thread_work_queue()
: _pending(queue_length)
, _completed(queue_length)
: _pending()
, _completed()
, _start_eventfd(0)
, _complete_eventfd(0) {
}

View File

@@ -24,7 +24,7 @@
#include <system_error>
#include <chrono>
#include <atomic>
#include <boost/lockfree/queue.hpp>
#include <boost/lockfree/spsc_queue.hpp>
#include <boost/optional.hpp>
#include <boost/program_options.hpp>
#include "util/eclipse.hh"
@@ -305,8 +305,10 @@ class smp;
class inter_thread_work_queue {
static constexpr size_t queue_length = 128;
struct work_item;
boost::lockfree::queue<work_item*> _pending;
boost::lockfree::queue<work_item*> _completed;
using lf_queue = boost::lockfree::spsc_queue<work_item*,
boost::lockfree::capacity<queue_length>>;
lf_queue _pending;
lf_queue _completed;
writeable_eventfd _start_eventfd;
readable_eventfd _complete_eventfd;
semaphore _queue_has_room = { queue_length };