mirror of
https://github.com/zeromq/libzmq.git
synced 2025-10-30 13:47:13 +01:00
Problem: invoking the conditional variable for zero time is expensive
Solution: for zero timeout, unlock and relock immediately instead of timedwait
This commit is contained in:
@@ -99,12 +99,20 @@ int zmq::mailbox_safe_t::recv (command_t *cmd_, int timeout_)
|
|||||||
if (_cpipe.read (cmd_))
|
if (_cpipe.read (cmd_))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
// If the timeout is zero, it will be quicker to release the lock, giving other a chance to send a command
|
||||||
|
// and immediately relock it.
|
||||||
|
if (timeout_ == 0) {
|
||||||
|
_sync->unlock ();
|
||||||
|
_sync->lock ();
|
||||||
|
}
|
||||||
|
else {
|
||||||
// Wait for signal from the command sender.
|
// Wait for signal from the command sender.
|
||||||
int rc = _cond_var.wait (_sync, timeout_);
|
int rc = _cond_var.wait (_sync, timeout_);
|
||||||
if (rc == -1) {
|
if (rc == -1) {
|
||||||
errno_assert (errno == EAGAIN || errno == EINTR);
|
errno_assert (errno == EAGAIN || errno == EINTR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Another thread may already fetch the command
|
// Another thread may already fetch the command
|
||||||
const bool ok = _cpipe.read (cmd_);
|
const bool ok = _cpipe.read (cmd_);
|
||||||
|
|||||||
Reference in New Issue
Block a user