… | |
… | |
225 | |
225 | |
226 | /*****************************************************************************/ |
226 | /*****************************************************************************/ |
227 | |
227 | |
228 | static void (*syserr_cb)(const char *msg); |
228 | static void (*syserr_cb)(const char *msg); |
229 | |
229 | |
|
|
230 | void |
230 | void ev_set_syserr_cb (void (*cb)(const char *msg)) |
231 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
231 | { |
232 | { |
232 | syserr_cb = cb; |
233 | syserr_cb = cb; |
233 | } |
234 | } |
234 | |
235 | |
235 | static void |
236 | static void noinline |
236 | syserr (const char *msg) |
237 | syserr (const char *msg) |
237 | { |
238 | { |
238 | if (!msg) |
239 | if (!msg) |
239 | msg = "(libev) system error"; |
240 | msg = "(libev) system error"; |
240 | |
241 | |
… | |
… | |
247 | } |
248 | } |
248 | } |
249 | } |
249 | |
250 | |
250 | static void *(*alloc)(void *ptr, long size); |
251 | static void *(*alloc)(void *ptr, long size); |
251 | |
252 | |
|
|
253 | void |
252 | void ev_set_allocator (void *(*cb)(void *ptr, long size)) |
254 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
253 | { |
255 | { |
254 | alloc = cb; |
256 | alloc = cb; |
255 | } |
257 | } |
256 | |
258 | |
257 | static void * |
259 | static void * |
… | |
… | |
315 | |
317 | |
316 | #endif |
318 | #endif |
317 | |
319 | |
318 | /*****************************************************************************/ |
320 | /*****************************************************************************/ |
319 | |
321 | |
320 | ev_tstamp noinline |
322 | ev_tstamp |
321 | ev_time (void) |
323 | ev_time (void) |
322 | { |
324 | { |
323 | #if EV_USE_REALTIME |
325 | #if EV_USE_REALTIME |
324 | struct timespec ts; |
326 | struct timespec ts; |
325 | clock_gettime (CLOCK_REALTIME, &ts); |
327 | clock_gettime (CLOCK_REALTIME, &ts); |
… | |
… | |
382 | #define array_free(stem, idx) \ |
384 | #define array_free(stem, idx) \ |
383 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
385 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; |
384 | |
386 | |
385 | /*****************************************************************************/ |
387 | /*****************************************************************************/ |
386 | |
388 | |
387 | void inline_size |
|
|
388 | anfds_init (ANFD *base, int count) |
|
|
389 | { |
|
|
390 | while (count--) |
|
|
391 | { |
|
|
392 | base->head = 0; |
|
|
393 | base->events = EV_NONE; |
|
|
394 | base->reify = 0; |
|
|
395 | |
|
|
396 | ++base; |
|
|
397 | } |
|
|
398 | } |
|
|
399 | |
|
|
400 | void noinline |
389 | void noinline |
401 | ev_feed_event (EV_P_ void *w, int revents) |
390 | ev_feed_event (EV_P_ void *w, int revents) |
402 | { |
391 | { |
403 | W w_ = (W)w; |
392 | W w_ = (W)w; |
404 | |
393 | |
… | |
… | |
412 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
401 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
413 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
402 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
414 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
403 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
415 | } |
404 | } |
416 | |
405 | |
417 | static void |
406 | void inline_size |
418 | queue_events (EV_P_ W *events, int eventcnt, int type) |
407 | queue_events (EV_P_ W *events, int eventcnt, int type) |
419 | { |
408 | { |
420 | int i; |
409 | int i; |
421 | |
410 | |
422 | for (i = 0; i < eventcnt; ++i) |
411 | for (i = 0; i < eventcnt; ++i) |
423 | ev_feed_event (EV_A_ events [i], type); |
412 | ev_feed_event (EV_A_ events [i], type); |
424 | } |
413 | } |
425 | |
414 | |
|
|
415 | /*****************************************************************************/ |
|
|
416 | |
|
|
417 | void inline_size |
|
|
418 | anfds_init (ANFD *base, int count) |
|
|
419 | { |
|
|
420 | while (count--) |
|
|
421 | { |
|
|
422 | base->head = 0; |
|
|
423 | base->events = EV_NONE; |
|
|
424 | base->reify = 0; |
|
|
425 | |
|
|
426 | ++base; |
|
|
427 | } |
|
|
428 | } |
|
|
429 | |
426 | void inline_speed |
430 | void inline_speed |
427 | fd_event (EV_P_ int fd, int revents) |
431 | fd_event (EV_P_ int fd, int revents) |
428 | { |
432 | { |
429 | ANFD *anfd = anfds + fd; |
433 | ANFD *anfd = anfds + fd; |
430 | ev_io *w; |
434 | ev_io *w; |
… | |
… | |
441 | void |
445 | void |
442 | ev_feed_fd_event (EV_P_ int fd, int revents) |
446 | ev_feed_fd_event (EV_P_ int fd, int revents) |
443 | { |
447 | { |
444 | fd_event (EV_A_ fd, revents); |
448 | fd_event (EV_A_ fd, revents); |
445 | } |
449 | } |
446 | |
|
|
447 | /*****************************************************************************/ |
|
|
448 | |
450 | |
449 | void inline_size |
451 | void inline_size |
450 | fd_reify (EV_P) |
452 | fd_reify (EV_P) |
451 | { |
453 | { |
452 | int i; |
454 | int i; |
… | |
… | |
712 | static ev_child *childs [PID_HASHSIZE]; |
714 | static ev_child *childs [PID_HASHSIZE]; |
713 | |
715 | |
714 | #ifndef _WIN32 |
716 | #ifndef _WIN32 |
715 | |
717 | |
716 | static ev_signal childev; |
718 | static ev_signal childev; |
717 | |
|
|
718 | #ifndef WCONTINUED |
|
|
719 | # define WCONTINUED 0 |
|
|
720 | #endif |
|
|
721 | |
719 | |
722 | void inline_speed |
720 | void inline_speed |
723 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
721 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
724 | { |
722 | { |
725 | ev_child *w; |
723 | ev_child *w; |
… | |
… | |
732 | w->rstatus = status; |
730 | w->rstatus = status; |
733 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
731 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
734 | } |
732 | } |
735 | } |
733 | } |
736 | |
734 | |
|
|
735 | #ifndef WCONTINUED |
|
|
736 | # define WCONTINUED 0 |
|
|
737 | #endif |
|
|
738 | |
737 | static void |
739 | static void |
738 | childcb (EV_P_ ev_signal *sw, int revents) |
740 | childcb (EV_P_ ev_signal *sw, int revents) |
739 | { |
741 | { |
740 | int pid, status; |
742 | int pid, status; |
741 | |
743 | |
|
|
744 | /* some systems define WCONTINUED but then fail to support it (linux 2.4) */ |
742 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
745 | if (0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
743 | { |
746 | if (!WCONTINUED |
|
|
747 | || errno != EINVAL |
|
|
748 | || 0 >= (pid = waitpid (-1, &status, WNOHANG | WUNTRACED))) |
|
|
749 | return; |
|
|
750 | |
744 | /* make sure we are called again until all childs have been reaped */ |
751 | /* make sure we are called again until all childs have been reaped */ |
745 | /* we need to do it this way so that the callback gets called before we continue */ |
752 | /* we need to do it this way so that the callback gets called before we continue */ |
746 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
753 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
747 | |
754 | |
748 | child_reap (EV_A_ sw, pid, pid, status); |
755 | child_reap (EV_A_ sw, pid, pid, status); |
749 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
756 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but feed_event catches that */ |
750 | } |
|
|
751 | } |
757 | } |
752 | |
758 | |
753 | #endif |
759 | #endif |
754 | |
760 | |
755 | /*****************************************************************************/ |
761 | /*****************************************************************************/ |
… | |
… | |
1759 | |
1765 | |
1760 | # ifdef _WIN32 |
1766 | # ifdef _WIN32 |
1761 | # define lstat(a,b) stat(a,b) |
1767 | # define lstat(a,b) stat(a,b) |
1762 | # endif |
1768 | # endif |
1763 | |
1769 | |
|
|
1770 | #define DEF_STAT_INTERVAL 5.0074891 |
|
|
1771 | #define MIN_STAT_INTERVAL 0.1074891 |
|
|
1772 | |
1764 | void |
1773 | void |
1765 | ev_stat_stat (EV_P_ ev_stat *w) |
1774 | ev_stat_stat (EV_P_ ev_stat *w) |
1766 | { |
1775 | { |
1767 | if (lstat (w->path, &w->attr) < 0) |
1776 | if (lstat (w->path, &w->attr) < 0) |
1768 | w->attr.st_nlink = 0; |
1777 | w->attr.st_nlink = 0; |
… | |
… | |
1793 | /* since we use memcmp, we need to clear any padding data etc. */ |
1802 | /* since we use memcmp, we need to clear any padding data etc. */ |
1794 | memset (&w->prev, 0, sizeof (ev_statdata)); |
1803 | memset (&w->prev, 0, sizeof (ev_statdata)); |
1795 | memset (&w->attr, 0, sizeof (ev_statdata)); |
1804 | memset (&w->attr, 0, sizeof (ev_statdata)); |
1796 | |
1805 | |
1797 | ev_stat_stat (EV_A_ w); |
1806 | ev_stat_stat (EV_A_ w); |
|
|
1807 | |
|
|
1808 | if (w->interval < MIN_STAT_INTERVAL) |
|
|
1809 | w->interval = w->interval ? MIN_STAT_INTERVAL : DEF_STAT_INTERVAL; |
1798 | |
1810 | |
1799 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
1811 | ev_timer_init (&w->timer, stat_timer_cb, w->interval, w->interval); |
1800 | ev_set_priority (&w->timer, ev_priority (w)); |
1812 | ev_set_priority (&w->timer, ev_priority (w)); |
1801 | ev_timer_start (EV_A_ &w->timer); |
1813 | ev_timer_start (EV_A_ &w->timer); |
1802 | |
1814 | |