diff --git a/include/haproxy/fd.h b/include/haproxy/fd.h index 010fdacf8..fa2424056 100644 --- a/include/haproxy/fd.h +++ b/include/haproxy/fd.h @@ -79,6 +79,7 @@ ssize_t fd_write_frag_line(int fd, size_t maxlen, const struct ist pfx[], size_t void my_closefrom(int start); int compute_poll_timeout(int next); +void fd_leaving_poll(int wait_time, int status); /* disable the specified poller */ void disable_poller(const char *poller_name); diff --git a/src/ev_epoll.c b/src/ev_epoll.c index 583206232..fd49d92c5 100644 --- a/src/ev_epoll.c +++ b/src/ev_epoll.c @@ -208,13 +208,7 @@ static void _do_poll(struct poller *p, int exp, int wake) break; } while (1); - clock_leaving_poll(wait_time, status); - - thread_harmless_end(); - thread_idle_end(); - - if (sleeping_thread_mask & tid_bit) - _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit); + fd_leaving_poll(wait_time, status); /* process polled events */ diff --git a/src/ev_evports.c b/src/ev_evports.c index 4d611541c..301e86eef 100644 --- a/src/ev_evports.c +++ b/src/ev_evports.c @@ -202,13 +202,7 @@ static void _do_poll(struct poller *p, int exp, int wake) break; } while(1); - clock_leaving_poll(wait_time, nevlist); - - thread_harmless_end(); - thread_idle_end(); - - if (sleeping_thread_mask & tid_bit) - _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit); + fd_leaving_poll(wait_time, nevlist); if (nevlist > 0) activity[tid].poll_io++; diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c index 3bc7121cb..43643fb38 100644 --- a/src/ev_kqueue.c +++ b/src/ev_kqueue.c @@ -174,13 +174,7 @@ static void _do_poll(struct poller *p, int exp, int wake) break; } while (1); - clock_leaving_poll(wait_time, status); - - thread_harmless_end(); - thread_idle_end(); - - if (sleeping_thread_mask & tid_bit) - _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit); + fd_leaving_poll(wait_time, status); for (count = 0; count < status; count++) { unsigned int n = 0; diff --git a/src/ev_poll.c b/src/ev_poll.c index 5f52262ad..92e45a634 100644 --- a/src/ev_poll.c +++ b/src/ev_poll.c @@ -205,13 +205,8 @@ static void _do_poll(struct poller *p, int exp, int wake) clock_entering_poll(); status = poll(poll_events, nbfd, wait_time); clock_update_date(wait_time, status); - clock_leaving_poll(wait_time, status); - thread_harmless_end(); - thread_idle_end(); - - if (sleeping_thread_mask & tid_bit) - _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit); + fd_leaving_poll(wait_time, status); if (status > 0) activity[tid].poll_io++; diff --git a/src/ev_select.c b/src/ev_select.c index 3880d0d14..b3e1b40e6 100644 --- a/src/ev_select.c +++ b/src/ev_select.c @@ -180,13 +180,7 @@ static void _do_poll(struct poller *p, int exp, int wake) NULL, &delta); clock_update_date(delta_ms, status); - clock_leaving_poll(delta_ms, status); - - thread_harmless_end(); - thread_idle_end(); - - if (sleeping_thread_mask & tid_bit) - _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit); + fd_leaving_poll(delta_ms, status); if (status <= 0) return; diff --git a/src/fd.c b/src/fd.c index 99c8c4e5b..5dd648ef7 100644 --- a/src/fd.c +++ b/src/fd.c @@ -759,6 +759,21 @@ int compute_poll_timeout(int next) return wait_time; } +/* Handle the return of the poller, which consists in calculating the idle + * time, saving a few clocks, marking the thread harmful again etc. All that + * is some boring stuff that all pollers have to do anyway. + */ +void fd_leaving_poll(int wait_time, int status) +{ + clock_leaving_poll(wait_time, status); + + thread_harmless_end(); + thread_idle_end(); + + if (sleeping_thread_mask & tid_bit) + _HA_ATOMIC_AND(&sleeping_thread_mask, ~tid_bit); +} + /* disable the specified poller */ void disable_poller(const char *poller_name) {