diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 245ec8d07..40ef38f73 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -27,13 +27,11 @@ #include #include #include -#include #include #include #include #include #include -#include /* public variables */ @@ -72,6 +70,8 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t /* close all FDs starting from */ void my_closefrom(int start); +int compute_poll_timeout(int next); + /* disable the specified poller */ void disable_poller(const char *poller_name); @@ -340,30 +340,6 @@ static inline void fd_insert(int fd, void *owner, void (*iocb)(int fd), unsigned _HA_ATOMIC_INC(&ha_used_fds); } -/* Computes the bounded poll() timeout based on the next expiration timer - * by bounding it to MAX_DELAY_MS. may equal TICK_ETERNITY. The pollers - * just needs to call this function right before polling to get their timeout - * value. Timeouts that are already expired (possibly due to a pending event) - * are accounted for in activity.poll_exp. - */ -static inline int compute_poll_timeout(int next) -{ - int wait_time; - - if (!tick_isset(next)) - wait_time = MAX_DELAY_MS; - else if (tick_is_expired(next, now_ms)) { - activity[tid].poll_exp++; - wait_time = 0; - } - else { - wait_time = TICKS_TO_MS(tick_remain(now_ms, next)) + 1; - if (wait_time > MAX_DELAY_MS) - wait_time = MAX_DELAY_MS; - } - return wait_time; -} - /* These are replacements for FD_SET, FD_CLR, FD_ISSET, working on uints */ static inline void hap_fd_set(int fd, unsigned int *evts) { diff --git a/src/fd.c b/src/fd.c index f6665ed57..b796b1ae4 100644 --- a/src/fd.c +++ b/src/fd.c @@ -94,6 +94,7 @@ #include #include #include +#include #include @@ -699,6 +700,30 @@ void my_closefrom(int start) } #endif // defined(USE_POLL) +/* Computes the bounded poll() timeout based on the next expiration timer + * by bounding it to MAX_DELAY_MS. may equal TICK_ETERNITY. The pollers + * just needs to call this function right before polling to get their timeout + * value. Timeouts that are already expired (possibly due to a pending event) + * are accounted for in activity.poll_exp. + */ +int compute_poll_timeout(int next) +{ + int wait_time; + + if (!tick_isset(next)) + wait_time = MAX_DELAY_MS; + else if (tick_is_expired(next, now_ms)) { + activity[tid].poll_exp++; + wait_time = 0; + } + else { + wait_time = TICKS_TO_MS(tick_remain(now_ms, next)) + 1; + if (wait_time > MAX_DELAY_MS) + wait_time = MAX_DELAY_MS; + } + return wait_time; +} + /* disable the specified poller */ void disable_poller(const char *poller_name) {