… | |
… | |
268 | ev_now (EV_P) |
268 | ev_now (EV_P) |
269 | { |
269 | { |
270 | return rt_now; |
270 | return rt_now; |
271 | } |
271 | } |
272 | |
272 | |
273 | #define array_roundsize(base,n) ((n) | 4 & ~3) |
273 | #define array_roundsize(type,n) ((n) | 4 & ~3) |
274 | |
274 | |
275 | #define array_needsize(base,cur,cnt,init) \ |
275 | #define array_needsize(type,base,cur,cnt,init) \ |
276 | if (expect_false ((cnt) > cur)) \ |
276 | if (expect_false ((cnt) > cur)) \ |
277 | { \ |
277 | { \ |
278 | int newcnt = cur; \ |
278 | int newcnt = cur; \ |
279 | do \ |
279 | do \ |
280 | { \ |
280 | { \ |
281 | newcnt = array_roundsize (base, newcnt << 1); \ |
281 | newcnt = array_roundsize (type, newcnt << 1); \ |
282 | } \ |
282 | } \ |
283 | while ((cnt) > newcnt); \ |
283 | while ((cnt) > newcnt); \ |
284 | \ |
284 | \ |
285 | base = ev_realloc (base, sizeof (*base) * (newcnt)); \ |
285 | base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\ |
286 | init (base + cur, newcnt - cur); \ |
286 | init (base + cur, newcnt - cur); \ |
287 | cur = newcnt; \ |
287 | cur = newcnt; \ |
288 | } |
288 | } |
289 | |
289 | |
290 | #define array_slim(stem) \ |
290 | #define array_slim(type,stem) \ |
291 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
291 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
292 | { \ |
292 | { \ |
293 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
293 | stem ## max = array_roundsize (stem ## cnt >> 1); \ |
294 | base = ev_realloc (base, sizeof (*base) * (stem ## max)); \ |
294 | base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ |
295 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
295 | fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ |
296 | } |
296 | } |
297 | |
297 | |
298 | /* 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 */ |
299 | /* 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 */ |
… | |
… | |
316 | |
316 | |
317 | ++base; |
317 | ++base; |
318 | } |
318 | } |
319 | } |
319 | } |
320 | |
320 | |
321 | static void |
321 | void |
322 | event (EV_P_ W w, int events) |
322 | ev_feed_event (EV_P_ void *w, int revents) |
323 | { |
323 | { |
|
|
324 | W w_ = (W)w; |
|
|
325 | |
324 | if (w->pending) |
326 | if (w_->pending) |
325 | { |
327 | { |
326 | pendings [ABSPRI (w)][w->pending - 1].events |= events; |
328 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
327 | return; |
329 | return; |
328 | } |
330 | } |
329 | |
331 | |
330 | w->pending = ++pendingcnt [ABSPRI (w)]; |
332 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
331 | 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)); |
332 | pendings [ABSPRI (w)][w->pending - 1].w = w; |
334 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
333 | pendings [ABSPRI (w)][w->pending - 1].events = events; |
335 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
334 | } |
336 | } |
335 | |
337 | |
336 | static void |
338 | static void |
337 | queue_events (EV_P_ W *events, int eventcnt, int type) |
339 | queue_events (EV_P_ W *events, int eventcnt, int type) |
338 | { |
340 | { |
339 | int i; |
341 | int i; |
340 | |
342 | |
341 | for (i = 0; i < eventcnt; ++i) |
343 | for (i = 0; i < eventcnt; ++i) |
342 | event (EV_A_ events [i], type); |
344 | ev_feed_event (EV_A_ events [i], type); |
343 | } |
345 | } |
344 | |
346 | |
345 | static void |
347 | inline void |
346 | fd_event (EV_P_ int fd, int events) |
348 | fd_event (EV_P_ int fd, int revents) |
347 | { |
349 | { |
348 | ANFD *anfd = anfds + fd; |
350 | ANFD *anfd = anfds + fd; |
349 | struct ev_io *w; |
351 | struct ev_io *w; |
350 | |
352 | |
351 | 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) |
352 | { |
354 | { |
353 | int ev = w->events & events; |
355 | int ev = w->events & revents; |
354 | |
356 | |
355 | if (ev) |
357 | if (ev) |
356 | event (EV_A_ (W)w, ev); |
358 | ev_feed_event (EV_A_ (W)w, ev); |
357 | } |
359 | } |
|
|
360 | } |
|
|
361 | |
|
|
362 | void |
|
|
363 | ev_feed_fd_event (EV_P_ int fd, int revents) |
|
|
364 | { |
|
|
365 | fd_event (EV_A_ fd, revents); |
358 | } |
366 | } |
359 | |
367 | |
360 | /*****************************************************************************/ |
368 | /*****************************************************************************/ |
361 | |
369 | |
362 | static void |
370 | static void |
… | |
… | |
391 | return; |
399 | return; |
392 | |
400 | |
393 | anfds [fd].reify = 1; |
401 | anfds [fd].reify = 1; |
394 | |
402 | |
395 | ++fdchangecnt; |
403 | ++fdchangecnt; |
396 | array_needsize (fdchanges, fdchangemax, fdchangecnt, (void)); |
404 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, (void)); |
397 | fdchanges [fdchangecnt - 1] = fd; |
405 | fdchanges [fdchangecnt - 1] = fd; |
398 | } |
406 | } |
399 | |
407 | |
400 | static void |
408 | static void |
401 | fd_kill (EV_P_ int fd) |
409 | fd_kill (EV_P_ int fd) |
… | |
… | |
403 | struct ev_io *w; |
411 | struct ev_io *w; |
404 | |
412 | |
405 | while ((w = (struct ev_io *)anfds [fd].head)) |
413 | while ((w = (struct ev_io *)anfds [fd].head)) |
406 | { |
414 | { |
407 | ev_io_stop (EV_A_ w); |
415 | ev_io_stop (EV_A_ w); |
408 | event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
416 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
409 | } |
417 | } |
410 | } |
418 | } |
411 | |
419 | |
412 | static int |
420 | static int |
413 | fd_valid (int fd) |
421 | fd_valid (int fd) |
… | |
… | |
541 | |
549 | |
542 | if (!gotsig) |
550 | if (!gotsig) |
543 | { |
551 | { |
544 | int old_errno = errno; |
552 | int old_errno = errno; |
545 | gotsig = 1; |
553 | gotsig = 1; |
|
|
554 | #ifdef WIN32 |
|
|
555 | send (sigpipe [1], &signum, 1, MSG_DONTWAIT); |
|
|
556 | #else |
546 | write (sigpipe [1], &signum, 1); |
557 | write (sigpipe [1], &signum, 1); |
|
|
558 | #endif |
547 | errno = old_errno; |
559 | errno = old_errno; |
548 | } |
560 | } |
|
|
561 | } |
|
|
562 | |
|
|
563 | void |
|
|
564 | ev_feed_signal_event (EV_P_ int signum) |
|
|
565 | { |
|
|
566 | #if EV_MULTIPLICITY |
|
|
567 | assert (("feeding signal events is only supported in the default loop", loop == default_loop)); |
|
|
568 | #endif |
|
|
569 | |
|
|
570 | --signum; |
|
|
571 | |
|
|
572 | if (signum < 0 || signum >= signalmax) |
|
|
573 | return; |
|
|
574 | |
|
|
575 | signals [signum].gotsig = 0; |
|
|
576 | |
|
|
577 | for (w = signals [signum].head; w; w = w->next) |
|
|
578 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
549 | } |
579 | } |
550 | |
580 | |
551 | static void |
581 | static void |
552 | sigcb (EV_P_ struct ev_io *iow, int revents) |
582 | sigcb (EV_P_ struct ev_io *iow, int revents) |
553 | { |
583 | { |
554 | WL w; |
584 | WL w; |
555 | int signum; |
585 | int signum; |
556 | |
586 | |
|
|
587 | #ifdef WIN32 |
|
|
588 | recv (sigpipe [0], &revents, 1, MSG_DONTWAIT); |
|
|
589 | #else |
557 | read (sigpipe [0], &revents, 1); |
590 | read (sigpipe [0], &revents, 1); |
|
|
591 | #endif |
558 | gotsig = 0; |
592 | gotsig = 0; |
559 | |
593 | |
560 | for (signum = signalmax; signum--; ) |
594 | for (signum = signalmax; signum--; ) |
561 | if (signals [signum].gotsig) |
595 | if (signals [signum].gotsig) |
562 | { |
596 | sigevent (EV_A_ signum + 1); |
563 | signals [signum].gotsig = 0; |
|
|
564 | |
|
|
565 | for (w = signals [signum].head; w; w = w->next) |
|
|
566 | event (EV_A_ (W)w, EV_SIGNAL); |
|
|
567 | } |
|
|
568 | } |
597 | } |
569 | |
598 | |
570 | static void |
599 | static void |
571 | siginit (EV_P) |
600 | siginit (EV_P) |
572 | { |
601 | { |
… | |
… | |
605 | if (w->pid == pid || !w->pid) |
634 | if (w->pid == pid || !w->pid) |
606 | { |
635 | { |
607 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
636 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
608 | w->rpid = pid; |
637 | w->rpid = pid; |
609 | w->rstatus = status; |
638 | w->rstatus = status; |
610 | event (EV_A_ (W)w, EV_CHILD); |
639 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
611 | } |
640 | } |
612 | } |
641 | } |
613 | |
642 | |
614 | static void |
643 | static void |
615 | childcb (EV_P_ struct ev_signal *sw, int revents) |
644 | childcb (EV_P_ struct ev_signal *sw, int revents) |
… | |
… | |
617 | int pid, status; |
646 | int pid, status; |
618 | |
647 | |
619 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
648 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
620 | { |
649 | { |
621 | /* make sure we are called again until all childs have been reaped */ |
650 | /* make sure we are called again until all childs have been reaped */ |
622 | event (EV_A_ (W)sw, EV_SIGNAL); |
651 | ev_feed_event (EV_A_ (W)sw, EV_SIGNAL); |
623 | |
652 | |
624 | child_reap (EV_A_ sw, pid, pid, status); |
653 | child_reap (EV_A_ sw, pid, pid, status); |
625 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
654 | child_reap (EV_A_ sw, 0, pid, status); /* this might trigger a watcher twice, but event catches that */ |
626 | } |
655 | } |
627 | } |
656 | } |
… | |
… | |
888 | if (method) |
917 | if (method) |
889 | postfork = 1; |
918 | postfork = 1; |
890 | } |
919 | } |
891 | |
920 | |
892 | /*****************************************************************************/ |
921 | /*****************************************************************************/ |
|
|
922 | |
|
|
923 | static int |
|
|
924 | any_pending (EV_P) |
|
|
925 | { |
|
|
926 | int pri; |
|
|
927 | |
|
|
928 | for (pri = NUMPRI; pri--; ) |
|
|
929 | if (pendingcnt [pri]) |
|
|
930 | return 1; |
|
|
931 | |
|
|
932 | return 0; |
|
|
933 | } |
893 | |
934 | |
894 | static void |
935 | static void |
895 | call_pending (EV_P) |
936 | call_pending (EV_P) |
896 | { |
937 | { |
897 | int pri; |
938 | int pri; |
… | |
… | |
926 | downheap ((WT *)timers, timercnt, 0); |
967 | downheap ((WT *)timers, timercnt, 0); |
927 | } |
968 | } |
928 | else |
969 | else |
929 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
970 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
930 | |
971 | |
931 | event (EV_A_ (W)w, EV_TIMEOUT); |
972 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
932 | } |
973 | } |
933 | } |
974 | } |
934 | |
975 | |
935 | static void |
976 | static void |
936 | periodics_reify (EV_P) |
977 | periodics_reify (EV_P) |
… | |
… | |
940 | struct ev_periodic *w = periodics [0]; |
981 | struct ev_periodic *w = periodics [0]; |
941 | |
982 | |
942 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
983 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
943 | |
984 | |
944 | /* first reschedule or stop timer */ |
985 | /* first reschedule or stop timer */ |
|
|
986 | if (w->reschedule_cb) |
|
|
987 | { |
|
|
988 | ev_tstamp at = ((WT)w)->at = w->reschedule_cb (w, rt_now + 0.0001); |
|
|
989 | |
|
|
990 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > rt_now)); |
|
|
991 | downheap ((WT *)periodics, periodiccnt, 0); |
|
|
992 | } |
945 | if (w->interval) |
993 | else if (w->interval) |
946 | { |
994 | { |
947 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
995 | ((WT)w)->at += floor ((rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
948 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
996 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > rt_now)); |
949 | downheap ((WT *)periodics, periodiccnt, 0); |
997 | downheap ((WT *)periodics, periodiccnt, 0); |
950 | } |
998 | } |
951 | else |
999 | else |
952 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1000 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
953 | |
1001 | |
954 | event (EV_A_ (W)w, EV_PERIODIC); |
1002 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
955 | } |
1003 | } |
956 | } |
1004 | } |
957 | |
1005 | |
958 | static void |
1006 | static void |
959 | periodics_reschedule (EV_P) |
1007 | periodics_reschedule (EV_P) |
… | |
… | |
963 | /* adjust periodics after time jump */ |
1011 | /* adjust periodics after time jump */ |
964 | for (i = 0; i < periodiccnt; ++i) |
1012 | for (i = 0; i < periodiccnt; ++i) |
965 | { |
1013 | { |
966 | struct ev_periodic *w = periodics [i]; |
1014 | struct ev_periodic *w = periodics [i]; |
967 | |
1015 | |
|
|
1016 | if (w->reschedule_cb) |
|
|
1017 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
968 | if (w->interval) |
1018 | else if (w->interval) |
969 | { |
|
|
970 | ev_tstamp diff = ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1019 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
971 | |
|
|
972 | if (fabs (diff) >= 1e-4) |
|
|
973 | { |
|
|
974 | ev_periodic_stop (EV_A_ w); |
|
|
975 | ev_periodic_start (EV_A_ w); |
|
|
976 | |
|
|
977 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
|
|
978 | } |
|
|
979 | } |
|
|
980 | } |
1020 | } |
|
|
1021 | |
|
|
1022 | /* now rebuild the heap */ |
|
|
1023 | for (i = periodiccnt >> 1; i--; ) |
|
|
1024 | downheap ((WT *)periodics, periodiccnt, i); |
981 | } |
1025 | } |
982 | |
1026 | |
983 | inline int |
1027 | inline int |
984 | time_update_monotonic (EV_P) |
1028 | time_update_monotonic (EV_P) |
985 | { |
1029 | { |
… | |
… | |
1081 | /* update fd-related kernel structures */ |
1125 | /* update fd-related kernel structures */ |
1082 | fd_reify (EV_A); |
1126 | fd_reify (EV_A); |
1083 | |
1127 | |
1084 | /* calculate blocking time */ |
1128 | /* calculate blocking time */ |
1085 | |
1129 | |
1086 | /* we only need this for !monotonic clockor timers, but as we basically |
1130 | /* we only need this for !monotonic clock or timers, but as we basically |
1087 | always have timers, we just calculate it always */ |
1131 | always have timers, we just calculate it always */ |
1088 | #if EV_USE_MONOTONIC |
1132 | #if EV_USE_MONOTONIC |
1089 | if (expect_true (have_monotonic)) |
1133 | if (expect_true (have_monotonic)) |
1090 | time_update_monotonic (EV_A); |
1134 | time_update_monotonic (EV_A); |
1091 | else |
1135 | else |
… | |
… | |
1124 | /* queue pending timers and reschedule them */ |
1168 | /* queue pending timers and reschedule them */ |
1125 | timers_reify (EV_A); /* relative timers called last */ |
1169 | timers_reify (EV_A); /* relative timers called last */ |
1126 | periodics_reify (EV_A); /* absolute timers called first */ |
1170 | periodics_reify (EV_A); /* absolute timers called first */ |
1127 | |
1171 | |
1128 | /* queue idle watchers unless io or timers are pending */ |
1172 | /* queue idle watchers unless io or timers are pending */ |
1129 | if (!pendingcnt) |
1173 | if (idlecnt && !any_pending (EV_A)) |
1130 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1174 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1131 | |
1175 | |
1132 | /* queue check watchers, to be executed first */ |
1176 | /* queue check watchers, to be executed first */ |
1133 | if (checkcnt) |
1177 | if (checkcnt) |
1134 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1178 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
… | |
… | |
1209 | return; |
1253 | return; |
1210 | |
1254 | |
1211 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1255 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1212 | |
1256 | |
1213 | ev_start (EV_A_ (W)w, 1); |
1257 | ev_start (EV_A_ (W)w, 1); |
1214 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
1258 | array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); |
1215 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1259 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1216 | |
1260 | |
1217 | fd_change (EV_A_ fd); |
1261 | fd_change (EV_A_ fd); |
1218 | } |
1262 | } |
1219 | |
1263 | |
… | |
… | |
1239 | ((WT)w)->at += mn_now; |
1283 | ((WT)w)->at += mn_now; |
1240 | |
1284 | |
1241 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1285 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1242 | |
1286 | |
1243 | ev_start (EV_A_ (W)w, ++timercnt); |
1287 | ev_start (EV_A_ (W)w, ++timercnt); |
1244 | array_needsize (timers, timermax, timercnt, (void)); |
1288 | array_needsize (struct ev_timer *, timers, timermax, timercnt, (void)); |
1245 | timers [timercnt - 1] = w; |
1289 | timers [timercnt - 1] = w; |
1246 | upheap ((WT *)timers, timercnt - 1); |
1290 | upheap ((WT *)timers, timercnt - 1); |
1247 | |
1291 | |
1248 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1292 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1249 | } |
1293 | } |
… | |
… | |
1289 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1333 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1290 | { |
1334 | { |
1291 | if (ev_is_active (w)) |
1335 | if (ev_is_active (w)) |
1292 | return; |
1336 | return; |
1293 | |
1337 | |
|
|
1338 | if (w->reschedule_cb) |
|
|
1339 | ((WT)w)->at = w->reschedule_cb (w, rt_now); |
|
|
1340 | else if (w->interval) |
|
|
1341 | { |
1294 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1342 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1295 | |
|
|
1296 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1343 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1297 | if (w->interval) |
|
|
1298 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1344 | ((WT)w)->at += ceil ((rt_now - ((WT)w)->at) / w->interval) * w->interval; |
|
|
1345 | } |
1299 | |
1346 | |
1300 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1347 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1301 | array_needsize (periodics, periodicmax, periodiccnt, (void)); |
1348 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, (void)); |
1302 | periodics [periodiccnt - 1] = w; |
1349 | periodics [periodiccnt - 1] = w; |
1303 | upheap ((WT *)periodics, periodiccnt - 1); |
1350 | upheap ((WT *)periodics, periodiccnt - 1); |
1304 | |
1351 | |
1305 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1352 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1306 | } |
1353 | } |
… | |
… | |
1322 | |
1369 | |
1323 | ev_stop (EV_A_ (W)w); |
1370 | ev_stop (EV_A_ (W)w); |
1324 | } |
1371 | } |
1325 | |
1372 | |
1326 | void |
1373 | void |
|
|
1374 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
|
|
1375 | { |
|
|
1376 | ev_periodic_stop (EV_A_ w); |
|
|
1377 | ev_periodic_start (EV_A_ w); |
|
|
1378 | } |
|
|
1379 | |
|
|
1380 | void |
1327 | ev_idle_start (EV_P_ struct ev_idle *w) |
1381 | ev_idle_start (EV_P_ struct ev_idle *w) |
1328 | { |
1382 | { |
1329 | if (ev_is_active (w)) |
1383 | if (ev_is_active (w)) |
1330 | return; |
1384 | return; |
1331 | |
1385 | |
1332 | ev_start (EV_A_ (W)w, ++idlecnt); |
1386 | ev_start (EV_A_ (W)w, ++idlecnt); |
1333 | array_needsize (idles, idlemax, idlecnt, (void)); |
1387 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, (void)); |
1334 | idles [idlecnt - 1] = w; |
1388 | idles [idlecnt - 1] = w; |
1335 | } |
1389 | } |
1336 | |
1390 | |
1337 | void |
1391 | void |
1338 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1392 | ev_idle_stop (EV_P_ struct ev_idle *w) |
… | |
… | |
1350 | { |
1404 | { |
1351 | if (ev_is_active (w)) |
1405 | if (ev_is_active (w)) |
1352 | return; |
1406 | return; |
1353 | |
1407 | |
1354 | ev_start (EV_A_ (W)w, ++preparecnt); |
1408 | ev_start (EV_A_ (W)w, ++preparecnt); |
1355 | array_needsize (prepares, preparemax, preparecnt, (void)); |
1409 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, (void)); |
1356 | prepares [preparecnt - 1] = w; |
1410 | prepares [preparecnt - 1] = w; |
1357 | } |
1411 | } |
1358 | |
1412 | |
1359 | void |
1413 | void |
1360 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1414 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
… | |
… | |
1372 | { |
1426 | { |
1373 | if (ev_is_active (w)) |
1427 | if (ev_is_active (w)) |
1374 | return; |
1428 | return; |
1375 | |
1429 | |
1376 | ev_start (EV_A_ (W)w, ++checkcnt); |
1430 | ev_start (EV_A_ (W)w, ++checkcnt); |
1377 | array_needsize (checks, checkmax, checkcnt, (void)); |
1431 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, (void)); |
1378 | checks [checkcnt - 1] = w; |
1432 | checks [checkcnt - 1] = w; |
1379 | } |
1433 | } |
1380 | |
1434 | |
1381 | void |
1435 | void |
1382 | ev_check_stop (EV_P_ struct ev_check *w) |
1436 | ev_check_stop (EV_P_ struct ev_check *w) |
… | |
… | |
1403 | return; |
1457 | return; |
1404 | |
1458 | |
1405 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1459 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1406 | |
1460 | |
1407 | ev_start (EV_A_ (W)w, 1); |
1461 | ev_start (EV_A_ (W)w, 1); |
1408 | array_needsize (signals, signalmax, w->signum, signals_init); |
1462 | array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); |
1409 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1463 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
1410 | |
1464 | |
1411 | if (!((WL)w)->next) |
1465 | if (!((WL)w)->next) |
1412 | { |
1466 | { |
1413 | #if WIN32 |
1467 | #if WIN32 |
… | |
… | |
1496 | } |
1550 | } |
1497 | |
1551 | |
1498 | void |
1552 | void |
1499 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1553 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1500 | { |
1554 | { |
1501 | struct ev_once *once = ev_malloc (sizeof (struct ev_once)); |
1555 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
1502 | |
1556 | |
1503 | if (!once) |
1557 | if (!once) |
1504 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1558 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1505 | else |
1559 | else |
1506 | { |
1560 | { |