diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2010-08-12 15:03:51 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2010-08-25 15:39:20 +0200 |
commit | 45f83d78a56f4b3a812c87fec03a75558445b2ab (patch) | |
tree | 1adba1798c914baf65929d89ed9725dd68672bd6 /src/ctx.cpp | |
parent | 936dbf956b0f1471a96fc06bcba67765257dbc4a (diff) |
one more dezombification bug fixed
Diffstat (limited to 'src/ctx.cpp')
-rw-r--r-- | src/ctx.cpp | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/ctx.cpp b/src/ctx.cpp index a958833..79145eb 100644 --- a/src/ctx.cpp +++ b/src/ctx.cpp @@ -201,22 +201,6 @@ void zmq::ctx_t::zombify_socket (socket_base_t *socket_) slot_sync.unlock (); } -void zmq::ctx_t::dezombify_socket (socket_base_t *socket_) -{ - // We assume that this function is called only within dezombification - // process, which in turn is running within a slot_sync critical section. - // Therefore, we need no locking here. - - // TODO: Can we do this better than O(n)? - zombies_t::iterator it = std::find (zombies.begin (), zombies.end (), - socket_); - zmq_assert (it != zombies.end ()); - - // Move from the slot from 'zombie' to 'empty' state. - empty_slots.push_back ((*it)->get_slot ()); - zombies.erase (it); -} - void zmq::ctx_t::send_command (uint32_t slot_, const command_t &command_) { slots [slot_]->send (command_); @@ -307,14 +291,15 @@ void zmq::ctx_t::dezombify () { // Try to dezombify each zombie in the list. Note that caller is // responsible for calling this method in the slot_sync critical section. - zombies_t::iterator it = zombies.begin (); - while (it != zombies.end ()) { - zombies_t::iterator old = it; - ++it; - - // dezombify_socket can be called here that will invalidate - // the iterator. That's why we've got the next zombie beforehand. - (*old)->dezombify (); + for (zombies_t::iterator it = zombies.begin (); it != zombies.end ();) { + uint32_t slot = (*it)->get_slot (); + if ((*it)->dezombify ()) { + zombies.erase (it); + empty_slots.push_back (slot); + slots [slot] = NULL; + } + else + it++; } } |