diff options
author | Martin Sustrik <sustrik@250bpm.com> | 2011-09-14 15:16:48 +0200 |
---|---|---|
committer | Martin Sustrik <sustrik@250bpm.com> | 2011-09-14 15:16:48 +0200 |
commit | 78b02d142e82015a2146b7d40f7e0a729ad0e89b (patch) | |
tree | 1d7519a8e06131fa83cebfd1845470c750fecc79 /src | |
parent | cf499ee016340a8534e24084a481a02498b44e70 (diff) |
Minor optimisation in message distribution algorithm
If several of the outbound pipes become passive while sending
a single message, the refcount on the message is adjusted
once only, not multiple times. It's an atomic operation so
the cost is not negligible.
Signed-off-by: Martin Sustrik <sustrik@250bpm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/dist.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/dist.cpp b/src/dist.cpp index 79baf43..795e13e 100644 --- a/src/dist.cpp +++ b/src/dist.cpp @@ -142,10 +142,12 @@ void zmq::dist_t::distribute (msg_t *msg_, int flags_) msg_->add_refs ((int) matching - 1); // Push copy of the message to each matching pipe. - for (pipes_t::size_type i = 0; i < matching; ++i) { + int failed = 0; + for (pipes_t::size_type i = 0; i < matching; ++i) if (!write (pipes [i], msg_)) - msg_->rm_refs (1); - } + ++failed; + if (unlikely (failed)) + msg_->rm_refs (failed); // Detach the original message from the data buffer. Note that we don't // close the message. That's because we've already used all the references. |