… | |
… | |
216 | # include <sys/inotify.h> |
216 | # include <sys/inotify.h> |
217 | #endif |
217 | #endif |
218 | |
218 | |
219 | /**/ |
219 | /**/ |
220 | |
220 | |
|
|
221 | /* |
|
|
222 | * This is used to avoid floating point rounding problems. |
|
|
223 | * It is added to ev_rt_now when scheduling periodics |
|
|
224 | * to ensure progress, time-wise, even when rounding |
|
|
225 | * errors are against us. |
|
|
226 | * This value is good at least till the year 4000 |
|
|
227 | * and intervals up to 20 years. |
|
|
228 | * Better solutions welcome. |
|
|
229 | */ |
|
|
230 | #define TIME_EPSILON 0.0001220703125 /* 1/8192 */ |
|
|
231 | |
221 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
232 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
222 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
233 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
223 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
234 | /*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds, TODO */ |
224 | |
235 | |
225 | #if __GNUC__ >= 3 |
236 | #if __GNUC__ >= 3 |
226 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
237 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
227 | # define inline_size static inline /* inline for codesize */ |
|
|
228 | # if EV_MINIMAL |
|
|
229 | # define noinline __attribute__ ((noinline)) |
238 | # define noinline __attribute__ ((noinline)) |
230 | # define inline_speed static noinline |
|
|
231 | # else |
|
|
232 | # define noinline |
|
|
233 | # define inline_speed static inline |
|
|
234 | # endif |
|
|
235 | #else |
239 | #else |
236 | # define expect(expr,value) (expr) |
240 | # define expect(expr,value) (expr) |
237 | # define inline_speed static |
|
|
238 | # define inline_size static |
|
|
239 | # define noinline |
241 | # define noinline |
|
|
242 | # if __STDC_VERSION__ < 199901L |
|
|
243 | # define inline |
|
|
244 | # endif |
240 | #endif |
245 | #endif |
241 | |
246 | |
242 | #define expect_false(expr) expect ((expr) != 0, 0) |
247 | #define expect_false(expr) expect ((expr) != 0, 0) |
243 | #define expect_true(expr) expect ((expr) != 0, 1) |
248 | #define expect_true(expr) expect ((expr) != 0, 1) |
|
|
249 | #define inline_size static inline |
|
|
250 | |
|
|
251 | #if EV_MINIMAL |
|
|
252 | # define inline_speed static noinline |
|
|
253 | #else |
|
|
254 | # define inline_speed static inline |
|
|
255 | #endif |
244 | |
256 | |
245 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
257 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
246 | #define ABSPRI(w) ((w)->priority - EV_MINPRI) |
258 | #define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
247 | |
259 | |
248 | #define EMPTY0 /* required for microsofts broken pseudo-c compiler */ |
260 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
249 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
261 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
250 | |
262 | |
251 | typedef ev_watcher *W; |
263 | typedef ev_watcher *W; |
252 | typedef ev_watcher_list *WL; |
264 | typedef ev_watcher_list *WL; |
253 | typedef ev_watcher_time *WT; |
265 | typedef ev_watcher_time *WT; |
… | |
… | |
417 | } |
429 | } |
418 | |
430 | |
419 | return ncur; |
431 | return ncur; |
420 | } |
432 | } |
421 | |
433 | |
422 | inline_speed void * |
434 | static noinline void * |
423 | array_realloc (int elem, void *base, int *cur, int cnt) |
435 | array_realloc (int elem, void *base, int *cur, int cnt) |
424 | { |
436 | { |
425 | *cur = array_nextsize (elem, *cur, cnt); |
437 | *cur = array_nextsize (elem, *cur, cnt); |
426 | return ev_realloc (base, elem * *cur); |
438 | return ev_realloc (base, elem * *cur); |
427 | } |
439 | } |
… | |
… | |
452 | |
464 | |
453 | void noinline |
465 | void noinline |
454 | ev_feed_event (EV_P_ void *w, int revents) |
466 | ev_feed_event (EV_P_ void *w, int revents) |
455 | { |
467 | { |
456 | W w_ = (W)w; |
468 | W w_ = (W)w; |
|
|
469 | int pri = ABSPRI (w_); |
457 | |
470 | |
458 | if (expect_false (w_->pending)) |
471 | if (expect_false (w_->pending)) |
|
|
472 | pendings [pri][w_->pending - 1].events |= revents; |
|
|
473 | else |
459 | { |
474 | { |
|
|
475 | w_->pending = ++pendingcnt [pri]; |
|
|
476 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
|
|
477 | pendings [pri][w_->pending - 1].w = w_; |
460 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
478 | pendings [pri][w_->pending - 1].events = revents; |
461 | return; |
|
|
462 | } |
479 | } |
463 | |
|
|
464 | w_->pending = ++pendingcnt [ABSPRI (w_)]; |
|
|
465 | array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); |
|
|
466 | pendings [ABSPRI (w_)][w_->pending - 1].w = w_; |
|
|
467 | pendings [ABSPRI (w_)][w_->pending - 1].events = revents; |
|
|
468 | } |
480 | } |
469 | |
481 | |
470 | void inline_size |
482 | void inline_size |
471 | queue_events (EV_P_ W *events, int eventcnt, int type) |
483 | queue_events (EV_P_ W *events, int eventcnt, int type) |
472 | { |
484 | { |
… | |
… | |
507 | } |
519 | } |
508 | |
520 | |
509 | void |
521 | void |
510 | ev_feed_fd_event (EV_P_ int fd, int revents) |
522 | ev_feed_fd_event (EV_P_ int fd, int revents) |
511 | { |
523 | { |
|
|
524 | if (fd >= 0 && fd < anfdmax) |
512 | fd_event (EV_A_ fd, revents); |
525 | fd_event (EV_A_ fd, revents); |
513 | } |
526 | } |
514 | |
527 | |
515 | void inline_size |
528 | void inline_size |
516 | fd_reify (EV_P) |
529 | fd_reify (EV_P) |
517 | { |
530 | { |
… | |
… | |
747 | for (signum = signalmax; signum--; ) |
760 | for (signum = signalmax; signum--; ) |
748 | if (signals [signum].gotsig) |
761 | if (signals [signum].gotsig) |
749 | ev_feed_signal_event (EV_A_ signum + 1); |
762 | ev_feed_signal_event (EV_A_ signum + 1); |
750 | } |
763 | } |
751 | |
764 | |
752 | void inline_size |
765 | void inline_speed |
753 | fd_intern (int fd) |
766 | fd_intern (int fd) |
754 | { |
767 | { |
755 | #ifdef _WIN32 |
768 | #ifdef _WIN32 |
756 | int arg = 1; |
769 | int arg = 1; |
757 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
770 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
… | |
… | |
786 | ev_child *w; |
799 | ev_child *w; |
787 | |
800 | |
788 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
801 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
789 | if (w->pid == pid || !w->pid) |
802 | if (w->pid == pid || !w->pid) |
790 | { |
803 | { |
791 | ev_priority (w) = ev_priority (sw); /* need to do it *now* */ |
804 | ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */ |
792 | w->rpid = pid; |
805 | w->rpid = pid; |
793 | w->rstatus = status; |
806 | w->rstatus = status; |
794 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
807 | ev_feed_event (EV_A_ (W)w, EV_CHILD); |
795 | } |
808 | } |
796 | } |
809 | } |
797 | |
810 | |
798 | #ifndef WCONTINUED |
811 | #ifndef WCONTINUED |
… | |
… | |
1003 | #if EV_USE_SELECT |
1016 | #if EV_USE_SELECT |
1004 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1017 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
1005 | #endif |
1018 | #endif |
1006 | |
1019 | |
1007 | for (i = NUMPRI; i--; ) |
1020 | for (i = NUMPRI; i--; ) |
|
|
1021 | { |
1008 | array_free (pending, [i]); |
1022 | array_free (pending, [i]); |
|
|
1023 | #if EV_IDLE_ENABLE |
|
|
1024 | array_free (idle, [i]); |
|
|
1025 | #endif |
|
|
1026 | } |
1009 | |
1027 | |
1010 | /* have to use the microsoft-never-gets-it-right macro */ |
1028 | /* have to use the microsoft-never-gets-it-right macro */ |
1011 | array_free (fdchange, EMPTY0); |
1029 | array_free (fdchange, EMPTY); |
1012 | array_free (timer, EMPTY0); |
1030 | array_free (timer, EMPTY); |
1013 | #if EV_PERIODIC_ENABLE |
1031 | #if EV_PERIODIC_ENABLE |
1014 | array_free (periodic, EMPTY0); |
1032 | array_free (periodic, EMPTY); |
1015 | #endif |
1033 | #endif |
1016 | array_free (idle, EMPTY0); |
|
|
1017 | array_free (prepare, EMPTY0); |
1034 | array_free (prepare, EMPTY); |
1018 | array_free (check, EMPTY0); |
1035 | array_free (check, EMPTY); |
1019 | |
1036 | |
1020 | backend = 0; |
1037 | backend = 0; |
1021 | } |
1038 | } |
1022 | |
1039 | |
1023 | void inline_size infy_fork (EV_P); |
1040 | void inline_size infy_fork (EV_P); |
… | |
… | |
1159 | postfork = 1; |
1176 | postfork = 1; |
1160 | } |
1177 | } |
1161 | |
1178 | |
1162 | /*****************************************************************************/ |
1179 | /*****************************************************************************/ |
1163 | |
1180 | |
1164 | int inline_size |
1181 | void |
1165 | any_pending (EV_P) |
1182 | ev_invoke (EV_P_ void *w, int revents) |
1166 | { |
1183 | { |
1167 | int pri; |
1184 | EV_CB_INVOKE ((W)w, revents); |
1168 | |
|
|
1169 | for (pri = NUMPRI; pri--; ) |
|
|
1170 | if (pendingcnt [pri]) |
|
|
1171 | return 1; |
|
|
1172 | |
|
|
1173 | return 0; |
|
|
1174 | } |
1185 | } |
1175 | |
1186 | |
1176 | void inline_speed |
1187 | void inline_speed |
1177 | call_pending (EV_P) |
1188 | call_pending (EV_P) |
1178 | { |
1189 | { |
… | |
… | |
1231 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1242 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1232 | |
1243 | |
1233 | /* first reschedule or stop timer */ |
1244 | /* first reschedule or stop timer */ |
1234 | if (w->reschedule_cb) |
1245 | if (w->reschedule_cb) |
1235 | { |
1246 | { |
1236 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + 0.0001); |
1247 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1237 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1248 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1238 | downheap ((WT *)periodics, periodiccnt, 0); |
1249 | downheap ((WT *)periodics, periodiccnt, 0); |
1239 | } |
1250 | } |
1240 | else if (w->interval) |
1251 | else if (w->interval) |
1241 | { |
1252 | { |
1242 | ((WT)w)->at += floor ((ev_rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; |
1253 | ((WT)w)->at = w->offset + floor ((ev_rt_now + TIME_EPSILON - w->offset) / w->interval + 1.) * w->interval; |
1243 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1254 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1244 | downheap ((WT *)periodics, periodiccnt, 0); |
1255 | downheap ((WT *)periodics, periodiccnt, 0); |
1245 | } |
1256 | } |
1246 | else |
1257 | else |
1247 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1258 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
… | |
… | |
1261 | ev_periodic *w = periodics [i]; |
1272 | ev_periodic *w = periodics [i]; |
1262 | |
1273 | |
1263 | if (w->reschedule_cb) |
1274 | if (w->reschedule_cb) |
1264 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1275 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1265 | else if (w->interval) |
1276 | else if (w->interval) |
1266 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1277 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1267 | } |
1278 | } |
1268 | |
1279 | |
1269 | /* now rebuild the heap */ |
1280 | /* now rebuild the heap */ |
1270 | for (i = periodiccnt >> 1; i--; ) |
1281 | for (i = periodiccnt >> 1; i--; ) |
1271 | downheap ((WT *)periodics, periodiccnt, i); |
1282 | downheap ((WT *)periodics, periodiccnt, i); |
|
|
1283 | } |
|
|
1284 | #endif |
|
|
1285 | |
|
|
1286 | #if EV_IDLE_ENABLE |
|
|
1287 | void inline_size |
|
|
1288 | idle_reify (EV_P) |
|
|
1289 | { |
|
|
1290 | if (expect_false (idleall)) |
|
|
1291 | { |
|
|
1292 | int pri; |
|
|
1293 | |
|
|
1294 | for (pri = NUMPRI; pri--; ) |
|
|
1295 | { |
|
|
1296 | if (pendingcnt [pri]) |
|
|
1297 | break; |
|
|
1298 | |
|
|
1299 | if (idlecnt [pri]) |
|
|
1300 | { |
|
|
1301 | queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE); |
|
|
1302 | break; |
|
|
1303 | } |
|
|
1304 | } |
|
|
1305 | } |
1272 | } |
1306 | } |
1273 | #endif |
1307 | #endif |
1274 | |
1308 | |
1275 | int inline_size |
1309 | int inline_size |
1276 | time_update_monotonic (EV_P) |
1310 | time_update_monotonic (EV_P) |
… | |
… | |
1391 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
1425 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
1392 | call_pending (EV_A); |
1426 | call_pending (EV_A); |
1393 | } |
1427 | } |
1394 | #endif |
1428 | #endif |
1395 | |
1429 | |
1396 | /* queue check watchers (and execute them) */ |
1430 | /* queue prepare watchers (and execute them) */ |
1397 | if (expect_false (preparecnt)) |
1431 | if (expect_false (preparecnt)) |
1398 | { |
1432 | { |
1399 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1433 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
1400 | call_pending (EV_A); |
1434 | call_pending (EV_A); |
1401 | } |
1435 | } |
… | |
… | |
1412 | |
1446 | |
1413 | /* calculate blocking time */ |
1447 | /* calculate blocking time */ |
1414 | { |
1448 | { |
1415 | ev_tstamp block; |
1449 | ev_tstamp block; |
1416 | |
1450 | |
1417 | if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) |
1451 | if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt)) |
1418 | block = 0.; /* do not block at all */ |
1452 | block = 0.; /* do not block at all */ |
1419 | else |
1453 | else |
1420 | { |
1454 | { |
1421 | /* update time to cancel out callback processing overhead */ |
1455 | /* update time to cancel out callback processing overhead */ |
1422 | #if EV_USE_MONOTONIC |
1456 | #if EV_USE_MONOTONIC |
… | |
… | |
1459 | timers_reify (EV_A); /* relative timers called last */ |
1493 | timers_reify (EV_A); /* relative timers called last */ |
1460 | #if EV_PERIODIC_ENABLE |
1494 | #if EV_PERIODIC_ENABLE |
1461 | periodics_reify (EV_A); /* absolute timers called first */ |
1495 | periodics_reify (EV_A); /* absolute timers called first */ |
1462 | #endif |
1496 | #endif |
1463 | |
1497 | |
|
|
1498 | #if EV_IDLE_ENABLE |
1464 | /* queue idle watchers unless other events are pending */ |
1499 | /* queue idle watchers unless other events are pending */ |
1465 | if (idlecnt && !any_pending (EV_A)) |
1500 | idle_reify (EV_A); |
1466 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1501 | #endif |
1467 | |
1502 | |
1468 | /* queue check watchers, to be executed first */ |
1503 | /* queue check watchers, to be executed first */ |
1469 | if (expect_false (checkcnt)) |
1504 | if (expect_false (checkcnt)) |
1470 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1505 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1471 | |
1506 | |
… | |
… | |
1507 | head = &(*head)->next; |
1542 | head = &(*head)->next; |
1508 | } |
1543 | } |
1509 | } |
1544 | } |
1510 | |
1545 | |
1511 | void inline_speed |
1546 | void inline_speed |
1512 | ev_clear_pending (EV_P_ W w) |
1547 | clear_pending (EV_P_ W w) |
1513 | { |
1548 | { |
1514 | if (w->pending) |
1549 | if (w->pending) |
1515 | { |
1550 | { |
1516 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1551 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
1517 | w->pending = 0; |
1552 | w->pending = 0; |
1518 | } |
1553 | } |
1519 | } |
1554 | } |
1520 | |
1555 | |
|
|
1556 | int |
|
|
1557 | ev_clear_pending (EV_P_ void *w) |
|
|
1558 | { |
|
|
1559 | W w_ = (W)w; |
|
|
1560 | int pending = w_->pending; |
|
|
1561 | |
|
|
1562 | if (expect_true (pending)) |
|
|
1563 | { |
|
|
1564 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
1565 | w_->pending = 0; |
|
|
1566 | p->w = 0; |
|
|
1567 | return p->events; |
|
|
1568 | } |
|
|
1569 | else |
|
|
1570 | return 0; |
|
|
1571 | } |
|
|
1572 | |
|
|
1573 | void inline_size |
|
|
1574 | pri_adjust (EV_P_ W w) |
|
|
1575 | { |
|
|
1576 | int pri = w->priority; |
|
|
1577 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
|
|
1578 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
|
|
1579 | w->priority = pri; |
|
|
1580 | } |
|
|
1581 | |
1521 | void inline_speed |
1582 | void inline_speed |
1522 | ev_start (EV_P_ W w, int active) |
1583 | ev_start (EV_P_ W w, int active) |
1523 | { |
1584 | { |
1524 | if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; |
1585 | pri_adjust (EV_A_ w); |
1525 | if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI; |
|
|
1526 | |
|
|
1527 | w->active = active; |
1586 | w->active = active; |
1528 | ev_ref (EV_A); |
1587 | ev_ref (EV_A); |
1529 | } |
1588 | } |
1530 | |
1589 | |
1531 | void inline_size |
1590 | void inline_size |
… | |
… | |
1535 | w->active = 0; |
1594 | w->active = 0; |
1536 | } |
1595 | } |
1537 | |
1596 | |
1538 | /*****************************************************************************/ |
1597 | /*****************************************************************************/ |
1539 | |
1598 | |
1540 | void |
1599 | void noinline |
1541 | ev_io_start (EV_P_ ev_io *w) |
1600 | ev_io_start (EV_P_ ev_io *w) |
1542 | { |
1601 | { |
1543 | int fd = w->fd; |
1602 | int fd = w->fd; |
1544 | |
1603 | |
1545 | if (expect_false (ev_is_active (w))) |
1604 | if (expect_false (ev_is_active (w))) |
… | |
… | |
1552 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1611 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
1553 | |
1612 | |
1554 | fd_change (EV_A_ fd); |
1613 | fd_change (EV_A_ fd); |
1555 | } |
1614 | } |
1556 | |
1615 | |
1557 | void |
1616 | void noinline |
1558 | ev_io_stop (EV_P_ ev_io *w) |
1617 | ev_io_stop (EV_P_ ev_io *w) |
1559 | { |
1618 | { |
1560 | ev_clear_pending (EV_A_ (W)w); |
1619 | clear_pending (EV_A_ (W)w); |
1561 | if (expect_false (!ev_is_active (w))) |
1620 | if (expect_false (!ev_is_active (w))) |
1562 | return; |
1621 | return; |
1563 | |
1622 | |
1564 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1623 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1565 | |
1624 | |
… | |
… | |
1567 | ev_stop (EV_A_ (W)w); |
1626 | ev_stop (EV_A_ (W)w); |
1568 | |
1627 | |
1569 | fd_change (EV_A_ w->fd); |
1628 | fd_change (EV_A_ w->fd); |
1570 | } |
1629 | } |
1571 | |
1630 | |
1572 | void |
1631 | void noinline |
1573 | ev_timer_start (EV_P_ ev_timer *w) |
1632 | ev_timer_start (EV_P_ ev_timer *w) |
1574 | { |
1633 | { |
1575 | if (expect_false (ev_is_active (w))) |
1634 | if (expect_false (ev_is_active (w))) |
1576 | return; |
1635 | return; |
1577 | |
1636 | |
… | |
… | |
1585 | upheap ((WT *)timers, timercnt - 1); |
1644 | upheap ((WT *)timers, timercnt - 1); |
1586 | |
1645 | |
1587 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1646 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1588 | } |
1647 | } |
1589 | |
1648 | |
1590 | void |
1649 | void noinline |
1591 | ev_timer_stop (EV_P_ ev_timer *w) |
1650 | ev_timer_stop (EV_P_ ev_timer *w) |
1592 | { |
1651 | { |
1593 | ev_clear_pending (EV_A_ (W)w); |
1652 | clear_pending (EV_A_ (W)w); |
1594 | if (expect_false (!ev_is_active (w))) |
1653 | if (expect_false (!ev_is_active (w))) |
1595 | return; |
1654 | return; |
1596 | |
1655 | |
1597 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1656 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1598 | |
1657 | |
… | |
… | |
1609 | ((WT)w)->at -= mn_now; |
1668 | ((WT)w)->at -= mn_now; |
1610 | |
1669 | |
1611 | ev_stop (EV_A_ (W)w); |
1670 | ev_stop (EV_A_ (W)w); |
1612 | } |
1671 | } |
1613 | |
1672 | |
1614 | void |
1673 | void noinline |
1615 | ev_timer_again (EV_P_ ev_timer *w) |
1674 | ev_timer_again (EV_P_ ev_timer *w) |
1616 | { |
1675 | { |
1617 | if (ev_is_active (w)) |
1676 | if (ev_is_active (w)) |
1618 | { |
1677 | { |
1619 | if (w->repeat) |
1678 | if (w->repeat) |
… | |
… | |
1630 | ev_timer_start (EV_A_ w); |
1689 | ev_timer_start (EV_A_ w); |
1631 | } |
1690 | } |
1632 | } |
1691 | } |
1633 | |
1692 | |
1634 | #if EV_PERIODIC_ENABLE |
1693 | #if EV_PERIODIC_ENABLE |
1635 | void |
1694 | void noinline |
1636 | ev_periodic_start (EV_P_ ev_periodic *w) |
1695 | ev_periodic_start (EV_P_ ev_periodic *w) |
1637 | { |
1696 | { |
1638 | if (expect_false (ev_is_active (w))) |
1697 | if (expect_false (ev_is_active (w))) |
1639 | return; |
1698 | return; |
1640 | |
1699 | |
… | |
… | |
1642 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1701 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1643 | else if (w->interval) |
1702 | else if (w->interval) |
1644 | { |
1703 | { |
1645 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1704 | assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); |
1646 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1705 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
1647 | ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; |
1706 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1648 | } |
1707 | } |
|
|
1708 | else |
|
|
1709 | ((WT)w)->at = w->offset; |
1649 | |
1710 | |
1650 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1711 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1651 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1712 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1652 | periodics [periodiccnt - 1] = w; |
1713 | periodics [periodiccnt - 1] = w; |
1653 | upheap ((WT *)periodics, periodiccnt - 1); |
1714 | upheap ((WT *)periodics, periodiccnt - 1); |
1654 | |
1715 | |
1655 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1716 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1656 | } |
1717 | } |
1657 | |
1718 | |
1658 | void |
1719 | void noinline |
1659 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1720 | ev_periodic_stop (EV_P_ ev_periodic *w) |
1660 | { |
1721 | { |
1661 | ev_clear_pending (EV_A_ (W)w); |
1722 | clear_pending (EV_A_ (W)w); |
1662 | if (expect_false (!ev_is_active (w))) |
1723 | if (expect_false (!ev_is_active (w))) |
1663 | return; |
1724 | return; |
1664 | |
1725 | |
1665 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1726 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1666 | |
1727 | |
… | |
… | |
1675 | } |
1736 | } |
1676 | |
1737 | |
1677 | ev_stop (EV_A_ (W)w); |
1738 | ev_stop (EV_A_ (W)w); |
1678 | } |
1739 | } |
1679 | |
1740 | |
1680 | void |
1741 | void noinline |
1681 | ev_periodic_again (EV_P_ ev_periodic *w) |
1742 | ev_periodic_again (EV_P_ ev_periodic *w) |
1682 | { |
1743 | { |
1683 | /* TODO: use adjustheap and recalculation */ |
1744 | /* TODO: use adjustheap and recalculation */ |
1684 | ev_periodic_stop (EV_A_ w); |
1745 | ev_periodic_stop (EV_A_ w); |
1685 | ev_periodic_start (EV_A_ w); |
1746 | ev_periodic_start (EV_A_ w); |
… | |
… | |
1688 | |
1749 | |
1689 | #ifndef SA_RESTART |
1750 | #ifndef SA_RESTART |
1690 | # define SA_RESTART 0 |
1751 | # define SA_RESTART 0 |
1691 | #endif |
1752 | #endif |
1692 | |
1753 | |
1693 | void |
1754 | void noinline |
1694 | ev_signal_start (EV_P_ ev_signal *w) |
1755 | ev_signal_start (EV_P_ ev_signal *w) |
1695 | { |
1756 | { |
1696 | #if EV_MULTIPLICITY |
1757 | #if EV_MULTIPLICITY |
1697 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1758 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1698 | #endif |
1759 | #endif |
… | |
… | |
1717 | sigaction (w->signum, &sa, 0); |
1778 | sigaction (w->signum, &sa, 0); |
1718 | #endif |
1779 | #endif |
1719 | } |
1780 | } |
1720 | } |
1781 | } |
1721 | |
1782 | |
1722 | void |
1783 | void noinline |
1723 | ev_signal_stop (EV_P_ ev_signal *w) |
1784 | ev_signal_stop (EV_P_ ev_signal *w) |
1724 | { |
1785 | { |
1725 | ev_clear_pending (EV_A_ (W)w); |
1786 | clear_pending (EV_A_ (W)w); |
1726 | if (expect_false (!ev_is_active (w))) |
1787 | if (expect_false (!ev_is_active (w))) |
1727 | return; |
1788 | return; |
1728 | |
1789 | |
1729 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1790 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1730 | ev_stop (EV_A_ (W)w); |
1791 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1747 | } |
1808 | } |
1748 | |
1809 | |
1749 | void |
1810 | void |
1750 | ev_child_stop (EV_P_ ev_child *w) |
1811 | ev_child_stop (EV_P_ ev_child *w) |
1751 | { |
1812 | { |
1752 | ev_clear_pending (EV_A_ (W)w); |
1813 | clear_pending (EV_A_ (W)w); |
1753 | if (expect_false (!ev_is_active (w))) |
1814 | if (expect_false (!ev_is_active (w))) |
1754 | return; |
1815 | return; |
1755 | |
1816 | |
1756 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1817 | wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); |
1757 | ev_stop (EV_A_ (W)w); |
1818 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1993 | } |
2054 | } |
1994 | |
2055 | |
1995 | void |
2056 | void |
1996 | ev_stat_stop (EV_P_ ev_stat *w) |
2057 | ev_stat_stop (EV_P_ ev_stat *w) |
1997 | { |
2058 | { |
1998 | ev_clear_pending (EV_A_ (W)w); |
2059 | clear_pending (EV_A_ (W)w); |
1999 | if (expect_false (!ev_is_active (w))) |
2060 | if (expect_false (!ev_is_active (w))) |
2000 | return; |
2061 | return; |
2001 | |
2062 | |
2002 | #if EV_USE_INOTIFY |
2063 | #if EV_USE_INOTIFY |
2003 | infy_del (EV_A_ w); |
2064 | infy_del (EV_A_ w); |
… | |
… | |
2006 | |
2067 | |
2007 | ev_stop (EV_A_ (W)w); |
2068 | ev_stop (EV_A_ (W)w); |
2008 | } |
2069 | } |
2009 | #endif |
2070 | #endif |
2010 | |
2071 | |
|
|
2072 | #if EV_IDLE_ENABLE |
2011 | void |
2073 | void |
2012 | ev_idle_start (EV_P_ ev_idle *w) |
2074 | ev_idle_start (EV_P_ ev_idle *w) |
2013 | { |
2075 | { |
2014 | if (expect_false (ev_is_active (w))) |
2076 | if (expect_false (ev_is_active (w))) |
2015 | return; |
2077 | return; |
2016 | |
2078 | |
|
|
2079 | pri_adjust (EV_A_ (W)w); |
|
|
2080 | |
|
|
2081 | { |
|
|
2082 | int active = ++idlecnt [ABSPRI (w)]; |
|
|
2083 | |
|
|
2084 | ++idleall; |
2017 | ev_start (EV_A_ (W)w, ++idlecnt); |
2085 | ev_start (EV_A_ (W)w, active); |
|
|
2086 | |
2018 | array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
2087 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
2019 | idles [idlecnt - 1] = w; |
2088 | idles [ABSPRI (w)][active - 1] = w; |
|
|
2089 | } |
2020 | } |
2090 | } |
2021 | |
2091 | |
2022 | void |
2092 | void |
2023 | ev_idle_stop (EV_P_ ev_idle *w) |
2093 | ev_idle_stop (EV_P_ ev_idle *w) |
2024 | { |
2094 | { |
2025 | ev_clear_pending (EV_A_ (W)w); |
2095 | clear_pending (EV_A_ (W)w); |
2026 | if (expect_false (!ev_is_active (w))) |
2096 | if (expect_false (!ev_is_active (w))) |
2027 | return; |
2097 | return; |
2028 | |
2098 | |
2029 | { |
2099 | { |
2030 | int active = ((W)w)->active; |
2100 | int active = ((W)w)->active; |
2031 | idles [active - 1] = idles [--idlecnt]; |
2101 | |
|
|
2102 | idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]]; |
2032 | ((W)idles [active - 1])->active = active; |
2103 | ((W)idles [ABSPRI (w)][active - 1])->active = active; |
|
|
2104 | |
|
|
2105 | ev_stop (EV_A_ (W)w); |
|
|
2106 | --idleall; |
2033 | } |
2107 | } |
2034 | |
|
|
2035 | ev_stop (EV_A_ (W)w); |
|
|
2036 | } |
2108 | } |
|
|
2109 | #endif |
2037 | |
2110 | |
2038 | void |
2111 | void |
2039 | ev_prepare_start (EV_P_ ev_prepare *w) |
2112 | ev_prepare_start (EV_P_ ev_prepare *w) |
2040 | { |
2113 | { |
2041 | if (expect_false (ev_is_active (w))) |
2114 | if (expect_false (ev_is_active (w))) |
… | |
… | |
2047 | } |
2120 | } |
2048 | |
2121 | |
2049 | void |
2122 | void |
2050 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2123 | ev_prepare_stop (EV_P_ ev_prepare *w) |
2051 | { |
2124 | { |
2052 | ev_clear_pending (EV_A_ (W)w); |
2125 | clear_pending (EV_A_ (W)w); |
2053 | if (expect_false (!ev_is_active (w))) |
2126 | if (expect_false (!ev_is_active (w))) |
2054 | return; |
2127 | return; |
2055 | |
2128 | |
2056 | { |
2129 | { |
2057 | int active = ((W)w)->active; |
2130 | int active = ((W)w)->active; |
… | |
… | |
2074 | } |
2147 | } |
2075 | |
2148 | |
2076 | void |
2149 | void |
2077 | ev_check_stop (EV_P_ ev_check *w) |
2150 | ev_check_stop (EV_P_ ev_check *w) |
2078 | { |
2151 | { |
2079 | ev_clear_pending (EV_A_ (W)w); |
2152 | clear_pending (EV_A_ (W)w); |
2080 | if (expect_false (!ev_is_active (w))) |
2153 | if (expect_false (!ev_is_active (w))) |
2081 | return; |
2154 | return; |
2082 | |
2155 | |
2083 | { |
2156 | { |
2084 | int active = ((W)w)->active; |
2157 | int active = ((W)w)->active; |
… | |
… | |
2126 | } |
2199 | } |
2127 | |
2200 | |
2128 | void |
2201 | void |
2129 | ev_embed_stop (EV_P_ ev_embed *w) |
2202 | ev_embed_stop (EV_P_ ev_embed *w) |
2130 | { |
2203 | { |
2131 | ev_clear_pending (EV_A_ (W)w); |
2204 | clear_pending (EV_A_ (W)w); |
2132 | if (expect_false (!ev_is_active (w))) |
2205 | if (expect_false (!ev_is_active (w))) |
2133 | return; |
2206 | return; |
2134 | |
2207 | |
2135 | ev_io_stop (EV_A_ &w->io); |
2208 | ev_io_stop (EV_A_ &w->io); |
2136 | |
2209 | |
… | |
… | |
2151 | } |
2224 | } |
2152 | |
2225 | |
2153 | void |
2226 | void |
2154 | ev_fork_stop (EV_P_ ev_fork *w) |
2227 | ev_fork_stop (EV_P_ ev_fork *w) |
2155 | { |
2228 | { |
2156 | ev_clear_pending (EV_A_ (W)w); |
2229 | clear_pending (EV_A_ (W)w); |
2157 | if (expect_false (!ev_is_active (w))) |
2230 | if (expect_false (!ev_is_active (w))) |
2158 | return; |
2231 | return; |
2159 | |
2232 | |
2160 | { |
2233 | { |
2161 | int active = ((W)w)->active; |
2234 | int active = ((W)w)->active; |