… | |
… | |
57 | # endif |
57 | # endif |
58 | # ifndef EV_USE_MONOTONIC |
58 | # ifndef EV_USE_MONOTONIC |
59 | # define EV_USE_MONOTONIC 1 |
59 | # define EV_USE_MONOTONIC 1 |
60 | # endif |
60 | # endif |
61 | # endif |
61 | # endif |
|
|
62 | # elif !defined(EV_USE_CLOCK_SYSCALL) |
|
|
63 | # define EV_USE_CLOCK_SYSCALL 0 |
62 | # endif |
64 | # endif |
63 | |
65 | |
64 | # if HAVE_CLOCK_GETTIME |
66 | # if HAVE_CLOCK_GETTIME |
65 | # ifndef EV_USE_MONOTONIC |
67 | # ifndef EV_USE_MONOTONIC |
66 | # define EV_USE_MONOTONIC 1 |
68 | # define EV_USE_MONOTONIC 1 |
… | |
… | |
324 | |
326 | |
325 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
327 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
326 | /* which makes programs even slower. might work on other unices, too. */ |
328 | /* which makes programs even slower. might work on other unices, too. */ |
327 | #if EV_USE_CLOCK_SYSCALL |
329 | #if EV_USE_CLOCK_SYSCALL |
328 | # include <syscall.h> |
330 | # include <syscall.h> |
|
|
331 | # ifdef SYS_clock_gettime |
329 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
332 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
330 | # undef EV_USE_MONOTONIC |
333 | # undef EV_USE_MONOTONIC |
331 | # define EV_USE_MONOTONIC 1 |
334 | # define EV_USE_MONOTONIC 1 |
|
|
335 | # else |
|
|
336 | # undef EV_USE_CLOCK_SYSCALL |
|
|
337 | # define EV_USE_CLOCK_SYSCALL 0 |
|
|
338 | # endif |
332 | #endif |
339 | #endif |
333 | |
340 | |
334 | #if EV_USE_EVENTFD |
341 | #if EV_USE_EVENTFD |
335 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
342 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
336 | # include <stdint.h> |
343 | # include <stdint.h> |
… | |
… | |
478 | #define ev_malloc(size) ev_realloc (0, (size)) |
485 | #define ev_malloc(size) ev_realloc (0, (size)) |
479 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
486 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
480 | |
487 | |
481 | /*****************************************************************************/ |
488 | /*****************************************************************************/ |
482 | |
489 | |
|
|
490 | /* file descriptor info structure */ |
483 | typedef struct |
491 | typedef struct |
484 | { |
492 | { |
485 | WL head; |
493 | WL head; |
486 | unsigned char events; |
494 | unsigned char events; /* the events watched for */ |
487 | unsigned char reify; |
495 | unsigned char reify; /* flag set when this ANFD needs reification */ |
488 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
496 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
489 | unsigned char unused; |
497 | unsigned char unused; |
490 | #if EV_USE_EPOLL |
498 | #if EV_USE_EPOLL |
491 | unsigned int egen; /* generation counter to counter epoll bugs */ |
499 | unsigned int egen; /* generation counter to counter epoll bugs */ |
492 | #endif |
500 | #endif |
493 | #if EV_SELECT_IS_WINSOCKET |
501 | #if EV_SELECT_IS_WINSOCKET |
494 | SOCKET handle; |
502 | SOCKET handle; |
495 | #endif |
503 | #endif |
496 | } ANFD; |
504 | } ANFD; |
497 | |
505 | |
|
|
506 | /* stores the pending event set for a given watcher */ |
498 | typedef struct |
507 | typedef struct |
499 | { |
508 | { |
500 | W w; |
509 | W w; |
501 | int events; |
510 | int events; /* the pending event set for the given watcher */ |
502 | } ANPENDING; |
511 | } ANPENDING; |
503 | |
512 | |
504 | #if EV_USE_INOTIFY |
513 | #if EV_USE_INOTIFY |
505 | /* hash table entry per inotify-id */ |
514 | /* hash table entry per inotify-id */ |
506 | typedef struct |
515 | typedef struct |
… | |
… | |
509 | } ANFS; |
518 | } ANFS; |
510 | #endif |
519 | #endif |
511 | |
520 | |
512 | /* Heap Entry */ |
521 | /* Heap Entry */ |
513 | #if EV_HEAP_CACHE_AT |
522 | #if EV_HEAP_CACHE_AT |
|
|
523 | /* a heap element */ |
514 | typedef struct { |
524 | typedef struct { |
515 | ev_tstamp at; |
525 | ev_tstamp at; |
516 | WT w; |
526 | WT w; |
517 | } ANHE; |
527 | } ANHE; |
518 | |
528 | |
519 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
529 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
520 | #define ANHE_at(he) (he).at /* access cached at, read-only */ |
530 | #define ANHE_at(he) (he).at /* access cached at, read-only */ |
521 | #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */ |
531 | #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */ |
522 | #else |
532 | #else |
|
|
533 | /* a heap element */ |
523 | typedef WT ANHE; |
534 | typedef WT ANHE; |
524 | |
535 | |
525 | #define ANHE_w(he) (he) |
536 | #define ANHE_w(he) (he) |
526 | #define ANHE_at(he) (he)->at |
537 | #define ANHE_at(he) (he)->at |
527 | #define ANHE_at_cache(he) |
538 | #define ANHE_at_cache(he) |
… | |
… | |
625 | |
636 | |
626 | /*****************************************************************************/ |
637 | /*****************************************************************************/ |
627 | |
638 | |
628 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
639 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
629 | |
640 | |
|
|
641 | /* find a suitable new size for the given array, */ |
|
|
642 | /* hopefully by rounding to a ncie-to-malloc size */ |
630 | inline_size int |
643 | inline_size int |
631 | array_nextsize (int elem, int cur, int cnt) |
644 | array_nextsize (int elem, int cur, int cnt) |
632 | { |
645 | { |
633 | int ncur = cur + 1; |
646 | int ncur = cur + 1; |
634 | |
647 | |
… | |
… | |
680 | #define array_free(stem, idx) \ |
693 | #define array_free(stem, idx) \ |
681 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
694 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
682 | |
695 | |
683 | /*****************************************************************************/ |
696 | /*****************************************************************************/ |
684 | |
697 | |
|
|
698 | /* dummy callback for pending events */ |
|
|
699 | static void noinline |
|
|
700 | pendingcb (EV_P_ ev_prepare *w, int revents) |
|
|
701 | { |
|
|
702 | } |
|
|
703 | |
685 | void noinline |
704 | void noinline |
686 | ev_feed_event (EV_P_ void *w, int revents) |
705 | ev_feed_event (EV_P_ void *w, int revents) |
687 | { |
706 | { |
688 | W w_ = (W)w; |
707 | W w_ = (W)w; |
689 | int pri = ABSPRI (w_); |
708 | int pri = ABSPRI (w_); |
… | |
… | |
745 | { |
764 | { |
746 | if (fd >= 0 && fd < anfdmax) |
765 | if (fd >= 0 && fd < anfdmax) |
747 | fd_event (EV_A_ fd, revents); |
766 | fd_event (EV_A_ fd, revents); |
748 | } |
767 | } |
749 | |
768 | |
|
|
769 | /* make sure the external fd watch events are in-sync */ |
|
|
770 | /* with the kernel/libev internal state */ |
750 | inline_size void |
771 | inline_size void |
751 | fd_reify (EV_P) |
772 | fd_reify (EV_P) |
752 | { |
773 | { |
753 | int i; |
774 | int i; |
754 | |
775 | |
… | |
… | |
789 | } |
810 | } |
790 | |
811 | |
791 | fdchangecnt = 0; |
812 | fdchangecnt = 0; |
792 | } |
813 | } |
793 | |
814 | |
|
|
815 | /* something about the given fd changed */ |
794 | inline_size void |
816 | inline_size void |
795 | fd_change (EV_P_ int fd, int flags) |
817 | fd_change (EV_P_ int fd, int flags) |
796 | { |
818 | { |
797 | unsigned char reify = anfds [fd].reify; |
819 | unsigned char reify = anfds [fd].reify; |
798 | anfds [fd].reify |= flags; |
820 | anfds [fd].reify |= flags; |
… | |
… | |
803 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
825 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
804 | fdchanges [fdchangecnt - 1] = fd; |
826 | fdchanges [fdchangecnt - 1] = fd; |
805 | } |
827 | } |
806 | } |
828 | } |
807 | |
829 | |
|
|
830 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
808 | inline_speed void |
831 | inline_speed void |
809 | fd_kill (EV_P_ int fd) |
832 | fd_kill (EV_P_ int fd) |
810 | { |
833 | { |
811 | ev_io *w; |
834 | ev_io *w; |
812 | |
835 | |
… | |
… | |
815 | ev_io_stop (EV_A_ w); |
838 | ev_io_stop (EV_A_ w); |
816 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
839 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
817 | } |
840 | } |
818 | } |
841 | } |
819 | |
842 | |
|
|
843 | /* check whether the given fd is atcually valid, for error recovery */ |
820 | inline_size int |
844 | inline_size int |
821 | fd_valid (int fd) |
845 | fd_valid (int fd) |
822 | { |
846 | { |
823 | #ifdef _WIN32 |
847 | #ifdef _WIN32 |
824 | return _get_osfhandle (fd) != -1; |
848 | return _get_osfhandle (fd) != -1; |
… | |
… | |
989 | |
1013 | |
990 | heap [k] = he; |
1014 | heap [k] = he; |
991 | ev_active (ANHE_w (he)) = k; |
1015 | ev_active (ANHE_w (he)) = k; |
992 | } |
1016 | } |
993 | |
1017 | |
|
|
1018 | /* move an element suitably so it is in a correct place */ |
994 | inline_size void |
1019 | inline_size void |
995 | adjustheap (ANHE *heap, int N, int k) |
1020 | adjustheap (ANHE *heap, int N, int k) |
996 | { |
1021 | { |
997 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
1022 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
998 | upheap (heap, k); |
1023 | upheap (heap, k); |
… | |
… | |
1012 | upheap (heap, i + HEAP0); |
1037 | upheap (heap, i + HEAP0); |
1013 | } |
1038 | } |
1014 | |
1039 | |
1015 | /*****************************************************************************/ |
1040 | /*****************************************************************************/ |
1016 | |
1041 | |
|
|
1042 | /* associate signal watchers to a signal signal */ |
1017 | typedef struct |
1043 | typedef struct |
1018 | { |
1044 | { |
1019 | WL head; |
1045 | WL head; |
1020 | EV_ATOMIC_T gotsig; |
1046 | EV_ATOMIC_T gotsig; |
1021 | } ANSIG; |
1047 | } ANSIG; |
… | |
… | |
1025 | |
1051 | |
1026 | static EV_ATOMIC_T gotsig; |
1052 | static EV_ATOMIC_T gotsig; |
1027 | |
1053 | |
1028 | /*****************************************************************************/ |
1054 | /*****************************************************************************/ |
1029 | |
1055 | |
|
|
1056 | /* used to prepare libev internal fd's */ |
|
|
1057 | /* this is not fork-safe */ |
1030 | inline_speed void |
1058 | inline_speed void |
1031 | fd_intern (int fd) |
1059 | fd_intern (int fd) |
1032 | { |
1060 | { |
1033 | #ifdef _WIN32 |
1061 | #ifdef _WIN32 |
1034 | unsigned long arg = 1; |
1062 | unsigned long arg = 1; |
… | |
… | |
1040 | } |
1068 | } |
1041 | |
1069 | |
1042 | static void noinline |
1070 | static void noinline |
1043 | evpipe_init (EV_P) |
1071 | evpipe_init (EV_P) |
1044 | { |
1072 | { |
1045 | if (!ev_is_active (&pipeev)) |
1073 | if (!ev_is_active (&pipe_w)) |
1046 | { |
1074 | { |
1047 | #if EV_USE_EVENTFD |
1075 | #if EV_USE_EVENTFD |
1048 | if ((evfd = eventfd (0, 0)) >= 0) |
1076 | if ((evfd = eventfd (0, 0)) >= 0) |
1049 | { |
1077 | { |
1050 | evpipe [0] = -1; |
1078 | evpipe [0] = -1; |
1051 | fd_intern (evfd); |
1079 | fd_intern (evfd); |
1052 | ev_io_set (&pipeev, evfd, EV_READ); |
1080 | ev_io_set (&pipe_w, evfd, EV_READ); |
1053 | } |
1081 | } |
1054 | else |
1082 | else |
1055 | #endif |
1083 | #endif |
1056 | { |
1084 | { |
1057 | while (pipe (evpipe)) |
1085 | while (pipe (evpipe)) |
1058 | ev_syserr ("(libev) error creating signal/async pipe"); |
1086 | ev_syserr ("(libev) error creating signal/async pipe"); |
1059 | |
1087 | |
1060 | fd_intern (evpipe [0]); |
1088 | fd_intern (evpipe [0]); |
1061 | fd_intern (evpipe [1]); |
1089 | fd_intern (evpipe [1]); |
1062 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
1090 | ev_io_set (&pipe_w, evpipe [0], EV_READ); |
1063 | } |
1091 | } |
1064 | |
1092 | |
1065 | ev_io_start (EV_A_ &pipeev); |
1093 | ev_io_start (EV_A_ &pipe_w); |
1066 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1094 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1067 | } |
1095 | } |
1068 | } |
1096 | } |
1069 | |
1097 | |
1070 | inline_size void |
1098 | inline_size void |
… | |
… | |
1088 | |
1116 | |
1089 | errno = old_errno; |
1117 | errno = old_errno; |
1090 | } |
1118 | } |
1091 | } |
1119 | } |
1092 | |
1120 | |
|
|
1121 | /* called whenever the libev signal pipe */ |
|
|
1122 | /* got some events (signal, async) */ |
1093 | static void |
1123 | static void |
1094 | pipecb (EV_P_ ev_io *iow, int revents) |
1124 | pipecb (EV_P_ ev_io *iow, int revents) |
1095 | { |
1125 | { |
1096 | #if EV_USE_EVENTFD |
1126 | #if EV_USE_EVENTFD |
1097 | if (evfd >= 0) |
1127 | if (evfd >= 0) |
… | |
… | |
1179 | |
1209 | |
1180 | #ifndef WIFCONTINUED |
1210 | #ifndef WIFCONTINUED |
1181 | # define WIFCONTINUED(status) 0 |
1211 | # define WIFCONTINUED(status) 0 |
1182 | #endif |
1212 | #endif |
1183 | |
1213 | |
|
|
1214 | /* handle a single child status event */ |
1184 | inline_speed void |
1215 | inline_speed void |
1185 | child_reap (EV_P_ int chain, int pid, int status) |
1216 | child_reap (EV_P_ int chain, int pid, int status) |
1186 | { |
1217 | { |
1187 | ev_child *w; |
1218 | ev_child *w; |
1188 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1219 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
… | |
… | |
1202 | |
1233 | |
1203 | #ifndef WCONTINUED |
1234 | #ifndef WCONTINUED |
1204 | # define WCONTINUED 0 |
1235 | # define WCONTINUED 0 |
1205 | #endif |
1236 | #endif |
1206 | |
1237 | |
|
|
1238 | /* called on sigchld etc., calls waitpid */ |
1207 | static void |
1239 | static void |
1208 | childcb (EV_P_ ev_signal *sw, int revents) |
1240 | childcb (EV_P_ ev_signal *sw, int revents) |
1209 | { |
1241 | { |
1210 | int pid, status; |
1242 | int pid, status; |
1211 | |
1243 | |
… | |
… | |
1336 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
1368 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
1337 | { |
1369 | { |
1338 | timeout_blocktime = interval; |
1370 | timeout_blocktime = interval; |
1339 | } |
1371 | } |
1340 | |
1372 | |
|
|
1373 | /* initialise a loop structure, must be zero-initialised */ |
1341 | static void noinline |
1374 | static void noinline |
1342 | loop_init (EV_P_ unsigned int flags) |
1375 | loop_init (EV_P_ unsigned int flags) |
1343 | { |
1376 | { |
1344 | if (!backend) |
1377 | if (!backend) |
1345 | { |
1378 | { |
… | |
… | |
1405 | #endif |
1438 | #endif |
1406 | #if EV_USE_SELECT |
1439 | #if EV_USE_SELECT |
1407 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1440 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1408 | #endif |
1441 | #endif |
1409 | |
1442 | |
|
|
1443 | ev_prepare_init (&pending_w, pendingcb); |
|
|
1444 | |
1410 | ev_init (&pipeev, pipecb); |
1445 | ev_init (&pipe_w, pipecb); |
1411 | ev_set_priority (&pipeev, EV_MAXPRI); |
1446 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1412 | } |
1447 | } |
1413 | } |
1448 | } |
1414 | |
1449 | |
|
|
1450 | /* free up a loop structure */ |
1415 | static void noinline |
1451 | static void noinline |
1416 | loop_destroy (EV_P) |
1452 | loop_destroy (EV_P) |
1417 | { |
1453 | { |
1418 | int i; |
1454 | int i; |
1419 | |
1455 | |
1420 | if (ev_is_active (&pipeev)) |
1456 | if (ev_is_active (&pipe_w)) |
1421 | { |
1457 | { |
1422 | ev_ref (EV_A); /* signal watcher */ |
1458 | ev_ref (EV_A); /* signal watcher */ |
1423 | ev_io_stop (EV_A_ &pipeev); |
1459 | ev_io_stop (EV_A_ &pipe_w); |
1424 | |
1460 | |
1425 | #if EV_USE_EVENTFD |
1461 | #if EV_USE_EVENTFD |
1426 | if (evfd >= 0) |
1462 | if (evfd >= 0) |
1427 | close (evfd); |
1463 | close (evfd); |
1428 | #endif |
1464 | #endif |
… | |
… | |
1505 | #endif |
1541 | #endif |
1506 | #if EV_USE_INOTIFY |
1542 | #if EV_USE_INOTIFY |
1507 | infy_fork (EV_A); |
1543 | infy_fork (EV_A); |
1508 | #endif |
1544 | #endif |
1509 | |
1545 | |
1510 | if (ev_is_active (&pipeev)) |
1546 | if (ev_is_active (&pipe_w)) |
1511 | { |
1547 | { |
1512 | /* this "locks" the handlers against writing to the pipe */ |
1548 | /* this "locks" the handlers against writing to the pipe */ |
1513 | /* while we modify the fd vars */ |
1549 | /* while we modify the fd vars */ |
1514 | gotsig = 1; |
1550 | gotsig = 1; |
1515 | #if EV_ASYNC_ENABLE |
1551 | #if EV_ASYNC_ENABLE |
1516 | gotasync = 1; |
1552 | gotasync = 1; |
1517 | #endif |
1553 | #endif |
1518 | |
1554 | |
1519 | ev_ref (EV_A); |
1555 | ev_ref (EV_A); |
1520 | ev_io_stop (EV_A_ &pipeev); |
1556 | ev_io_stop (EV_A_ &pipe_w); |
1521 | |
1557 | |
1522 | #if EV_USE_EVENTFD |
1558 | #if EV_USE_EVENTFD |
1523 | if (evfd >= 0) |
1559 | if (evfd >= 0) |
1524 | close (evfd); |
1560 | close (evfd); |
1525 | #endif |
1561 | #endif |
… | |
… | |
1530 | close (evpipe [1]); |
1566 | close (evpipe [1]); |
1531 | } |
1567 | } |
1532 | |
1568 | |
1533 | evpipe_init (EV_A); |
1569 | evpipe_init (EV_A); |
1534 | /* now iterate over everything, in case we missed something */ |
1570 | /* now iterate over everything, in case we missed something */ |
1535 | pipecb (EV_A_ &pipeev, EV_READ); |
1571 | pipecb (EV_A_ &pipe_w, EV_READ); |
1536 | } |
1572 | } |
1537 | |
1573 | |
1538 | postfork = 0; |
1574 | postfork = 0; |
1539 | } |
1575 | } |
1540 | |
1576 | |
… | |
… | |
1746 | for (pri = NUMPRI; pri--; ) |
1782 | for (pri = NUMPRI; pri--; ) |
1747 | while (pendingcnt [pri]) |
1783 | while (pendingcnt [pri]) |
1748 | { |
1784 | { |
1749 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1785 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1750 | |
1786 | |
1751 | if (expect_true (p->w)) |
|
|
1752 | { |
|
|
1753 | /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/ |
1787 | /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/ |
|
|
1788 | /* ^ this is no longer true, as pending_w could be here */ |
1754 | |
1789 | |
1755 | p->w->pending = 0; |
1790 | p->w->pending = 0; |
1756 | EV_CB_INVOKE (p->w, p->events); |
1791 | EV_CB_INVOKE (p->w, p->events); |
1757 | EV_FREQUENT_CHECK; |
1792 | EV_FREQUENT_CHECK; |
1758 | } |
|
|
1759 | } |
1793 | } |
1760 | } |
1794 | } |
1761 | |
1795 | |
1762 | #if EV_IDLE_ENABLE |
1796 | #if EV_IDLE_ENABLE |
|
|
1797 | /* make idle watchers pending. this handles the "call-idle */ |
|
|
1798 | /* only when higher priorities are idle" logic */ |
1763 | inline_size void |
1799 | inline_size void |
1764 | idle_reify (EV_P) |
1800 | idle_reify (EV_P) |
1765 | { |
1801 | { |
1766 | if (expect_false (idleall)) |
1802 | if (expect_false (idleall)) |
1767 | { |
1803 | { |
… | |
… | |
1780 | } |
1816 | } |
1781 | } |
1817 | } |
1782 | } |
1818 | } |
1783 | #endif |
1819 | #endif |
1784 | |
1820 | |
|
|
1821 | /* make timers pending */ |
1785 | inline_size void |
1822 | inline_size void |
1786 | timers_reify (EV_P) |
1823 | timers_reify (EV_P) |
1787 | { |
1824 | { |
1788 | EV_FREQUENT_CHECK; |
1825 | EV_FREQUENT_CHECK; |
1789 | |
1826 | |
… | |
… | |
1818 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
1855 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
1819 | } |
1856 | } |
1820 | } |
1857 | } |
1821 | |
1858 | |
1822 | #if EV_PERIODIC_ENABLE |
1859 | #if EV_PERIODIC_ENABLE |
|
|
1860 | /* make periodics pending */ |
1823 | inline_size void |
1861 | inline_size void |
1824 | periodics_reify (EV_P) |
1862 | periodics_reify (EV_P) |
1825 | { |
1863 | { |
1826 | EV_FREQUENT_CHECK; |
1864 | EV_FREQUENT_CHECK; |
1827 | |
1865 | |
… | |
… | |
1874 | |
1912 | |
1875 | feed_reverse_done (EV_A_ EV_PERIODIC); |
1913 | feed_reverse_done (EV_A_ EV_PERIODIC); |
1876 | } |
1914 | } |
1877 | } |
1915 | } |
1878 | |
1916 | |
|
|
1917 | /* simply recalculate all periodics */ |
|
|
1918 | /* TODO: maybe ensure that at leats one event happens when jumping forward? */ |
1879 | static void noinline |
1919 | static void noinline |
1880 | periodics_reschedule (EV_P) |
1920 | periodics_reschedule (EV_P) |
1881 | { |
1921 | { |
1882 | int i; |
1922 | int i; |
1883 | |
1923 | |
… | |
… | |
1896 | |
1936 | |
1897 | reheap (periodics, periodiccnt); |
1937 | reheap (periodics, periodiccnt); |
1898 | } |
1938 | } |
1899 | #endif |
1939 | #endif |
1900 | |
1940 | |
|
|
1941 | /* adjust all timers by a given offset */ |
1901 | static void noinline |
1942 | static void noinline |
1902 | timers_reschedule (EV_P_ ev_tstamp adjust) |
1943 | timers_reschedule (EV_P_ ev_tstamp adjust) |
1903 | { |
1944 | { |
1904 | int i; |
1945 | int i; |
1905 | |
1946 | |
… | |
… | |
1909 | ANHE_w (*he)->at += adjust; |
1950 | ANHE_w (*he)->at += adjust; |
1910 | ANHE_at_cache (*he); |
1951 | ANHE_at_cache (*he); |
1911 | } |
1952 | } |
1912 | } |
1953 | } |
1913 | |
1954 | |
|
|
1955 | /* fetch new monotonic and realtime times from the kernel */ |
|
|
1956 | /* also detetc if there was a timejump, and act accordingly */ |
1914 | inline_speed void |
1957 | inline_speed void |
1915 | time_update (EV_P_ ev_tstamp max_block) |
1958 | time_update (EV_P_ ev_tstamp max_block) |
1916 | { |
1959 | { |
1917 | int i; |
|
|
1918 | |
|
|
1919 | #if EV_USE_MONOTONIC |
1960 | #if EV_USE_MONOTONIC |
1920 | if (expect_true (have_monotonic)) |
1961 | if (expect_true (have_monotonic)) |
1921 | { |
1962 | { |
|
|
1963 | int i; |
1922 | ev_tstamp odiff = rtmn_diff; |
1964 | ev_tstamp odiff = rtmn_diff; |
1923 | |
1965 | |
1924 | mn_now = get_clock (); |
1966 | mn_now = get_clock (); |
1925 | |
1967 | |
1926 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
1968 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
… | |
… | |
2137 | ev_tstamp mn_prev = mn_now; |
2179 | ev_tstamp mn_prev = mn_now; |
2138 | |
2180 | |
2139 | ev_now_update (EV_A); |
2181 | ev_now_update (EV_A); |
2140 | timers_reschedule (EV_A_ mn_now - mn_prev); |
2182 | timers_reschedule (EV_A_ mn_now - mn_prev); |
2141 | #if EV_PERIODIC_ENABLE |
2183 | #if EV_PERIODIC_ENABLE |
|
|
2184 | /* TODO: really do this? */ |
2142 | periodics_reschedule (EV_A); |
2185 | periodics_reschedule (EV_A); |
2143 | #endif |
2186 | #endif |
2144 | } |
2187 | } |
2145 | |
2188 | |
2146 | /*****************************************************************************/ |
2189 | /*****************************************************************************/ |
|
|
2190 | /* singly-linked list management, used when the expected list length is short */ |
2147 | |
2191 | |
2148 | inline_size void |
2192 | inline_size void |
2149 | wlist_add (WL *head, WL elem) |
2193 | wlist_add (WL *head, WL elem) |
2150 | { |
2194 | { |
2151 | elem->next = *head; |
2195 | elem->next = *head; |
… | |
… | |
2165 | |
2209 | |
2166 | head = &(*head)->next; |
2210 | head = &(*head)->next; |
2167 | } |
2211 | } |
2168 | } |
2212 | } |
2169 | |
2213 | |
|
|
2214 | /* internal, faster, version of ev_clear_pending */ |
2170 | inline_speed void |
2215 | inline_speed void |
2171 | clear_pending (EV_P_ W w) |
2216 | clear_pending (EV_P_ W w) |
2172 | { |
2217 | { |
2173 | if (w->pending) |
2218 | if (w->pending) |
2174 | { |
2219 | { |
2175 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
2220 | pendings [ABSPRI (w)][w->pending - 1].w = (W)&pending_w; |
2176 | w->pending = 0; |
2221 | w->pending = 0; |
2177 | } |
2222 | } |
2178 | } |
2223 | } |
2179 | |
2224 | |
2180 | int |
2225 | int |
… | |
… | |
2184 | int pending = w_->pending; |
2229 | int pending = w_->pending; |
2185 | |
2230 | |
2186 | if (expect_true (pending)) |
2231 | if (expect_true (pending)) |
2187 | { |
2232 | { |
2188 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
2233 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
2234 | p->w = (W)&pending_w; |
2189 | w_->pending = 0; |
2235 | w_->pending = 0; |
2190 | p->w = 0; |
|
|
2191 | return p->events; |
2236 | return p->events; |
2192 | } |
2237 | } |
2193 | else |
2238 | else |
2194 | return 0; |
2239 | return 0; |
2195 | } |
2240 | } |
… | |
… | |
3201 | } |
3246 | } |
3202 | } |
3247 | } |
3203 | |
3248 | |
3204 | /*****************************************************************************/ |
3249 | /*****************************************************************************/ |
3205 | |
3250 | |
3206 | #if 0 |
3251 | #if EV_WALK_ENABLE |
3207 | void |
3252 | void |
3208 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
3253 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
3209 | { |
3254 | { |
3210 | int i, j; |
3255 | int i, j; |
3211 | ev_watcher_list *wl, *wn; |
3256 | ev_watcher_list *wl, *wn; |
… | |
… | |
3227 | #if EV_USE_INOTIFY |
3272 | #if EV_USE_INOTIFY |
3228 | if (ev_cb ((ev_io *)wl) == infy_cb) |
3273 | if (ev_cb ((ev_io *)wl) == infy_cb) |
3229 | ; |
3274 | ; |
3230 | else |
3275 | else |
3231 | #endif |
3276 | #endif |
3232 | if ((ev_io *)wl != &pipeev) |
3277 | if ((ev_io *)wl != &pipe_w) |
3233 | if (types & EV_IO) |
3278 | if (types & EV_IO) |
3234 | cb (EV_A_ EV_IO, wl); |
3279 | cb (EV_A_ EV_IO, wl); |
3235 | |
3280 | |
3236 | wl = wn; |
3281 | wl = wn; |
3237 | } |
3282 | } |