Commit 5a897f75 authored by somdoron's avatar somdoron

allocate reaper_signal only when needed

parent bbdd8662
...@@ -161,7 +161,8 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool ...@@ -161,7 +161,8 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool
file_desc(-1), file_desc(-1),
monitor_socket (NULL), monitor_socket (NULL),
monitor_events (0), monitor_events (0),
thread_safe (thread_safe_) thread_safe (thread_safe_),
reaper_signaler (NULL)
{ {
options.socket_id = sid_; options.socket_id = sid_;
options.ipv6 = (parent_->get (ZMQ_IPV6) != 0); options.ipv6 = (parent_->get (ZMQ_IPV6) != 0);
...@@ -171,12 +172,15 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool ...@@ -171,12 +172,15 @@ zmq::socket_base_t::socket_base_t (ctx_t *parent_, uint32_t tid_, int sid_, bool
mailbox = new mailbox_safe_t(&sync); mailbox = new mailbox_safe_t(&sync);
else else
mailbox = new mailbox_t(); mailbox = new mailbox_t();
} }
zmq::socket_base_t::~socket_base_t () zmq::socket_base_t::~socket_base_t ()
{ {
delete mailbox; delete mailbox;
if (reaper_signaler)
delete reaper_signaler;
stop_monitor (); stop_monitor ();
zmq_assert (destroyed); zmq_assert (destroyed);
} }
...@@ -1111,12 +1115,14 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_) ...@@ -1111,12 +1115,14 @@ void zmq::socket_base_t::start_reaping (poller_t *poller_)
else { else {
ENTER_MUTEX(); ENTER_MUTEX();
reaper_signaler = new signaler_t();
// Add signaler to the safe mailbox // Add signaler to the safe mailbox
fd = reaper_signaler.get_fd(); fd = reaper_signaler->get_fd();
((mailbox_safe_t*)mailbox)->add_signaler(&reaper_signaler); ((mailbox_safe_t*)mailbox)->add_signaler(reaper_signaler);
// Send a signal to make sure reaper handle existing commands // Send a signal to make sure reaper handle existing commands
reaper_signaler.send(); reaper_signaler->send();
EXIT_MUTEX(); EXIT_MUTEX();
} }
...@@ -1277,6 +1283,11 @@ void zmq::socket_base_t::in_event () ...@@ -1277,6 +1283,11 @@ void zmq::socket_base_t::in_event ()
// be destroyed. // be destroyed.
ENTER_MUTEX(); ENTER_MUTEX();
// If the socket is thread safe we need to unsignal the reaper signaler
if (thread_safe)
reaper_signaler->recv();
process_commands (0, false); process_commands (0, false);
EXIT_MUTEX(); EXIT_MUTEX();
check_destroy (); check_destroy ();
......
...@@ -261,7 +261,7 @@ namespace zmq ...@@ -261,7 +261,7 @@ namespace zmq
bool thread_safe; bool thread_safe;
// Signaler to be used in the reaping stage // Signaler to be used in the reaping stage
signaler_t reaper_signaler; signaler_t* reaper_signaler;
// Mutex for synchronize access to the socket in thread safe mode // Mutex for synchronize access to the socket in thread safe mode
mutex_t sync; mutex_t sync;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment