signaler rewritten in such a way that any number (>64) of threads can be used

This commit is contained in:
Martin Sustrik
2010-04-29 20:34:48 +02:00
parent 1ffc6dd41f
commit ae93ed318a
12 changed files with 188 additions and 145 deletions

View File

@@ -28,7 +28,8 @@
#include "command.hpp"
#include "dispatcher.hpp"
zmq::io_thread_t::io_thread_t (dispatcher_t *dispatcher_, int thread_slot_) :
zmq::io_thread_t::io_thread_t (dispatcher_t *dispatcher_,
uint32_t thread_slot_) :
object_t (dispatcher_, thread_slot_)
{
poller = new (std::nothrow) poller_t;
@@ -66,22 +67,17 @@ int zmq::io_thread_t::get_load ()
void zmq::io_thread_t::in_event ()
{
// Find out which threads are sending us commands.
uint64_t signals = signaler.check ();
zmq_assert (signals);
while (true) {
// Iterate through all the threads in the process and find out
// which of them sent us commands.
int slot_count = thread_slot_count ();
for (int source_thread_slot = 0;
source_thread_slot != slot_count; source_thread_slot++) {
if (signals & (uint64_t (1) << source_thread_slot)) {
// Get the next signal.
uint32_t signal = signaler.check ();
if (signal == signaler_t::no_signal)
break;
// Read all the commands from particular thread.
command_t cmd;
while (dispatcher->read (source_thread_slot, thread_slot, &cmd))
cmd.destination->process_command (cmd);
}
// Process all the commands from the thread that sent the signal.
command_t cmd;
while (dispatcher->read (signal, thread_slot, &cmd))
cmd.destination->process_command (cmd);
}
}