summaryrefslogtreecommitdiff
path: root/ev.c
diff options
context:
space:
mode:
authorroot <root>2007-10-31 20:10:17 +0000
committerroot <root>2007-10-31 20:10:17 +0000
commitde6670e4475f8cc20fa55cf2c5e40f8de9df5812 (patch)
treeebd64caea9919c9829c1393d2d3b2bb0a527e198 /ev.c
parentcc491ddade261fb0e1755c6da29a95f1c66e8b32 (diff)
better resize
Diffstat (limited to 'ev.c')
-rw-r--r--ev.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/ev.c b/ev.c
index b2e48f8..f48b007 100644
--- a/ev.c
+++ b/ev.c
@@ -115,7 +115,13 @@ get_clock (void)
#define array_needsize(base,cur,cnt,init) \
if ((cnt) > cur) \
{ \
- int newcnt = cur ? cur << 1 : 16; \
+ int newcnt = cur; \
+ do \
+ { \
+ newcnt = (newcnt << 1) | 4 & ~3; \
+ } \
+ while ((cnt) > newcnt); \
+ \
base = realloc (base, sizeof (*base) * (newcnt)); \
init (base + cur, newcnt - cur); \
cur = newcnt; \
@@ -370,36 +376,39 @@ childcb (struct ev_signal *sw, int revents)
int ev_init (int flags)
{
+ if (!ev_method)
+ {
#if HAVE_MONOTONIC
- {
- struct timespec ts;
- if (!clock_gettime (CLOCK_MONOTONIC, &ts))
- have_monotonic = 1;
- }
+ {
+ struct timespec ts;
+ if (!clock_gettime (CLOCK_MONOTONIC, &ts))
+ have_monotonic = 1;
+ }
#endif
- ev_now = ev_time ();
- now = get_clock ();
- diff = ev_now - now;
+ ev_now = ev_time ();
+ now = get_clock ();
+ diff = ev_now - now;
- if (pipe (sigpipe))
- return 0;
+ if (pipe (sigpipe))
+ return 0;
- ev_method = EVMETHOD_NONE;
+ ev_method = EVMETHOD_NONE;
#if HAVE_EPOLL
- if (ev_method == EVMETHOD_NONE) epoll_init (flags);
+ if (ev_method == EVMETHOD_NONE) epoll_init (flags);
#endif
#if HAVE_SELECT
- if (ev_method == EVMETHOD_NONE) select_init (flags);
+ if (ev_method == EVMETHOD_NONE) select_init (flags);
#endif
- if (ev_method)
- {
- evw_init (&sigev, sigcb);
- siginit ();
+ if (ev_method)
+ {
+ evw_init (&sigev, sigcb);
+ siginit ();
- evsignal_init (&childev, childcb, SIGCHLD);
- evsignal_start (&childev);
+ evsignal_init (&childev, childcb, SIGCHLD);
+ evsignal_start (&childev);
+ }
}
return ev_method;