From 6f47f1281bcd56a085097cecfeaa1064f90fb19e Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Wed, 28 Mar 2012 06:38:25 +0200 Subject: [PATCH 1/3] Do not pass a message to the check_write method The check_write method does not use the passed message. The parameter was needed to implement the swap. As the swap is not supported anymore, it is safe to remove this parameter. --- src/lb.cpp | 12 ++---------- src/pair.cpp | 8 +------- src/pipe.cpp | 4 ++-- src/pipe.hpp | 2 +- src/router.cpp | 8 +------- 5 files changed, 7 insertions(+), 27 deletions(-) diff --git a/src/lb.cpp b/src/lb.cpp index 2a0f7693..4f613ded 100644 --- a/src/lb.cpp +++ b/src/lb.cpp @@ -131,17 +131,9 @@ bool zmq::lb_t::has_out () while (active > 0) { - // Check whether zero-sized message can be written to the pipe. - msg_t msg; - int rc = msg.init (); - errno_assert (rc == 0); - if (pipes [current]->check_write (&msg)) { - rc = msg.close (); - errno_assert (rc == 0); + // Check whether a pipe has room for another message. + if (pipes [current]->check_write ()) return true; - } - rc = msg.close (); - errno_assert (rc == 0); // Deactivate the pipe. active--; diff --git a/src/pair.cpp b/src/pair.cpp index cf35e123..6b17b906 100644 --- a/src/pair.cpp +++ b/src/pair.cpp @@ -108,13 +108,7 @@ bool zmq::pair_t::xhas_out () if (!pipe) return false; - msg_t msg; - int rc = msg.init (); - errno_assert (rc == 0); - bool result = pipe->check_write (&msg); - rc = msg.close (); - errno_assert (rc == 0); - return result; + return pipe->check_write (); } zmq::pair_session_t::pair_session_t (io_thread_t *io_thread_, bool connect_, diff --git a/src/pipe.cpp b/src/pipe.cpp index 25dd51cc..2a7e6ef4 100644 --- a/src/pipe.cpp +++ b/src/pipe.cpp @@ -146,7 +146,7 @@ bool zmq::pipe_t::read (msg_t *msg_) return true; } -bool zmq::pipe_t::check_write (msg_t *msg_) +bool zmq::pipe_t::check_write () { if (unlikely (!out_active || state != active)) return false; @@ -163,7 +163,7 @@ bool zmq::pipe_t::check_write (msg_t *msg_) bool zmq::pipe_t::write (msg_t *msg_) { - if (unlikely (!check_write (msg_))) + if (unlikely (!check_write ())) return false; bool more = msg_->flags () & msg_t::more ? true : false; diff --git a/src/pipe.hpp b/src/pipe.hpp index f4382575..c950ebc2 100644 --- a/src/pipe.hpp +++ b/src/pipe.hpp @@ -87,7 +87,7 @@ namespace zmq // Checks whether messages can be written to the pipe. If writing // the message would cause high watermark the function returns false. - bool check_write (msg_t *msg_); + bool check_write (); // Writes a message to the underlying pipe. Returns false if the // message cannot be written because high watermark was reached. diff --git a/src/router.cpp b/src/router.cpp index 4cf5212c..0b7576c9 100644 --- a/src/router.cpp +++ b/src/router.cpp @@ -152,21 +152,15 @@ int zmq::router_t::xsend (msg_t *msg_, int flags_) if (it != outpipes.end ()) { current_out = it->second.pipe; - msg_t empty; - int rc = empty.init (); - errno_assert (rc == 0); - if (!current_out->check_write (&empty)) { + if (!current_out->check_write ()) { it->second.active = false; more_out = false; current_out = NULL; } - rc = empty.close (); - errno_assert (rc == 0); } else if(fail_unroutable) { more_out = false; retval = EHOSTUNREACH; } - } int rc = msg_->close (); From e7674025e583044c7d6a52cd54033973df934bef Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Wed, 28 Mar 2012 06:49:25 +0200 Subject: [PATCH 2/3] Remove the launch_sibling method The method is not used anymore. --- src/own.cpp | 18 ------------------ src/own.hpp | 4 ---- 2 files changed, 22 deletions(-) diff --git a/src/own.cpp b/src/own.cpp index d6dd3092..719c116d 100644 --- a/src/own.cpp +++ b/src/own.cpp @@ -80,24 +80,6 @@ void zmq::own_t::launch_child (own_t *object_) send_own (this, object_); } -void zmq::own_t::launch_sibling (own_t *object_) -{ - // At this point it is important that object is plugged in before its - // owner has a chance to terminate it. Thus, 'plug' command is sent before - // the 'own' command. Given that the mailbox preserves ordering of - // commands, 'term' command from the owner cannot make it to the object - // before the already written 'plug' command. - - // Specify the owner of the object. - object_->set_owner (owner); - - // Plug the object into its I/O thread. - send_plug (object_); - - // Make parent own the object. - send_own (owner, object_); -} - void zmq::own_t::process_term_req (own_t *object_) { // When shutting down we can ignore termination requests from owned diff --git a/src/own.hpp b/src/own.hpp index 2969ffd1..205631a2 100644 --- a/src/own.hpp +++ b/src/own.hpp @@ -70,10 +70,6 @@ namespace zmq // Launch the supplied object and become its owner. void launch_child (own_t *object_); - // Launch the supplied object and make it your sibling (make your - // owner become its owner as well). - void launch_sibling (own_t *object_); - // Ask owner object to terminate this object. It may take a while // while actual termination is started. This function should not be // called more than once. From 77d93d70f07a9f41f82bc16e430a078f4f230a27 Mon Sep 17 00:00:00 2001 From: Martin Hurton Date: Wed, 28 Mar 2012 06:56:53 +0200 Subject: [PATCH 3/3] Simplify use of posix_assert in mutex.hpp It is the job of the posix_assert macro to check the value. No need to do it twice. The patch also fixes some whitespace problems. --- src/mutex.hpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/mutex.hpp b/src/mutex.hpp index 8d7068a0..0b532eb1 100644 --- a/src/mutex.hpp +++ b/src/mutex.hpp @@ -74,47 +74,43 @@ namespace zmq namespace zmq { - + class mutex_t { public: inline mutex_t () { int rc = pthread_mutex_init (&mutex, NULL); - if (rc) - posix_assert (rc); + posix_assert (rc); } - + inline ~mutex_t () { int rc = pthread_mutex_destroy (&mutex); - if (rc) - posix_assert (rc); + posix_assert (rc); } - + inline void lock () { int rc = pthread_mutex_lock (&mutex); - if (rc) - posix_assert (rc); + posix_assert (rc); } - + inline void unlock () { int rc = pthread_mutex_unlock (&mutex); - if (rc) - posix_assert (rc); + posix_assert (rc); } - + private: - + pthread_mutex_t mutex; - + // Disable copy construction and assignment. mutex_t (const mutex_t&); const mutex_t &operator = (const mutex_t&); }; - + } #endif