… | |
… | |
113 | } |
113 | } |
114 | |
114 | |
115 | #define array_needsize(base,cur,cnt,init) \ |
115 | #define array_needsize(base,cur,cnt,init) \ |
116 | if ((cnt) > cur) \ |
116 | if ((cnt) > cur) \ |
117 | { \ |
117 | { \ |
118 | int newcnt = cur ? cur << 1 : 16; \ |
118 | int newcnt = cur; \ |
|
|
119 | do \ |
|
|
120 | { \ |
|
|
121 | newcnt = (newcnt << 1) | 4 & ~3; \ |
|
|
122 | } \ |
|
|
123 | while ((cnt) > newcnt); \ |
|
|
124 | \ |
119 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
125 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
120 | init (base + cur, newcnt - cur); \ |
126 | init (base + cur, newcnt - cur); \ |
121 | cur = newcnt; \ |
127 | cur = newcnt; \ |
122 | } |
128 | } |
123 | |
129 | |
… | |
… | |
368 | # include "ev_select.c" |
374 | # include "ev_select.c" |
369 | #endif |
375 | #endif |
370 | |
376 | |
371 | int ev_init (int flags) |
377 | int ev_init (int flags) |
372 | { |
378 | { |
|
|
379 | if (!ev_method) |
|
|
380 | { |
373 | #if HAVE_MONOTONIC |
381 | #if HAVE_MONOTONIC |
374 | { |
382 | { |
375 | struct timespec ts; |
383 | struct timespec ts; |
376 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
384 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
377 | have_monotonic = 1; |
385 | have_monotonic = 1; |
378 | } |
386 | } |
379 | #endif |
387 | #endif |
380 | |
388 | |
381 | ev_now = ev_time (); |
389 | ev_now = ev_time (); |
382 | now = get_clock (); |
390 | now = get_clock (); |
383 | diff = ev_now - now; |
391 | diff = ev_now - now; |
384 | |
392 | |
385 | if (pipe (sigpipe)) |
393 | if (pipe (sigpipe)) |
386 | return 0; |
394 | return 0; |
387 | |
395 | |
388 | ev_method = EVMETHOD_NONE; |
396 | ev_method = EVMETHOD_NONE; |
389 | #if HAVE_EPOLL |
397 | #if HAVE_EPOLL |
390 | if (ev_method == EVMETHOD_NONE) epoll_init (flags); |
398 | if (ev_method == EVMETHOD_NONE) epoll_init (flags); |
391 | #endif |
399 | #endif |
392 | #if HAVE_SELECT |
400 | #if HAVE_SELECT |
393 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
401 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
394 | #endif |
402 | #endif |
395 | |
403 | |
396 | if (ev_method) |
404 | if (ev_method) |
397 | { |
405 | { |
398 | evw_init (&sigev, sigcb); |
406 | evw_init (&sigev, sigcb); |
399 | siginit (); |
407 | siginit (); |
400 | |
408 | |
401 | evsignal_init (&childev, childcb, SIGCHLD); |
409 | evsignal_init (&childev, childcb, SIGCHLD); |
402 | evsignal_start (&childev); |
410 | evsignal_start (&childev); |
|
|
411 | } |
403 | } |
412 | } |
404 | |
413 | |
405 | return ev_method; |
414 | return ev_method; |
406 | } |
415 | } |
407 | |
416 | |