… | |
… | |
126 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
126 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
127 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
127 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detect time jumps) */ |
128 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
128 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
129 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
129 | /*#define CLEANUP_INTERVAL 300. /* how often to try to free memory and re-check fds */ |
130 | |
130 | |
|
|
131 | #ifdef EV_H |
|
|
132 | # include EV_H |
|
|
133 | #else |
131 | #include "ev.h" |
134 | # include "ev.h" |
|
|
135 | #endif |
132 | |
136 | |
133 | #if __GNUC__ >= 3 |
137 | #if __GNUC__ >= 3 |
134 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
138 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
135 | # define inline inline |
139 | # define inline inline |
136 | #else |
140 | #else |
… | |
… | |
514 | |
518 | |
515 | heap [k] = w; |
519 | heap [k] = w; |
516 | ((W)heap [k])->active = k + 1; |
520 | ((W)heap [k])->active = k + 1; |
517 | } |
521 | } |
518 | |
522 | |
|
|
523 | inline void |
|
|
524 | adjustheap (WT *heap, int N, int k, ev_tstamp at) |
|
|
525 | { |
|
|
526 | ev_tstamp old_at = heap [k]->at; |
|
|
527 | heap [k]->at = at; |
|
|
528 | |
|
|
529 | if (old_at < at) |
|
|
530 | downheap (heap, N, k); |
|
|
531 | else |
|
|
532 | upheap (heap, k); |
|
|
533 | } |
|
|
534 | |
519 | /*****************************************************************************/ |
535 | /*****************************************************************************/ |
520 | |
536 | |
521 | typedef struct |
537 | typedef struct |
522 | { |
538 | { |
523 | WL head; |
539 | WL head; |
… | |
… | |
747 | #endif |
763 | #endif |
748 | #if EV_USE_SELECT |
764 | #if EV_USE_SELECT |
749 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
765 | if (!method && (methods & EVMETHOD_SELECT)) method = select_init (EV_A_ methods); |
750 | #endif |
766 | #endif |
751 | |
767 | |
752 | ev_watcher_init (&sigev, sigcb); |
768 | ev_init (&sigev, sigcb); |
753 | ev_set_priority (&sigev, EV_MAXPRI); |
769 | ev_set_priority (&sigev, EV_MAXPRI); |
754 | } |
770 | } |
755 | } |
771 | } |
756 | |
772 | |
757 | void |
773 | void |
… | |
… | |
944 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
960 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
945 | |
961 | |
946 | if (p->w) |
962 | if (p->w) |
947 | { |
963 | { |
948 | p->w->pending = 0; |
964 | p->w->pending = 0; |
949 | p->w->cb (EV_A_ p->w, p->events); |
965 | EV_CB_INVOKE (p->w, p->events); |
950 | } |
966 | } |
951 | } |
967 | } |
952 | } |
968 | } |
953 | |
969 | |
954 | static void |
970 | static void |
… | |
… | |
1317 | ev_timer_again (EV_P_ struct ev_timer *w) |
1333 | ev_timer_again (EV_P_ struct ev_timer *w) |
1318 | { |
1334 | { |
1319 | if (ev_is_active (w)) |
1335 | if (ev_is_active (w)) |
1320 | { |
1336 | { |
1321 | if (w->repeat) |
1337 | if (w->repeat) |
1322 | { |
|
|
1323 | ((WT)w)->at = mn_now + w->repeat; |
|
|
1324 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1338 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); |
1325 | } |
|
|
1326 | else |
1339 | else |
1327 | ev_timer_stop (EV_A_ w); |
1340 | ev_timer_stop (EV_A_ w); |
1328 | } |
1341 | } |
1329 | else if (w->repeat) |
1342 | else if (w->repeat) |
1330 | ev_timer_start (EV_A_ w); |
1343 | ev_timer_start (EV_A_ w); |
… | |
… | |
1372 | } |
1385 | } |
1373 | |
1386 | |
1374 | void |
1387 | void |
1375 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
1388 | ev_periodic_again (EV_P_ struct ev_periodic *w) |
1376 | { |
1389 | { |
|
|
1390 | /* TODO: use adjustheap and recalculation */ |
1377 | ev_periodic_stop (EV_A_ w); |
1391 | ev_periodic_stop (EV_A_ w); |
1378 | ev_periodic_start (EV_A_ w); |
1392 | ev_periodic_start (EV_A_ w); |
1379 | } |
1393 | } |
1380 | |
1394 | |
1381 | void |
1395 | void |
… | |
… | |
1560 | else |
1574 | else |
1561 | { |
1575 | { |
1562 | once->cb = cb; |
1576 | once->cb = cb; |
1563 | once->arg = arg; |
1577 | once->arg = arg; |
1564 | |
1578 | |
1565 | ev_watcher_init (&once->io, once_cb_io); |
1579 | ev_init (&once->io, once_cb_io); |
1566 | if (fd >= 0) |
1580 | if (fd >= 0) |
1567 | { |
1581 | { |
1568 | ev_io_set (&once->io, fd, events); |
1582 | ev_io_set (&once->io, fd, events); |
1569 | ev_io_start (EV_A_ &once->io); |
1583 | ev_io_start (EV_A_ &once->io); |
1570 | } |
1584 | } |
1571 | |
1585 | |
1572 | ev_watcher_init (&once->to, once_cb_to); |
1586 | ev_init (&once->to, once_cb_to); |
1573 | if (timeout >= 0.) |
1587 | if (timeout >= 0.) |
1574 | { |
1588 | { |
1575 | ev_timer_set (&once->to, timeout, 0.); |
1589 | ev_timer_set (&once->to, timeout, 0.); |
1576 | ev_timer_start (EV_A_ &once->to); |
1590 | ev_timer_start (EV_A_ &once->to); |
1577 | } |
1591 | } |