Browse Source

clean up tv/ts handling

master
Marc Alexander Lehmann 11 years ago
parent
commit
616dbfae77
  1. 12
      ev.c
  2. 3
      ev_kqueue.c
  3. 3
      ev_port.c
  4. 3
      ev_select.c
  5. 9
      event.c

12
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
}

3
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;

3
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;

3
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);

9
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;

Loading…
Cancel
Save