summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Sustrik <sustrik@250bpm.com>2010-09-19 22:17:37 +0200
committerMartin Sustrik <sustrik@250bpm.com>2010-09-19 22:17:37 +0200
commitcda3c96a7fed0ee603c13e787ac511a1ea171367 (patch)
tree58453848037c876847b7763e4195440cff878f67 /src
parent938689a49128ca17d2bc9662f311c6dbb70240db (diff)
minor code reorganisation in ctx_t::terminate
Diffstat (limited to 'src')
-rw-r--r--src/ctx.cpp31
1 files changed, 15 insertions, 16 deletions
diff --git a/src/ctx.cpp b/src/ctx.cpp
index b17fac0..7ed924d 100644
--- a/src/ctx.cpp
+++ b/src/ctx.cpp
@@ -106,13 +106,6 @@ zmq::ctx_t::~ctx_t ()
int zmq::ctx_t::terminate ()
{
- // First send stop command to sockets so that any
- // blocking calls are interrupted.
- slot_sync.lock ();
- for (sockets_t::size_type i = 0; i != sockets.size (); i++)
- sockets [i]->stop ();
- slot_sync.unlock ();
-
// Close the logging infrastructure.
log_sync.lock ();
int rc = log_socket->close ();
@@ -120,26 +113,32 @@ int zmq::ctx_t::terminate ()
log_socket = NULL;
log_sync.unlock ();
- // Find out whether there are any open sockets to care about.
- // If so, sleep till they are closed. Note that we can use
- // no_sockets_notify safely out of the critical section as once set
- // its value is never changed again.
+ // First send stop command to sockets so that any
+ // blocking calls are interrupted.
slot_sync.lock ();
+ for (sockets_t::size_type i = 0; i != sockets.size (); i++)
+ sockets [i]->stop ();
if (!sockets.empty ())
no_sockets_notify = true;
slot_sync.unlock ();
+
+ // Find out whether there are any open sockets to care about.
+ // If there are open sockets, sleep till they are closed. Note that we can
+ // use no_sockets_notify safely out of the critical section as once set
+ // its value is never changed again.
if (no_sockets_notify)
no_sockets_sync.wait ();
+ // Note that the lock won't block anyone here. There's noone else having
+ // open sockets anyway. The only purpose of the lock is to double-check all
+ // the CPU caches have been synchronised.
+ slot_sync.lock ();
+
// At this point there should be no active sockets. What we have is a set
// of zombies waiting to be dezombified.
zmq_assert (sockets.empty ());
- // Get rid of remaining zombie sockets. Note that the lock won't block
- // anyone here. There's noone else having open sockets anyway. The only
- // purpose of the lock is to double-check all the CPU caches have been
- // synchronised.
- slot_sync.lock ();
+ // Get rid of remaining zombie sockets.
while (!zombies.empty ()) {
dezombify ();