summaryrefslogtreecommitdiff
path: root/lib/libevent
diff options
context:
space:
mode:
authorBrad Smith <brad@cvs.openbsd.org>2006-03-28 15:32:14 +0000
committerBrad Smith <brad@cvs.openbsd.org>2006-03-28 15:32:14 +0000
commitcff9071d88082990af47a0a05d95dfb54bdff887 (patch)
tree2bf0d3b748d8494adb6d2811b146739d14db7d30 /lib/libevent
parent7f51172409696fad7c4d2793e777d1dd1271d0ad (diff)
use clock_gettime if available.
From claudio@ via libevent CVS ok claudio@
Diffstat (limited to 'lib/libevent')
-rw-r--r--lib/libevent/Makefile3
-rw-r--r--lib/libevent/event.c38
2 files changed, 32 insertions, 9 deletions
diff --git a/lib/libevent/Makefile b/lib/libevent/Makefile
index cd1f36ba6f5..5a76c369aa7 100644
--- a/lib/libevent/Makefile
+++ b/lib/libevent/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.19 2006/01/23 20:18:20 brad Exp $
+# $OpenBSD: Makefile,v 1.20 2006/03/28 15:32:13 brad Exp $
LIB= event
WANTLINT=
@@ -24,6 +24,7 @@ MLINKS= event.3 event_init.3 event.3 event_dispatch.3 event.3 event_loop.3 \
event.3 evbuffer_readline.3
CFLAGS+= -I${.CURDIR} \
+ -DHAVE_CLOCK_GETTIME \
-DHAVE_FCNTL_H \
-DHAVE_POLL \
-DHAVE_SELECT \
diff --git a/lib/libevent/event.c b/lib/libevent/event.c
index fb5e1bac179..b03918d3f11 100644
--- a/lib/libevent/event.c
+++ b/lib/libevent/event.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: event.c,v 1.11 2005/07/02 07:15:13 grunk Exp $ */
+/* $OpenBSD: event.c,v 1.12 2006/03/28 15:32:13 brad Exp $ */
/*
* Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
@@ -140,6 +140,23 @@ compare(struct event *a, struct event *b)
return (0);
}
+static int
+gettime(struct timeval *tp)
+{
+#ifdef HAVE_CLOCK_GETTIME
+ struct timespec ts;
+
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1)
+ return (-1);
+ tp->tv_sec = ts.tv_sec;
+ tp->tv_usec = ts.tv_nsec / 1000;
+#else
+ gettimeofday(tp, NULL);
+#endif
+
+ return (0);
+}
+
RB_PROTOTYPE(event_tree, event, ev_timeout_node, compare);
RB_GENERATE(event_tree, event, ev_timeout_node, compare);
@@ -155,7 +172,7 @@ event_init(void)
event_sigcb = NULL;
event_gotsig = 0;
- gettimeofday(&current_base->event_tv, NULL);
+ gettime(&current_base->event_tv);
RB_INIT(&current_base->timetree);
TAILQ_INIT(&current_base->eventqueue);
@@ -343,7 +360,7 @@ event_base_loop(struct event_base *base, int flags)
}
/* Check if time is running backwards */
- gettimeofday(&tv, NULL);
+ gettime(&tv);
if (timercmp(&tv, &base->event_tv, <)) {
struct timeval off;
event_debug(("%s: time is running backwards, corrected",
@@ -504,6 +521,7 @@ event_priority_set(struct event *ev, int pri)
int
event_pending(struct event *ev, short event, struct timeval *tv)
{
+ struct timeval now, res;
int flags = 0;
if (ev->ev_flags & EVLIST_INSERTED)
@@ -518,8 +536,12 @@ event_pending(struct event *ev, short event, struct timeval *tv)
event &= (EV_TIMEOUT|EV_READ|EV_WRITE|EV_SIGNAL);
/* See if there is a timeout that we should report */
- if (tv != NULL && (flags & event & EV_TIMEOUT))
- *tv = ev->ev_timeout;
+ if (tv != NULL && (flags & event & EV_TIMEOUT)) {
+ gettime(&now);
+ timersub(&ev->ev_timeout, &now, &res);
+ gettimeofday(&now, NULL);
+ timeradd(&now, &res, tv);
+ }
return (flags & event);
}
@@ -563,7 +585,7 @@ event_add(struct event *ev, struct timeval *tv)
event_queue_remove(base, ev, EVLIST_ACTIVE);
}
- gettimeofday(&now, NULL);
+ gettime(&now);
timeradd(&now, tv, &ev->ev_timeout);
event_debug((
@@ -659,7 +681,7 @@ timeout_next(struct event_base *base, struct timeval *tv)
return (0);
}
- if (gettimeofday(&now, NULL) == -1)
+ if (gettime(&now) == -1)
return (-1);
if (timercmp(&ev->ev_timeout, &now, <=)) {
@@ -695,7 +717,7 @@ timeout_process(struct event_base *base)
struct timeval now;
struct event *ev, *next;
- gettimeofday(&now, NULL);
+ gettime(&now);
for (ev = RB_MIN(event_tree, &base->timetree); ev; ev = next) {
if (timercmp(&ev->ev_timeout, &now, >))