summaryrefslogtreecommitdiff
path: root/ev.c
diff options
context:
space:
mode:
authorroot <root>2010-10-15 22:44:41 +0000
committerroot <root>2010-10-15 22:44:41 +0000
commitfdc074f34b5284968cb4174e9c5d2bc253d70d4c (patch)
tree6ce10fe71c36eadc30790d780d0ceb70862ec709 /ev.c
parent434c3b77aa4f5ced4961b2ec6b3397c9c683d0fd (diff)
clean up tv/ts handling
Diffstat (limited to 'ev.c')
-rw-r--r--ev.c12
1 files changed, 5 insertions, 7 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
}