Commit 462dd36d authored by somdoron's avatar somdoron

Problem: invoking the conditional variable for zero time is expensive

Solution: for zero timeout, unlock and relock immediately instead of timedwait
parent 9b1627f0
...@@ -99,11 +99,19 @@ int zmq::mailbox_safe_t::recv (command_t *cmd_, int timeout_) ...@@ -99,11 +99,19 @@ int zmq::mailbox_safe_t::recv (command_t *cmd_, int timeout_)
if (_cpipe.read (cmd_)) if (_cpipe.read (cmd_))
return 0; return 0;
// Wait for signal from the command sender. // If the timeout is zero, it will be quicker to release the lock, giving other a chance to send a command
int rc = _cond_var.wait (_sync, timeout_); // and immediately relock it.
if (rc == -1) { if (timeout_ == 0) {
errno_assert (errno == EAGAIN || errno == EINTR); _sync->unlock ();
return -1; _sync->lock ();
}
else {
// Wait for signal from the command sender.
int rc = _cond_var.wait (_sync, timeout_);
if (rc == -1) {
errno_assert (errno == EAGAIN || errno == EINTR);
return -1;
}
} }
// Another thread may already fetch the command // Another thread may already fetch the command
......
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