… | |
… | |
64 | #include <assert.h> |
64 | #include <assert.h> |
65 | #include <errno.h> |
65 | #include <errno.h> |
66 | #include <sys/types.h> |
66 | #include <sys/types.h> |
67 | #include <time.h> |
67 | #include <time.h> |
68 | |
68 | |
69 | #ifndef PERL |
|
|
70 | # include <signal.h> |
69 | #include <signal.h> |
71 | #endif |
|
|
72 | |
70 | |
73 | #ifndef WIN32 |
71 | #ifndef WIN32 |
74 | # include <unistd.h> |
72 | # include <unistd.h> |
75 | # include <sys/time.h> |
73 | # include <sys/time.h> |
76 | # include <sys/wait.h> |
74 | # include <sys/wait.h> |
… | |
… | |
150 | typedef struct ev_watcher_list *WL; |
148 | typedef struct ev_watcher_list *WL; |
151 | typedef struct ev_watcher_time *WT; |
149 | typedef struct ev_watcher_time *WT; |
152 | |
150 | |
153 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
151 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
154 | |
152 | |
155 | #if WIN32 |
153 | #include "ev_win32.c" |
156 | /* note: the comment below could not be substantiated, but what would I care */ |
|
|
157 | /* MSDN says this is required to handle SIGFPE */ |
|
|
158 | volatile double SIGFPE_REQ = 0.0f; |
|
|
159 | #endif |
|
|
160 | |
154 | |
161 | /*****************************************************************************/ |
155 | /*****************************************************************************/ |
162 | |
156 | |
163 | static void (*syserr_cb)(const char *msg); |
157 | static void (*syserr_cb)(const char *msg); |
164 | |
158 | |
… | |
… | |
274 | ev_now (EV_P) |
268 | ev_now (EV_P) |
275 | { |
269 | { |
276 | return rt_now; |
270 | return rt_now; |
277 | } |
271 | } |
278 | |
272 | |
279 | #define array_roundsize(base,n) ((n) | 4 & ~3) |
273 | #define array_roundsize(type,n) ((n) | 4 & ~3) |
280 | |
274 | |
281 | #define array_needsize(base,cur,cnt,init) \ |
275 | #define array_needsize(type,base,cur,cnt,init) \ |
282 | if (expect_false ((cnt) > cur)) \ |
276 | if (expect_false ((cnt) > cur)) \ |
283 | { \ |
277 | { \ |
284 | int newcnt = cur; \ |
278 | int newcnt = cur; \ |
285 | do \ |
279 | do \ |
286 | { \ |
280 | { \ |
287 | newcnt = array_roundsize (base, newcnt << 1); \ |
281 | newcnt = array_roundsize (type, newcnt << 1); \ |
288 | } \ |
282 | } \ |
289 | while ((cnt) > newcnt); \ |
283 | while ((cnt) > newcnt); \ |
290 | \ |
284 | \ |
291 | base = ev_realloc (base, sizeof (*base) * (newcnt)); \ |
285 | base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\ |
292 | init (base + cur, newcnt - cur); \ |
286 | init (base + cur, newcnt - cur); \ |
293 | cur = newcnt; \ |
287 | cur = newcnt; \ |
294 | } |
288 | } |
295 | |
289 | |
296 | #define array_slim(stem) \ |
290 | #define array_slim(type,stem) \ |
297 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
291 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
298 | { \ |
292 | { \ |
299 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
293 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
300 | base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ |
294 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
301 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
295 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
302 | } |
296 | } |
303 | |
297 | |
304 | /* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ |
298 | /* microsoft's pseudo-c is quite far from C as the rest of the world and the standard knows it */ |
305 | /* bringing us everlasting joy in form of stupid extra macros that are not required in C */ |
299 | /* bringing us everlasting joy in form of stupid extra macros that are not required in C */ |
… | |
… | |
322 | |
316 | |
323 | ++base; |
317 | ++base; |
324 | } |
318 | } |
325 | } |
319 | } |
326 | |
320 | |
327 | static void |
321 | void |
328 | event (EV_P_ W w, int events) |
322 | ev_feed_event (EV_P_ void *w, int revents) |
329 | { |
323 | { |
|
|
324 | W w_ = (W)w; |
|
|
325 | |
330 | if (w->pending) |
326 | if (w_->pending) |
331 | { |
327 | { |
332 | pendings [ABSPRI (w)][w->pending - 1].events |= events; |
328 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
333 | return; |
329 | return; |
334 | } |
330 | } |
335 | |
331 | |
336 | w->pending = ++pendingcnt [ABSPRI (w)]; |
332 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
337 | array_needsize (pendings [ABSPRI (w)], pendingmax [ABSPRI (w)], pendingcnt [ABSPRI (w)], (void)); |
333 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], (void)); |
338 | pendings [ABSPRI (w)][w->pending - 1].w = w; |
334 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
339 | pendings [ABSPRI (w)][w->pending - 1].events = events; |
335 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
340 | } |
336 | } |
341 | |
337 | |
342 | static void |
338 | static void |
343 | queue_events (EV_P_ W *events, int eventcnt, int type) |
339 | queue_events (EV_P_ W *events, int eventcnt, int type) |
344 | { |
340 | { |
345 | int i; |
341 | int i; |
346 | |
342 | |
347 | for (i = 0; i < eventcnt; ++i) |
343 | for (i = 0; i < eventcnt; ++i) |
348 | event (EV_A_ events [i], type); |
344 | ev_feed_event (EV_A_ events [i], type); |
349 | } |
345 | } |
350 | |
346 | |
351 | static void |
347 | static void |
352 | fd_event (EV_P_ int fd, int events) |
348 | fd_event (EV_P_ int fd, int events) |
353 | { |
349 | { |
… | |
… | |
357 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
353 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
358 | { |
354 | { |
359 | int ev = w->events & events; |
355 | int ev = w->events & events; |
360 | |
356 | |
361 | if (ev) |
357 | if (ev) |
362 | event (EV_A_ (W)w, ev); |
358 | ev_feed_event (EV_A_ (W)w, ev); |
363 | } |
359 | } |
364 | } |
360 | } |
365 | |
361 | |
366 | /*****************************************************************************/ |
362 | /*****************************************************************************/ |
367 | |
363 | |
… | |
… | |
397 | return; |
393 | return; |
398 | |
394 | |
399 | anfds [fd].reify = 1; |
395 | anfds [fd].reify = 1; |
400 | |
396 | |
401 | ++fdchangecnt; |
397 | ++fdchangecnt; |
402 | array_needsize (fdchanges, fdchangemax, fdchangecnt, (void)); |
398 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); |
403 | fdchanges [fdchangecnt - 1] = fd; |
399 | fdchanges [fdchangecnt - 1] = fd; |
404 | } |
400 | } |
405 | |
401 | |
406 | static void |
402 | static void |
407 | fd_kill (EV_P_ int fd) |
403 | fd_kill (EV_P_ int fd) |
… | |
… | |
409 | struct ev_io *w; |
405 | struct ev_io *w; |
410 | |
406 | |
411 | while ((w = (struct ev_io *)anfds [fd].head)) |
407 | while ((w = (struct ev_io *)anfds [fd].head)) |
412 | { |
408 | { |
413 | ev_io_stop (EV_A_ w); |
409 | ev_io_stop (EV_A_ w); |
414 | event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
410 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
415 | } |
411 | } |
416 | } |
412 | } |
417 | |
413 | |
418 | static int |
414 | static int |
419 | fd_valid (int fd) |
415 | fd_valid (int fd) |
… | |
… | |
547 | |
543 | |
548 | if (!gotsig) |
544 | if (!gotsig) |
549 | { |
545 | { |
550 | int old_errno = errno; |
546 | int old_errno = errno; |
551 | gotsig = 1; |
547 | gotsig = 1; |
|
|
548 | #ifdef WIN32 |
|
|
549 | send (sigpipe [1], &signum, 1, MSG_DONTWAIT); |
|
|
550 | #else |
552 | write (sigpipe [1], &signum, 1); |
551 | write (sigpipe [1], &signum, 1); |
|
|
552 | #endif |
553 | errno = old_errno; |
553 | errno = old_errno; |
554 | } |
554 | } |
555 | } |
555 | } |
556 | |
556 | |
557 | static void |
557 | static void |
558 | sigcb (EV_P_ struct ev_io *iow, int revents) |
558 | sigcb (EV_P_ struct ev_io *iow, int revents) |
559 | { |
559 | { |
560 | WL w; |
560 | WL w; |
561 | int signum; |
561 | int signum; |
562 | |
562 | |
|
|
563 | #ifdef WIN32 |
|
|
564 | recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); |
|
|
565 | #else |
563 | read (sigpipe [0], &revents, 1); |
566 | read (sigpipe [0], &revents, 1); |
|
|
567 | #endif |
564 | gotsig = 0; |
568 | gotsig = 0; |
565 | |
569 | |
566 | for (signum = signalmax; signum--; ) |
570 | for (signum = signalmax; signum--; ) |
567 | if (signals [signum].gotsig) |
571 | if (signals [signum].gotsig) |
568 | { |
572 | { |
569 | signals [signum].gotsig = 0; |
573 | signals [signum].gotsig = 0; |
570 | |
574 | |
571 | for (w = signals [signum].head; w; w = w->next) |
575 | for (w = signals [signum].head; w; w = w->next) |
572 | event (EV_A_ (W)w, EV_SIGNAL); |
576 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
573 | } |
577 | } |
574 | } |
578 | } |
575 | |
579 | |
576 | static void |
580 | static void |
577 | siginit (EV_P) |
581 | siginit (EV_P) |
… | |
… | |
611 | if (w->pid == pid || !w->pid) |
615 | if (w->pid == pid || !w->pid) |
612 | { |
616 | { |
613 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
617 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
614 | w->rpid = pid; |
618 | w->rpid = pid; |
615 | w->rstatus = status; |
619 | w->rstatus = status; |
616 | event (EV_A_ (W)w, EV_CHILD); |
620 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
617 | } |
621 | } |
618 | } |
622 | } |
619 | |
623 | |
620 | static void |
624 | static void |
621 | childcb (EV_P_ struct ev_signal *sw, int revents) |
625 | childcb (EV_P_ struct ev_signal *sw, int revents) |
… | |
… | |
623 | int pid, status; |
627 | int pid, status; |
624 | |
628 | |
625 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
629 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
626 | { |
630 | { |
627 | /* make sure we are called again until all childs have been reaped */ |
631 | /* make sure we are called again until all childs have been reaped */ |
628 | event (EV_A_ (W)sw, EV_SIGNAL); |
632 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
629 | |
633 | |
630 | child_reap (EV_A_ sw, pid, pid, status); |
634 | child_reap (EV_A_ sw, pid, pid, status); |
631 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
635 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
632 | } |
636 | } |
633 | } |
637 | } |
… | |
… | |
894 | if (method) |
898 | if (method) |
895 | postfork = 1; |
899 | postfork = 1; |
896 | } |
900 | } |
897 | |
901 | |
898 | /*****************************************************************************/ |
902 | /*****************************************************************************/ |
|
|
903 | |
|
|
904 | static int |
|
|
905 | any_pending (EV_P) |
|
|
906 | { |
|
|
907 | int pri; |
|
|
908 | |
|
|
909 | for (pri = NUMPRI; pri--; ) |
|
|
910 | if (pendingcnt [pri]) |
|
|
911 | return 1; |
|
|
912 | |
|
|
913 | return 0; |
|
|
914 | } |
899 | |
915 | |
900 | static void |
916 | static void |
901 | call_pending (EV_P) |
917 | call_pending (EV_P) |
902 | { |
918 | { |
903 | int pri; |
919 | int pri; |
… | |
… | |
932 | downheap ((WT *)timers, timercnt, 0); |
948 | downheap ((WT *)timers, timercnt, 0); |
933 | } |
949 | } |
934 | else |
950 | else |
935 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
951 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
936 | |
952 | |
937 | event (EV_A_ (W)w, EV_TIMEOUT); |
953 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
938 | } |
954 | } |
939 | } |
955 | } |
940 | |
956 | |
941 | static void |
957 | static void |
942 | periodics_reify (EV_P) |
958 | periodics_reify (EV_P) |
… | |
… | |
946 | struct ev_periodic *w = periodics [0]; |
962 | struct ev_periodic *w = periodics [0]; |
947 | |
963 | |
948 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
964 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
949 | |
965 | |
950 | /* first reschedule or stop timer */ |
966 | /* first reschedule or stop timer */ |
|
|
967 | if (w->reschedule_cb) |
|
|
968 | { |
|
|
969 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, rt_now + 0.0001); |
|
|
970 | |
|
|
971 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > rt_now)); |
|
|
972 | downheap ((WT *)periodics, periodiccnt, 0); |
|
|
973 | } |
951 | if (w->interval) |
974 | else if (w->interval) |
952 | { |
975 | { |
953 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
976 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
954 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
977 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
955 | downheap ((WT *)periodics, periodiccnt, 0); |
978 | downheap ((WT *)periodics, periodiccnt, 0); |
956 | } |
979 | } |
957 | else |
980 | else |
958 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
981 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
959 | |
982 | |
960 | event (EV_A_ (W)w, EV_PERIODIC); |
983 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
961 | } |
984 | } |
962 | } |
985 | } |
963 | |
986 | |
964 | static void |
987 | static void |
965 | periodics_reschedule (EV_P) |
988 | periodics_reschedule (EV_P) |
… | |
… | |
969 | /* adjust periodics after time jump */ |
992 | /* adjust periodics after time jump */ |
970 | for (i = 0; i < periodiccnt; ++i) |
993 | for (i = 0; i < periodiccnt; ++i) |
971 | { |
994 | { |
972 | struct ev_periodic *w = periodics [i]; |
995 | struct ev_periodic *w = periodics [i]; |
973 | |
996 | |
|
|
997 | if (w->reschedule_cb) |
|
|
998 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
974 | if (w->interval) |
999 | else if (w->interval) |
975 | { |
|
|
976 | ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1000 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
977 | |
|
|
978 | if (fabs (diff) >= 1e-4) |
|
|
979 | { |
|
|
980 | ev_periodic_stop (EV_A_ w); |
|
|
981 | ev_periodic_start (EV_A_ w); |
|
|
982 | |
|
|
983 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
|
|
984 | } |
|
|
985 | } |
|
|
986 | } |
1001 | } |
|
|
1002 | |
|
|
1003 | /* now rebuild the heap */ |
|
|
1004 | for (i = periodiccnt >> 1; i--; ) |
|
|
1005 | downheap ((WT *)periodics, periodiccnt, i); |
987 | } |
1006 | } |
988 | |
1007 | |
989 | inline int |
1008 | inline int |
990 | time_update_monotonic (EV_P) |
1009 | time_update_monotonic (EV_P) |
991 | { |
1010 | { |
… | |
… | |
1087 | /* update fd-related kernel structures */ |
1106 | /* update fd-related kernel structures */ |
1088 | fd_reify (EV_A); |
1107 | fd_reify (EV_A); |
1089 | |
1108 | |
1090 | /* calculate blocking time */ |
1109 | /* calculate blocking time */ |
1091 | |
1110 | |
1092 | /* we only need this for !monotonic clockor timers, but as we basically |
1111 | /* we only need this for !monotonic clock or timers, but as we basically |
1093 | always have timers, we just calculate it always */ |
1112 | always have timers, we just calculate it always */ |
1094 | #if EV_USE_MONOTONIC |
1113 | #if EV_USE_MONOTONIC |
1095 | if (expect_true (have_monotonic)) |
1114 | if (expect_true (have_monotonic)) |
1096 | time_update_monotonic (EV_A); |
1115 | time_update_monotonic (EV_A); |
1097 | else |
1116 | else |
… | |
… | |
1130 | /* queue pending timers and reschedule them */ |
1149 | /* queue pending timers and reschedule them */ |
1131 | timers_reify (EV_A); /* relative timers called last */ |
1150 | timers_reify (EV_A); /* relative timers called last */ |
1132 | periodics_reify (EV_A); /* absolute timers called first */ |
1151 | periodics_reify (EV_A); /* absolute timers called first */ |
1133 | |
1152 | |
1134 | /* queue idle watchers unless io or timers are pending */ |
1153 | /* queue idle watchers unless io or timers are pending */ |
1135 | if (!pendingcnt) |
1154 | if (idlecnt && !any_pending (EV_A)) |
1136 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1155 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1137 | |
1156 | |
1138 | /* queue check watchers, to be executed first */ |
1157 | /* queue check watchers, to be executed first */ |
1139 | if (checkcnt) |
1158 | if (checkcnt) |
1140 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1159 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
… | |
… | |
1215 | return; |
1234 | return; |
1216 | |
1235 | |
1217 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1236 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1218 | |
1237 | |
1219 | ev_start (EV_A_ (W)w, 1); |
1238 | ev_start (EV_A_ (W)w, 1); |
1220 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
1239 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1221 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1240 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1222 | |
1241 | |
1223 | fd_change (EV_A_ fd); |
1242 | fd_change (EV_A_ fd); |
1224 | } |
1243 | } |
1225 | |
1244 | |
… | |
… | |
1245 | ((WT)w)->at += mn_now; |
1264 | ((WT)w)->at += mn_now; |
1246 | |
1265 | |
1247 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1266 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1248 | |
1267 | |
1249 | ev_start (EV_A_ (W)w, ++timercnt); |
1268 | ev_start (EV_A_ (W)w, ++timercnt); |
1250 | array_needsize (timers, timermax, timercnt, (void)); |
1269 | array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); |
1251 | timers [timercnt - 1] = w; |
1270 | timers [timercnt - 1] = w; |
1252 | upheap ((WT *)timers, timercnt - 1); |
1271 | upheap ((WT *)timers, timercnt - 1); |
1253 | |
1272 | |
1254 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1273 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1255 | } |
1274 | } |
… | |
… | |
1295 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1314 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1296 | { |
1315 | { |
1297 | if (ev_is_active (w)) |
1316 | if (ev_is_active (w)) |
1298 | return; |
1317 | return; |
1299 | |
1318 | |
|
|
1319 | if (w->reschedule_cb) |
|
|
1320 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
|
|
1321 | else if (w->interval) |
|
|
1322 | { |
1300 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1323 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1301 | |
|
|
1302 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1324 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1303 | if (w->interval) |
|
|
1304 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1325 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
|
|
1326 | } |
1305 | |
1327 | |
1306 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1328 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1307 | array_needsize (periodics, periodicmax, periodiccnt, (void)); |
1329 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1308 | periodics [periodiccnt - 1] = w; |
1330 | periodics [periodiccnt - 1] = w; |
1309 | upheap ((WT *)periodics, periodiccnt - 1); |
1331 | upheap ((WT *)periodics, periodiccnt - 1); |
1310 | |
1332 | |
1311 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1333 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1312 | } |
1334 | } |
… | |
… | |
1328 | |
1350 | |
1329 | ev_stop (EV_A_ (W)w); |
1351 | ev_stop (EV_A_ (W)w); |
1330 | } |
1352 | } |
1331 | |
1353 | |
1332 | void |
1354 | void |
|
|
1355 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
|
|
1356 | { |
|
|
1357 | ev_periodic_stop (EV_A_ w); |
|
|
1358 | ev_periodic_start (EV_A_ w); |
|
|
1359 | } |
|
|
1360 | |
|
|
1361 | void |
1333 | ev_idle_start (EV_P_ struct ev_idle *w) |
1362 | ev_idle_start (EV_P_ struct ev_idle *w) |
1334 | { |
1363 | { |
1335 | if (ev_is_active (w)) |
1364 | if (ev_is_active (w)) |
1336 | return; |
1365 | return; |
1337 | |
1366 | |
1338 | ev_start (EV_A_ (W)w, ++idlecnt); |
1367 | ev_start (EV_A_ (W)w, ++idlecnt); |
1339 | array_needsize (idles, idlemax, idlecnt, (void)); |
1368 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); |
1340 | idles [idlecnt - 1] = w; |
1369 | idles [idlecnt - 1] = w; |
1341 | } |
1370 | } |
1342 | |
1371 | |
1343 | void |
1372 | void |
1344 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1373 | ev_idle_stop (EV_P_ struct ev_idle *w) |
… | |
… | |
1356 | { |
1385 | { |
1357 | if (ev_is_active (w)) |
1386 | if (ev_is_active (w)) |
1358 | return; |
1387 | return; |
1359 | |
1388 | |
1360 | ev_start (EV_A_ (W)w, ++preparecnt); |
1389 | ev_start (EV_A_ (W)w, ++preparecnt); |
1361 | array_needsize (prepares, preparemax, preparecnt, (void)); |
1390 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); |
1362 | prepares [preparecnt - 1] = w; |
1391 | prepares [preparecnt - 1] = w; |
1363 | } |
1392 | } |
1364 | |
1393 | |
1365 | void |
1394 | void |
1366 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1395 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
… | |
… | |
1378 | { |
1407 | { |
1379 | if (ev_is_active (w)) |
1408 | if (ev_is_active (w)) |
1380 | return; |
1409 | return; |
1381 | |
1410 | |
1382 | ev_start (EV_A_ (W)w, ++checkcnt); |
1411 | ev_start (EV_A_ (W)w, ++checkcnt); |
1383 | array_needsize (checks, checkmax, checkcnt, (void)); |
1412 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); |
1384 | checks [checkcnt - 1] = w; |
1413 | checks [checkcnt - 1] = w; |
1385 | } |
1414 | } |
1386 | |
1415 | |
1387 | void |
1416 | void |
1388 | ev_check_stop (EV_P_ struct ev_check *w) |
1417 | ev_check_stop (EV_P_ struct ev_check *w) |
… | |
… | |
1409 | return; |
1438 | return; |
1410 | |
1439 | |
1411 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1440 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1412 | |
1441 | |
1413 | ev_start (EV_A_ (W)w, 1); |
1442 | ev_start (EV_A_ (W)w, 1); |
1414 | array_needsize (signals, signalmax, w->signum, signals_init); |
1443 | array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); |
1415 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1444 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1416 | |
1445 | |
1417 | if (!((WL)w)->next) |
1446 | if (!((WL)w)->next) |
1418 | { |
1447 | { |
1419 | #if WIN32 |
1448 | #if WIN32 |
… | |
… | |
1502 | } |
1531 | } |
1503 | |
1532 | |
1504 | void |
1533 | void |
1505 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1534 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1506 | { |
1535 | { |
1507 | struct ev_once *once = ev_malloc (sizeof (struct ev_once)); |
1536 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
1508 | |
1537 | |
1509 | if (!once) |
1538 | if (!once) |
1510 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1539 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1511 | else |
1540 | else |
1512 | { |
1541 | { |