MINOR: poller: move time and date computation out of the pollers

By placing this code into time.h (tv_entering_poll() and tv_leaving_poll())
we can remove the logic from the pollers and prepare for extending this to
offer more accurate time measurements.
diff --git a/include/common/time.h b/include/common/time.h
index f3dd3ba..aeb1986 100644
--- a/include/common/time.h
+++ b/include/common/time.h
@@ -543,6 +543,25 @@
 	idle_time = samp_time = 0;
 }
 
+/* Collect date and time information before calling poll(). This will be used
+ * to count the run time of the past loop and the sleep time of the next poll.
+ */
+static inline void tv_entering_poll()
+{
+	gettimeofday(&before_poll, NULL);
+}
+
+/* Collect date and time information after leaving poll(). <timeout> must be
+ * set to the maximum sleep time passed to poll (in milliseconds), and
+ * <interrupted> must be zero if the poller reached the timeout or non-zero
+ * otherwise, which generally is provided by the poller's return value.
+ */
+static inline void tv_leaving_poll(int timeout, int interrupted)
+{
+	tv_update_date(timeout, interrupted);
+	measure_idle();
+}
+
 #endif /* _COMMON_TIME_H */
 
 /*
diff --git a/src/ev_epoll.c b/src/ev_epoll.c
index b9980db..9d111ce 100644
--- a/src/ev_epoll.c
+++ b/src/ev_epoll.c
@@ -146,10 +146,9 @@
 
 	/* now let's wait for polled events */
 	wait_time = compute_poll_timeout(exp);
-	gettimeofday(&before_poll, NULL);
+	tv_entering_poll();
 	status = epoll_wait(epoll_fd[tid], epoll_events, global.tune.maxpollevents, wait_time);
-	tv_update_date(wait_time, status);
-	measure_idle();
+	tv_leaving_poll(wait_time, status);
 
 	thread_harmless_end();
 
diff --git a/src/ev_kqueue.c b/src/ev_kqueue.c
index 3d21cb0..c1c3e11 100644
--- a/src/ev_kqueue.c
+++ b/src/ev_kqueue.c
@@ -134,15 +134,14 @@
 	timeout.tv_sec  = (delta_ms / 1000);
 	timeout.tv_nsec = (delta_ms % 1000) * 1000000;
 	fd = global.tune.maxpollevents;
-	gettimeofday(&before_poll, NULL);
+	tv_entering_poll();
 	status = kevent(kqueue_fd[tid], // int kq
 			NULL,      // const struct kevent *changelist
 			0,         // int nchanges
 			kev,       // struct kevent *eventlist
 			fd,        // int nevents
 			&timeout); // const struct timespec *timeout
-	tv_update_date(delta_ms, status);
-	measure_idle();
+	tv_leaving_poll(delta_ms, status);
 
 	thread_harmless_end();
 
diff --git a/src/ev_poll.c b/src/ev_poll.c
index 0b51e8d..b08274c 100644
--- a/src/ev_poll.c
+++ b/src/ev_poll.c
@@ -194,10 +194,9 @@
 
 	/* now let's wait for events */
 	wait_time = compute_poll_timeout(exp);
-	gettimeofday(&before_poll, NULL);
+	tv_entering_poll();
 	status = poll(poll_events, nbfd, wait_time);
-	tv_update_date(wait_time, status);
-	measure_idle();
+	tv_leaving_poll(wait_time, status);
 
 	thread_harmless_end();
 
diff --git a/src/ev_select.c b/src/ev_select.c
index 0f9b87e..464635b 100644
--- a/src/ev_select.c
+++ b/src/ev_select.c
@@ -164,15 +164,13 @@
 	delta_ms = compute_poll_timeout(exp);
 	delta.tv_sec  = (delta_ms / 1000);
 	delta.tv_usec = (delta_ms % 1000) * 1000;
-	gettimeofday(&before_poll, NULL);
+	tv_entering_poll();
 	status = select(maxfd,
 			readnotnull ? tmp_evts[DIR_RD] : NULL,
 			writenotnull ? tmp_evts[DIR_WR] : NULL,
 			NULL,
 			&delta);
-
-	tv_update_date(delta_ms, status);
-	measure_idle();
+	tv_leaving_poll(delta_ms, status);
 
 	thread_harmless_end();