Problem: poller implementation of zmq_poll is slow

Solution: use it only if there is at least one thread-safe socket,
which is not compatible with the older zmq_poll implementation.
This commit is contained in:
Luca Boccassi 2018-11-04 22:16:36 +00:00 committed by Luca Boccassi
parent b6f55eac14
commit ab1607f813

View File

@ -801,9 +801,15 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
// TODO: the function implementation can just call zmq_pollfd_poll with // TODO: the function implementation can just call zmq_pollfd_poll with
// pollfd as NULL, however pollfd is not yet stable. // pollfd as NULL, however pollfd is not yet stable.
#if defined ZMQ_HAVE_POLLER #if defined ZMQ_HAVE_POLLER
// if poller is present, use that. // if poller is present, use that if there is at least 1 thread-safe socket,
return zmq_poller_poll (items_, nitems_, timeout_); // otherwise fall back to the previous implementation as it's faster.
#else for (int i = 0; i != nitems_; i++) {
if (items_[i].socket
&& as_socket_base_t (items_[i].socket)->is_thread_safe ()) {
return zmq_poller_poll (items_, nitems_, timeout_);
}
}
#endif // ZMQ_HAVE_POLLER
#if defined ZMQ_POLL_BASED_ON_POLL || defined ZMQ_POLL_BASED_ON_SELECT #if defined ZMQ_POLL_BASED_ON_POLL || defined ZMQ_POLL_BASED_ON_SELECT
if (unlikely (nitems_ < 0)) { if (unlikely (nitems_ < 0)) {
errno = EINVAL; errno = EINVAL;
@ -1086,7 +1092,6 @@ int zmq_poll (zmq_pollitem_t *items_, int nitems_, long timeout_)
errno = ENOTSUP; errno = ENOTSUP;
return -1; return -1;
#endif #endif
#endif // ZMQ_HAVE_POLLER
} }
// The poller functionality // The poller functionality