… | |
… | |
202 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
202 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
203 | |
203 | |
204 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
204 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
205 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
205 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
206 | |
206 | |
207 | typedef struct ev_watcher *W; |
207 | typedef ev_watcher *W; |
208 | typedef struct ev_watcher_list *WL; |
208 | typedef ev_watcher_list *WL; |
209 | typedef struct ev_watcher_time *WT; |
209 | typedef ev_watcher_time *WT; |
210 | |
210 | |
211 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
211 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
212 | |
212 | |
213 | #ifdef _WIN32 |
213 | #ifdef _WIN32 |
214 | # include "ev_win32.c" |
214 | # include "ev_win32.c" |
… | |
… | |
416 | |
416 | |
417 | inline void |
417 | inline void |
418 | fd_event (EV_P_ int fd, int revents) |
418 | fd_event (EV_P_ int fd, int revents) |
419 | { |
419 | { |
420 | ANFD *anfd = anfds + fd; |
420 | ANFD *anfd = anfds + fd; |
421 | struct ev_io *w; |
421 | ev_io *w; |
422 | |
422 | |
423 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
423 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
424 | { |
424 | { |
425 | int ev = w->events & revents; |
425 | int ev = w->events & revents; |
426 | |
426 | |
427 | if (ev) |
427 | if (ev) |
428 | ev_feed_event (EV_A_ (W)w, ev); |
428 | ev_feed_event (EV_A_ (W)w, ev); |
… | |
… | |
444 | |
444 | |
445 | for (i = 0; i < fdchangecnt; ++i) |
445 | for (i = 0; i < fdchangecnt; ++i) |
446 | { |
446 | { |
447 | int fd = fdchanges [i]; |
447 | int fd = fdchanges [i]; |
448 | ANFD *anfd = anfds + fd; |
448 | ANFD *anfd = anfds + fd; |
449 | struct ev_io *w; |
449 | ev_io *w; |
450 | |
450 | |
451 | int events = 0; |
451 | int events = 0; |
452 | |
452 | |
453 | for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) |
453 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
454 | events |= w->events; |
454 | events |= w->events; |
455 | |
455 | |
456 | #if EV_SELECT_IS_WINSOCKET |
456 | #if EV_SELECT_IS_WINSOCKET |
457 | if (events) |
457 | if (events) |
458 | { |
458 | { |
… | |
… | |
485 | } |
485 | } |
486 | |
486 | |
487 | static void |
487 | static void |
488 | fd_kill (EV_P_ int fd) |
488 | fd_kill (EV_P_ int fd) |
489 | { |
489 | { |
490 | struct ev_io *w; |
490 | ev_io *w; |
491 | |
491 | |
492 | while ((w = (struct ev_io *)anfds [fd].head)) |
492 | while ((w = (ev_io *)anfds [fd].head)) |
493 | { |
493 | { |
494 | ev_io_stop (EV_A_ w); |
494 | ev_io_stop (EV_A_ w); |
495 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
495 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
496 | } |
496 | } |
497 | } |
497 | } |
… | |
… | |
608 | static ANSIG *signals; |
608 | static ANSIG *signals; |
609 | static int signalmax; |
609 | static int signalmax; |
610 | |
610 | |
611 | static int sigpipe [2]; |
611 | static int sigpipe [2]; |
612 | static sig_atomic_t volatile gotsig; |
612 | static sig_atomic_t volatile gotsig; |
613 | static struct ev_io sigev; |
613 | static ev_io sigev; |
614 | |
614 | |
615 | static void |
615 | static void |
616 | signals_init (ANSIG *base, int count) |
616 | signals_init (ANSIG *base, int count) |
617 | { |
617 | { |
618 | while (count--) |
618 | while (count--) |
… | |
… | |
661 | for (w = signals [signum].head; w; w = w->next) |
661 | for (w = signals [signum].head; w; w = w->next) |
662 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
662 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
663 | } |
663 | } |
664 | |
664 | |
665 | static void |
665 | static void |
666 | sigcb (EV_P_ struct ev_io *iow, int revents) |
666 | sigcb (EV_P_ ev_io *iow, int revents) |
667 | { |
667 | { |
668 | int signum; |
668 | int signum; |
669 | |
669 | |
670 | read (sigpipe [0], &revents, 1); |
670 | read (sigpipe [0], &revents, 1); |
671 | gotsig = 0; |
671 | gotsig = 0; |
… | |
… | |
698 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
698 | ev_unref (EV_A); /* child watcher should not keep loop alive */ |
699 | } |
699 | } |
700 | |
700 | |
701 | /*****************************************************************************/ |
701 | /*****************************************************************************/ |
702 | |
702 | |
703 | static struct ev_child *childs [PID_HASHSIZE]; |
703 | static ev_child *childs [PID_HASHSIZE]; |
704 | |
704 | |
705 | #ifndef _WIN32 |
705 | #ifndef _WIN32 |
706 | |
706 | |
707 | static struct ev_signal childev; |
707 | static ev_signal childev; |
708 | |
708 | |
709 | #ifndef WCONTINUED |
709 | #ifndef WCONTINUED |
710 | # define WCONTINUED 0 |
710 | # define WCONTINUED 0 |
711 | #endif |
711 | #endif |
712 | |
712 | |
713 | static void |
713 | static void |
714 | child_reap (EV_P_ struct ev_signal *sw, int chain, int pid, int status) |
714 | child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status) |
715 | { |
715 | { |
716 | struct ev_child *w; |
716 | ev_child *w; |
717 | |
717 | |
718 | for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) |
718 | for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
719 | if (w->pid == pid || !w->pid) |
719 | if (w->pid == pid || !w->pid) |
720 | { |
720 | { |
721 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
721 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
722 | w->rpid = pid; |
722 | w->rpid = pid; |
723 | w->rstatus = status; |
723 | w->rstatus = status; |
724 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
724 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
725 | } |
725 | } |
726 | } |
726 | } |
727 | |
727 | |
728 | static void |
728 | static void |
729 | childcb (EV_P_ struct ev_signal *sw, int revents) |
729 | childcb (EV_P_ ev_signal *sw, int revents) |
730 | { |
730 | { |
731 | int pid, status; |
731 | int pid, status; |
732 | |
732 | |
733 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
733 | if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) |
734 | { |
734 | { |
… | |
… | |
816 | |
816 | |
817 | return flags; |
817 | return flags; |
818 | } |
818 | } |
819 | |
819 | |
820 | unsigned int |
820 | unsigned int |
|
|
821 | ev_embeddable_backends (void) |
|
|
822 | { |
|
|
823 | return EVBACKEND_EPOLL |
|
|
824 | | EVBACKEND_KQUEUE |
|
|
825 | | EVBACKEND_PORT; |
|
|
826 | } |
|
|
827 | |
|
|
828 | unsigned int |
821 | ev_backend (EV_P) |
829 | ev_backend (EV_P) |
822 | { |
830 | { |
823 | return backend; |
831 | return backend; |
824 | } |
832 | } |
825 | |
833 | |
… | |
… | |
1077 | inline void |
1085 | inline void |
1078 | timers_reify (EV_P) |
1086 | timers_reify (EV_P) |
1079 | { |
1087 | { |
1080 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1088 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1081 | { |
1089 | { |
1082 | struct ev_timer *w = timers [0]; |
1090 | ev_timer *w = timers [0]; |
1083 | |
1091 | |
1084 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
1092 | assert (("inactive timer on timer heap detected", ev_is_active (w))); |
1085 | |
1093 | |
1086 | /* first reschedule or stop timer */ |
1094 | /* first reschedule or stop timer */ |
1087 | if (w->repeat) |
1095 | if (w->repeat) |
… | |
… | |
1105 | inline void |
1113 | inline void |
1106 | periodics_reify (EV_P) |
1114 | periodics_reify (EV_P) |
1107 | { |
1115 | { |
1108 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1116 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1109 | { |
1117 | { |
1110 | struct ev_periodic *w = periodics [0]; |
1118 | ev_periodic *w = periodics [0]; |
1111 | |
1119 | |
1112 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1120 | assert (("inactive timer on periodic heap detected", ev_is_active (w))); |
1113 | |
1121 | |
1114 | /* first reschedule or stop timer */ |
1122 | /* first reschedule or stop timer */ |
1115 | if (w->reschedule_cb) |
1123 | if (w->reschedule_cb) |
… | |
… | |
1137 | int i; |
1145 | int i; |
1138 | |
1146 | |
1139 | /* adjust periodics after time jump */ |
1147 | /* adjust periodics after time jump */ |
1140 | for (i = 0; i < periodiccnt; ++i) |
1148 | for (i = 0; i < periodiccnt; ++i) |
1141 | { |
1149 | { |
1142 | struct ev_periodic *w = periodics [i]; |
1150 | ev_periodic *w = periodics [i]; |
1143 | |
1151 | |
1144 | if (w->reschedule_cb) |
1152 | if (w->reschedule_cb) |
1145 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1153 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1146 | else if (w->interval) |
1154 | else if (w->interval) |
1147 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1155 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
… | |
… | |
1237 | static int loop_done; |
1245 | static int loop_done; |
1238 | |
1246 | |
1239 | void |
1247 | void |
1240 | ev_loop (EV_P_ int flags) |
1248 | ev_loop (EV_P_ int flags) |
1241 | { |
1249 | { |
1242 | double block; |
|
|
1243 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
1250 | loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) |
|
|
1251 | ? EVUNLOOP_ONE |
|
|
1252 | : EVUNLOOP_CANCEL; |
1244 | |
1253 | |
1245 | while (activecnt) |
1254 | while (activecnt) |
1246 | { |
1255 | { |
1247 | /* queue check watchers (and execute them) */ |
1256 | /* queue check watchers (and execute them) */ |
1248 | if (expect_false (preparecnt)) |
1257 | if (expect_false (preparecnt)) |
… | |
… | |
1257 | |
1266 | |
1258 | /* update fd-related kernel structures */ |
1267 | /* update fd-related kernel structures */ |
1259 | fd_reify (EV_A); |
1268 | fd_reify (EV_A); |
1260 | |
1269 | |
1261 | /* calculate blocking time */ |
1270 | /* calculate blocking time */ |
|
|
1271 | { |
|
|
1272 | double block; |
1262 | |
1273 | |
1263 | /* we only need this for !monotonic clock or timers, but as we basically |
1274 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
1264 | always have timers, we just calculate it always */ |
1275 | block = 0.; /* do not block at all */ |
|
|
1276 | else |
|
|
1277 | { |
|
|
1278 | /* update time to cancel out callback processing overhead */ |
1265 | #if EV_USE_MONOTONIC |
1279 | #if EV_USE_MONOTONIC |
1266 | if (expect_true (have_monotonic)) |
1280 | if (expect_true (have_monotonic)) |
1267 | time_update_monotonic (EV_A); |
1281 | time_update_monotonic (EV_A); |
1268 | else |
1282 | else |
1269 | #endif |
1283 | #endif |
1270 | { |
1284 | { |
1271 | ev_rt_now = ev_time (); |
1285 | ev_rt_now = ev_time (); |
1272 | mn_now = ev_rt_now; |
1286 | mn_now = ev_rt_now; |
1273 | } |
1287 | } |
1274 | |
1288 | |
1275 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
|
|
1276 | block = 0.; |
|
|
1277 | else |
|
|
1278 | { |
|
|
1279 | block = MAX_BLOCKTIME; |
1289 | block = MAX_BLOCKTIME; |
1280 | |
1290 | |
1281 | if (timercnt) |
1291 | if (timercnt) |
1282 | { |
1292 | { |
1283 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1293 | ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; |
1284 | if (block > to) block = to; |
1294 | if (block > to) block = to; |
1285 | } |
1295 | } |
1286 | |
1296 | |
1287 | #if EV_PERIODICS |
1297 | #if EV_PERIODICS |
1288 | if (periodiccnt) |
1298 | if (periodiccnt) |
1289 | { |
1299 | { |
1290 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; |
1300 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; |
1291 | if (block > to) block = to; |
1301 | if (block > to) block = to; |
1292 | } |
1302 | } |
1293 | #endif |
1303 | #endif |
1294 | |
1304 | |
1295 | if (expect_false (block < 0.)) block = 0.; |
1305 | if (expect_false (block < 0.)) block = 0.; |
1296 | } |
1306 | } |
1297 | |
1307 | |
1298 | backend_poll (EV_A_ block); |
1308 | backend_poll (EV_A_ block); |
|
|
1309 | } |
1299 | |
1310 | |
1300 | /* update ev_rt_now, do magic */ |
1311 | /* update ev_rt_now, do magic */ |
1301 | time_update (EV_A); |
1312 | time_update (EV_A); |
1302 | |
1313 | |
1303 | /* queue pending timers and reschedule them */ |
1314 | /* queue pending timers and reschedule them */ |
1304 | timers_reify (EV_A); /* relative timers called last */ |
1315 | timers_reify (EV_A); /* relative timers called last */ |
1305 | #if EV_PERIODICS |
1316 | #if EV_PERIODICS |
1306 | periodics_reify (EV_A); /* absolute timers called first */ |
1317 | periodics_reify (EV_A); /* absolute timers called first */ |
1307 | #endif |
1318 | #endif |
1308 | |
1319 | |
1309 | /* queue idle watchers unless io or timers are pending */ |
1320 | /* queue idle watchers unless other events are pending */ |
1310 | if (idlecnt && !any_pending (EV_A)) |
1321 | if (idlecnt && !any_pending (EV_A)) |
1311 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1322 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1312 | |
1323 | |
1313 | /* queue check watchers, to be executed first */ |
1324 | /* queue check watchers, to be executed first */ |
1314 | if (expect_false (checkcnt)) |
1325 | if (expect_false (checkcnt)) |
… | |
… | |
1318 | |
1329 | |
1319 | if (expect_false (loop_done)) |
1330 | if (expect_false (loop_done)) |
1320 | break; |
1331 | break; |
1321 | } |
1332 | } |
1322 | |
1333 | |
1323 | if (loop_done != 2) |
1334 | if (loop_done == EVUNLOOP_ONE) |
1324 | loop_done = 0; |
1335 | loop_done = EVUNLOOP_CANCEL; |
1325 | } |
1336 | } |
1326 | |
1337 | |
1327 | void |
1338 | void |
1328 | ev_unloop (EV_P_ int how) |
1339 | ev_unloop (EV_P_ int how) |
1329 | { |
1340 | { |
… | |
… | |
1382 | } |
1393 | } |
1383 | |
1394 | |
1384 | /*****************************************************************************/ |
1395 | /*****************************************************************************/ |
1385 | |
1396 | |
1386 | void |
1397 | void |
1387 | ev_io_start (EV_P_ struct ev_io *w) |
1398 | ev_io_start (EV_P_ ev_io *w) |
1388 | { |
1399 | { |
1389 | int fd = w->fd; |
1400 | int fd = w->fd; |
1390 | |
1401 | |
1391 | if (expect_false (ev_is_active (w))) |
1402 | if (expect_false (ev_is_active (w))) |
1392 | return; |
1403 | return; |
… | |
… | |
1399 | |
1410 | |
1400 | fd_change (EV_A_ fd); |
1411 | fd_change (EV_A_ fd); |
1401 | } |
1412 | } |
1402 | |
1413 | |
1403 | void |
1414 | void |
1404 | ev_io_stop (EV_P_ struct ev_io *w) |
1415 | ev_io_stop (EV_P_ ev_io *w) |
1405 | { |
1416 | { |
1406 | ev_clear_pending (EV_A_ (W)w); |
1417 | ev_clear_pending (EV_A_ (W)w); |
1407 | if (expect_false (!ev_is_active (w))) |
1418 | if (expect_false (!ev_is_active (w))) |
1408 | return; |
1419 | return; |
1409 | |
1420 | |
… | |
… | |
1414 | |
1425 | |
1415 | fd_change (EV_A_ w->fd); |
1426 | fd_change (EV_A_ w->fd); |
1416 | } |
1427 | } |
1417 | |
1428 | |
1418 | void |
1429 | void |
1419 | ev_timer_start (EV_P_ struct ev_timer *w) |
1430 | ev_timer_start (EV_P_ ev_timer *w) |
1420 | { |
1431 | { |
1421 | if (expect_false (ev_is_active (w))) |
1432 | if (expect_false (ev_is_active (w))) |
1422 | return; |
1433 | return; |
1423 | |
1434 | |
1424 | ((WT)w)->at += mn_now; |
1435 | ((WT)w)->at += mn_now; |
1425 | |
1436 | |
1426 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1437 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1427 | |
1438 | |
1428 | ev_start (EV_A_ (W)w, ++timercnt); |
1439 | ev_start (EV_A_ (W)w, ++timercnt); |
1429 | array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2); |
1440 | array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2); |
1430 | timers [timercnt - 1] = w; |
1441 | timers [timercnt - 1] = w; |
1431 | upheap ((WT *)timers, timercnt - 1); |
1442 | upheap ((WT *)timers, timercnt - 1); |
1432 | |
1443 | |
1433 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1444 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1434 | } |
1445 | } |
1435 | |
1446 | |
1436 | void |
1447 | void |
1437 | ev_timer_stop (EV_P_ struct ev_timer *w) |
1448 | ev_timer_stop (EV_P_ ev_timer *w) |
1438 | { |
1449 | { |
1439 | ev_clear_pending (EV_A_ (W)w); |
1450 | ev_clear_pending (EV_A_ (W)w); |
1440 | if (expect_false (!ev_is_active (w))) |
1451 | if (expect_false (!ev_is_active (w))) |
1441 | return; |
1452 | return; |
1442 | |
1453 | |
… | |
… | |
1452 | |
1463 | |
1453 | ev_stop (EV_A_ (W)w); |
1464 | ev_stop (EV_A_ (W)w); |
1454 | } |
1465 | } |
1455 | |
1466 | |
1456 | void |
1467 | void |
1457 | ev_timer_again (EV_P_ struct ev_timer *w) |
1468 | ev_timer_again (EV_P_ ev_timer *w) |
1458 | { |
1469 | { |
1459 | if (ev_is_active (w)) |
1470 | if (ev_is_active (w)) |
1460 | { |
1471 | { |
1461 | if (w->repeat) |
1472 | if (w->repeat) |
1462 | { |
1473 | { |
… | |
… | |
1473 | } |
1484 | } |
1474 | } |
1485 | } |
1475 | |
1486 | |
1476 | #if EV_PERIODICS |
1487 | #if EV_PERIODICS |
1477 | void |
1488 | void |
1478 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1489 | ev_periodic_start (EV_P_ ev_periodic *w) |
1479 | { |
1490 | { |
1480 | if (expect_false (ev_is_active (w))) |
1491 | if (expect_false (ev_is_active (w))) |
1481 | return; |
1492 | return; |
1482 | |
1493 | |
1483 | if (w->reschedule_cb) |
1494 | if (w->reschedule_cb) |
… | |
… | |
1488 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1499 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1489 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1500 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1490 | } |
1501 | } |
1491 | |
1502 | |
1492 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1503 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1493 | array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1504 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1494 | periodics [periodiccnt - 1] = w; |
1505 | periodics [periodiccnt - 1] = w; |
1495 | upheap ((WT *)periodics, periodiccnt - 1); |
1506 | upheap ((WT *)periodics, periodiccnt - 1); |
1496 | |
1507 | |
1497 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1508 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1498 | } |
1509 | } |
1499 | |
1510 | |
1500 | void |
1511 | void |
1501 | ev_periodic_stop (EV_P_ struct ev_periodic *w) |
1512 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1502 | { |
1513 | { |
1503 | ev_clear_pending (EV_A_ (W)w); |
1514 | ev_clear_pending (EV_A_ (W)w); |
1504 | if (expect_false (!ev_is_active (w))) |
1515 | if (expect_false (!ev_is_active (w))) |
1505 | return; |
1516 | return; |
1506 | |
1517 | |
… | |
… | |
1514 | |
1525 | |
1515 | ev_stop (EV_A_ (W)w); |
1526 | ev_stop (EV_A_ (W)w); |
1516 | } |
1527 | } |
1517 | |
1528 | |
1518 | void |
1529 | void |
1519 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
1530 | ev_periodic_again (EV_P_ ev_periodic *w) |
1520 | { |
1531 | { |
1521 | /* TODO: use adjustheap and recalculation */ |
1532 | /* TODO: use adjustheap and recalculation */ |
1522 | ev_periodic_stop (EV_A_ w); |
1533 | ev_periodic_stop (EV_A_ w); |
1523 | ev_periodic_start (EV_A_ w); |
1534 | ev_periodic_start (EV_A_ w); |
1524 | } |
1535 | } |
1525 | #endif |
1536 | #endif |
1526 | |
1537 | |
1527 | void |
1538 | void |
1528 | ev_idle_start (EV_P_ struct ev_idle *w) |
1539 | ev_idle_start (EV_P_ ev_idle *w) |
1529 | { |
1540 | { |
1530 | if (expect_false (ev_is_active (w))) |
1541 | if (expect_false (ev_is_active (w))) |
1531 | return; |
1542 | return; |
1532 | |
1543 | |
1533 | ev_start (EV_A_ (W)w, ++idlecnt); |
1544 | ev_start (EV_A_ (W)w, ++idlecnt); |
1534 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1545 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1535 | idles [idlecnt - 1] = w; |
1546 | idles [idlecnt - 1] = w; |
1536 | } |
1547 | } |
1537 | |
1548 | |
1538 | void |
1549 | void |
1539 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1550 | ev_idle_stop (EV_P_ ev_idle *w) |
1540 | { |
1551 | { |
1541 | ev_clear_pending (EV_A_ (W)w); |
1552 | ev_clear_pending (EV_A_ (W)w); |
1542 | if (expect_false (!ev_is_active (w))) |
1553 | if (expect_false (!ev_is_active (w))) |
1543 | return; |
1554 | return; |
1544 | |
1555 | |
1545 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1556 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1546 | ev_stop (EV_A_ (W)w); |
1557 | ev_stop (EV_A_ (W)w); |
1547 | } |
1558 | } |
1548 | |
1559 | |
1549 | void |
1560 | void |
1550 | ev_prepare_start (EV_P_ struct ev_prepare *w) |
1561 | ev_prepare_start (EV_P_ ev_prepare *w) |
1551 | { |
1562 | { |
1552 | if (expect_false (ev_is_active (w))) |
1563 | if (expect_false (ev_is_active (w))) |
1553 | return; |
1564 | return; |
1554 | |
1565 | |
1555 | ev_start (EV_A_ (W)w, ++preparecnt); |
1566 | ev_start (EV_A_ (W)w, ++preparecnt); |
1556 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1567 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1557 | prepares [preparecnt - 1] = w; |
1568 | prepares [preparecnt - 1] = w; |
1558 | } |
1569 | } |
1559 | |
1570 | |
1560 | void |
1571 | void |
1561 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1572 | ev_prepare_stop (EV_P_ ev_prepare *w) |
1562 | { |
1573 | { |
1563 | ev_clear_pending (EV_A_ (W)w); |
1574 | ev_clear_pending (EV_A_ (W)w); |
1564 | if (expect_false (!ev_is_active (w))) |
1575 | if (expect_false (!ev_is_active (w))) |
1565 | return; |
1576 | return; |
1566 | |
1577 | |
1567 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1578 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1568 | ev_stop (EV_A_ (W)w); |
1579 | ev_stop (EV_A_ (W)w); |
1569 | } |
1580 | } |
1570 | |
1581 | |
1571 | void |
1582 | void |
1572 | ev_check_start (EV_P_ struct ev_check *w) |
1583 | ev_check_start (EV_P_ ev_check *w) |
1573 | { |
1584 | { |
1574 | if (expect_false (ev_is_active (w))) |
1585 | if (expect_false (ev_is_active (w))) |
1575 | return; |
1586 | return; |
1576 | |
1587 | |
1577 | ev_start (EV_A_ (W)w, ++checkcnt); |
1588 | ev_start (EV_A_ (W)w, ++checkcnt); |
1578 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1589 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1579 | checks [checkcnt - 1] = w; |
1590 | checks [checkcnt - 1] = w; |
1580 | } |
1591 | } |
1581 | |
1592 | |
1582 | void |
1593 | void |
1583 | ev_check_stop (EV_P_ struct ev_check *w) |
1594 | ev_check_stop (EV_P_ ev_check *w) |
1584 | { |
1595 | { |
1585 | ev_clear_pending (EV_A_ (W)w); |
1596 | ev_clear_pending (EV_A_ (W)w); |
1586 | if (expect_false (!ev_is_active (w))) |
1597 | if (expect_false (!ev_is_active (w))) |
1587 | return; |
1598 | return; |
1588 | |
1599 | |
… | |
… | |
1593 | #ifndef SA_RESTART |
1604 | #ifndef SA_RESTART |
1594 | # define SA_RESTART 0 |
1605 | # define SA_RESTART 0 |
1595 | #endif |
1606 | #endif |
1596 | |
1607 | |
1597 | void |
1608 | void |
1598 | ev_signal_start (EV_P_ struct ev_signal *w) |
1609 | ev_signal_start (EV_P_ ev_signal *w) |
1599 | { |
1610 | { |
1600 | #if EV_MULTIPLICITY |
1611 | #if EV_MULTIPLICITY |
1601 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1612 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1602 | #endif |
1613 | #endif |
1603 | if (expect_false (ev_is_active (w))) |
1614 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1622 | #endif |
1633 | #endif |
1623 | } |
1634 | } |
1624 | } |
1635 | } |
1625 | |
1636 | |
1626 | void |
1637 | void |
1627 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1638 | ev_signal_stop (EV_P_ ev_signal *w) |
1628 | { |
1639 | { |
1629 | ev_clear_pending (EV_A_ (W)w); |
1640 | ev_clear_pending (EV_A_ (W)w); |
1630 | if (expect_false (!ev_is_active (w))) |
1641 | if (expect_false (!ev_is_active (w))) |
1631 | return; |
1642 | return; |
1632 | |
1643 | |
… | |
… | |
1636 | if (!signals [w->signum - 1].head) |
1647 | if (!signals [w->signum - 1].head) |
1637 | signal (w->signum, SIG_DFL); |
1648 | signal (w->signum, SIG_DFL); |
1638 | } |
1649 | } |
1639 | |
1650 | |
1640 | void |
1651 | void |
1641 | ev_child_start (EV_P_ struct ev_child *w) |
1652 | ev_child_start (EV_P_ ev_child *w) |
1642 | { |
1653 | { |
1643 | #if EV_MULTIPLICITY |
1654 | #if EV_MULTIPLICITY |
1644 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1655 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1645 | #endif |
1656 | #endif |
1646 | if (expect_false (ev_is_active (w))) |
1657 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1649 | ev_start (EV_A_ (W)w, 1); |
1660 | ev_start (EV_A_ (W)w, 1); |
1650 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1661 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1651 | } |
1662 | } |
1652 | |
1663 | |
1653 | void |
1664 | void |
1654 | ev_child_stop (EV_P_ struct ev_child *w) |
1665 | ev_child_stop (EV_P_ ev_child *w) |
1655 | { |
1666 | { |
1656 | ev_clear_pending (EV_A_ (W)w); |
1667 | ev_clear_pending (EV_A_ (W)w); |
1657 | if (expect_false (!ev_is_active (w))) |
1668 | if (expect_false (!ev_is_active (w))) |
1658 | return; |
1669 | return; |
1659 | |
1670 | |
1660 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1671 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1661 | ev_stop (EV_A_ (W)w); |
1672 | ev_stop (EV_A_ (W)w); |
1662 | } |
1673 | } |
1663 | |
1674 | |
|
|
1675 | #if EV_MULTIPLICITY |
|
|
1676 | void |
|
|
1677 | ev_embed_sweep (EV_P_ ev_embed *w) |
|
|
1678 | { |
|
|
1679 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
|
|
1680 | } |
|
|
1681 | |
|
|
1682 | static void |
|
|
1683 | embed_cb (EV_P_ ev_io *io, int revents) |
|
|
1684 | { |
|
|
1685 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
|
|
1686 | |
|
|
1687 | if (ev_cb (w)) |
|
|
1688 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
|
|
1689 | else |
|
|
1690 | ev_embed_sweep (loop, w); |
|
|
1691 | } |
|
|
1692 | |
|
|
1693 | void |
|
|
1694 | ev_embed_start (EV_P_ ev_embed *w) |
|
|
1695 | { |
|
|
1696 | if (expect_false (ev_is_active (w))) |
|
|
1697 | return; |
|
|
1698 | |
|
|
1699 | { |
|
|
1700 | struct ev_loop *loop = w->loop; |
|
|
1701 | assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
|
|
1702 | ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); |
|
|
1703 | } |
|
|
1704 | |
|
|
1705 | ev_set_priority (&w->io, ev_priority (w)); |
|
|
1706 | ev_io_start (EV_A_ &w->io); |
|
|
1707 | ev_start (EV_A_ (W)w, 1); |
|
|
1708 | } |
|
|
1709 | |
|
|
1710 | void |
|
|
1711 | ev_embed_stop (EV_P_ ev_embed *w) |
|
|
1712 | { |
|
|
1713 | ev_clear_pending (EV_A_ (W)w); |
|
|
1714 | if (expect_false (!ev_is_active (w))) |
|
|
1715 | return; |
|
|
1716 | |
|
|
1717 | ev_io_stop (EV_A_ &w->io); |
|
|
1718 | ev_stop (EV_A_ (W)w); |
|
|
1719 | } |
|
|
1720 | #endif |
|
|
1721 | |
1664 | /*****************************************************************************/ |
1722 | /*****************************************************************************/ |
1665 | |
1723 | |
1666 | struct ev_once |
1724 | struct ev_once |
1667 | { |
1725 | { |
1668 | struct ev_io io; |
1726 | ev_io io; |
1669 | struct ev_timer to; |
1727 | ev_timer to; |
1670 | void (*cb)(int revents, void *arg); |
1728 | void (*cb)(int revents, void *arg); |
1671 | void *arg; |
1729 | void *arg; |
1672 | }; |
1730 | }; |
1673 | |
1731 | |
1674 | static void |
1732 | static void |
… | |
… | |
1683 | |
1741 | |
1684 | cb (revents, arg); |
1742 | cb (revents, arg); |
1685 | } |
1743 | } |
1686 | |
1744 | |
1687 | static void |
1745 | static void |
1688 | once_cb_io (EV_P_ struct ev_io *w, int revents) |
1746 | once_cb_io (EV_P_ ev_io *w, int revents) |
1689 | { |
1747 | { |
1690 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
1748 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
1691 | } |
1749 | } |
1692 | |
1750 | |
1693 | static void |
1751 | static void |
1694 | once_cb_to (EV_P_ struct ev_timer *w, int revents) |
1752 | once_cb_to (EV_P_ ev_timer *w, int revents) |
1695 | { |
1753 | { |
1696 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
1754 | once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
1697 | } |
1755 | } |
1698 | |
1756 | |
1699 | void |
1757 | void |