summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ev.c12
-rw-r--r--ev_kqueue.c3
-rw-r--r--ev_port.c3
-rw-r--r--ev_select.c3
-rw-r--r--event.c9
5 files changed, 9 insertions, 21 deletions
diff --git a/ev.c b/ev.c
index 81bbd88..8ef1f03 100644
--- a/ev.c
+++ b/ev.c
@@ -450,7 +450,6 @@ struct signalfd_siginfo
# endif
#endif
-
/**/
#if EV_VERIFY >= 3
@@ -472,6 +471,9 @@ struct signalfd_siginfo
#define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */
#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
+#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0)
+#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; tv.tv_nsec = (long)((t - tv.tv_sec) * 1e9); } while (0)
+
#if __GNUC__ >= 4
# define expect(expr,value) __builtin_expect ((expr),(value))
# define noinline __attribute__ ((noinline))
@@ -771,21 +773,17 @@ ev_sleep (ev_tstamp delay)
#if EV_USE_NANOSLEEP
struct timespec ts;
- ts.tv_sec = (time_t)delay;
- ts.tv_nsec = (long)((delay - (ev_tstamp)(ts.tv_sec)) * 1e9);
-
+ EV_SET_TS (ts, delay);
nanosleep (&ts, 0);
#elif defined(_WIN32)
Sleep ((unsigned long)(delay * 1e3));
#else
struct timeval tv;
- tv.tv_sec = (time_t)delay;
- tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6);
-
/* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
/* something not guaranteed by newer posix versions, but guaranteed */
/* by older ones */
+ EV_SET_TV (tv, delay);
select (0, 0, 0, 0, &tv);
#endif
}
diff --git a/ev_kqueue.c b/ev_kqueue.c
index 2ab8a58..ab6000e 100644
--- a/ev_kqueue.c
+++ b/ev_kqueue.c
@@ -97,8 +97,7 @@ kqueue_poll (EV_P_ ev_tstamp timeout)
}
EV_RELEASE_CB;
- ts.tv_sec = (time_t)timeout;
- ts.tv_nsec = (long)((timeout - (ev_tstamp)ts.tv_sec) * 1e9);
+ EV_SET_TV (tv, timeout);
res = kevent (backend_fd, kqueue_changes, kqueue_changecnt, kqueue_events, kqueue_eventmax, &ts);
EV_ACQUIRE_CB;
kqueue_changecnt = 0;
diff --git a/ev_port.c b/ev_port.c
index 9b3041c..a482ce6 100644
--- a/ev_port.c
+++ b/ev_port.c
@@ -86,8 +86,7 @@ port_poll (EV_P_ ev_tstamp timeout)
uint_t nget = 1;
EV_RELEASE_CB;
- ts.tv_sec = (time_t)timeout;
- ts.tv_nsec = ((long)(timeout - (ev_tstamp)ts.tv_sec) * 1e9);
+ EV_TS_SET (ts, timeout);
res = port_getn (backend_fd, port_events, port_eventmax, &nget, &ts);
EV_ACQUIRE_CB;
diff --git a/ev_select.c b/ev_select.c
index b11a413..05486e0 100644
--- a/ev_select.c
+++ b/ev_select.c
@@ -141,8 +141,7 @@ select_poll (EV_P_ ev_tstamp timeout)
int fd_setsize;
EV_RELEASE_CB;
- tv.tv_sec = (long)timeout;
- tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6);
+ EV_TV_SET (tv, timeout);
#if EV_SELECT_USE_FD_SET
fd_setsize = sizeof (fd_set);
diff --git a/event.c b/event.c
index 4124769..af6267f 100644
--- a/event.c
+++ b/event.c
@@ -63,13 +63,6 @@ struct event_base
static struct event_base *ev_x_cur;
-static void
-ev_tv_set (struct timeval *tv, ev_tstamp at)
-{
- tv->tv_sec = (long)at;
- tv->tv_usec = (long)((at - (ev_tstamp)tv->tv_sec) * 1e6);
-}
-
static ev_tstamp
ev_tv_get (struct timeval *tv)
{
@@ -305,7 +298,7 @@ int event_pending (struct event *ev, short events, struct timeval *tv)
revents |= EV_TIMEOUT;
if (tv)
- ev_tv_set (tv, ev_now (EV_A)); /* not sure if this is right :) */
+ EV_TV_SET (tv, ev_now (EV_A)); /* not sure if this is right :) */
}
return events & revents;