Commit 78b02d14 authored by Martin Sustrik's avatar Martin Sustrik

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: 's avatarMartin Sustrik <sustrik@250bpm.com>
parent cf499ee0
......@@ -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.
......
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