… | |
… | |
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 |
… | |
… | |
282 | |
284 | |
283 | #ifndef EV_HEAP_CACHE_AT |
285 | #ifndef EV_HEAP_CACHE_AT |
284 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
286 | # define EV_HEAP_CACHE_AT !EV_MINIMAL |
285 | #endif |
287 | #endif |
286 | |
288 | |
|
|
289 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
|
|
290 | /* which makes programs even slower. might work on other unices, too. */ |
|
|
291 | #if EV_USE_CLOCK_SYSCALL |
|
|
292 | # include <syscall.h> |
|
|
293 | # ifdef SYS_clock_gettime |
|
|
294 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
|
|
295 | # undef EV_USE_MONOTONIC |
|
|
296 | # define EV_USE_MONOTONIC 1 |
|
|
297 | # else |
|
|
298 | # undef EV_USE_CLOCK_SYSCALL |
|
|
299 | # define EV_USE_CLOCK_SYSCALL 0 |
|
|
300 | # endif |
|
|
301 | #endif |
|
|
302 | |
287 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
303 | /* this block fixes any misconfiguration where we know we run into trouble otherwise */ |
288 | |
304 | |
289 | #ifndef CLOCK_MONOTONIC |
305 | #ifndef CLOCK_MONOTONIC |
290 | # undef EV_USE_MONOTONIC |
306 | # undef EV_USE_MONOTONIC |
291 | # define EV_USE_MONOTONIC 0 |
307 | # define EV_USE_MONOTONIC 0 |
… | |
… | |
320 | |
336 | |
321 | #if EV_SELECT_IS_WINSOCKET |
337 | #if EV_SELECT_IS_WINSOCKET |
322 | # include <winsock.h> |
338 | # include <winsock.h> |
323 | #endif |
339 | #endif |
324 | |
340 | |
325 | /* 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. */ |
|
|
327 | #if EV_USE_CLOCK_SYSCALL |
|
|
328 | # include <syscall.h> |
|
|
329 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
|
|
330 | # undef EV_USE_MONOTONIC |
|
|
331 | # define EV_USE_MONOTONIC 1 |
|
|
332 | #endif |
|
|
333 | |
|
|
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> |
337 | # ifdef __cplusplus |
344 | # ifdef __cplusplus |
338 | extern "C" { |
345 | extern "C" { |
… | |
… | |
384 | # define inline_speed static noinline |
391 | # define inline_speed static noinline |
385 | #else |
392 | #else |
386 | # define inline_speed static inline |
393 | # define inline_speed static inline |
387 | #endif |
394 | #endif |
388 | |
395 | |
389 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
396 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
|
|
397 | |
|
|
398 | #if EV_MINPRI == EV_MAXPRI |
|
|
399 | # define ABSPRI(w) (((W)w), 0) |
|
|
400 | #else |
390 | #define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
401 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
|
|
402 | #endif |
391 | |
403 | |
392 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
404 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
393 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
405 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
394 | |
406 | |
395 | typedef ev_watcher *W; |
407 | typedef ev_watcher *W; |
… | |
… | |
478 | #define ev_malloc(size) ev_realloc (0, (size)) |
490 | #define ev_malloc(size) ev_realloc (0, (size)) |
479 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
491 | #define ev_free(ptr) ev_realloc ((ptr), 0) |
480 | |
492 | |
481 | /*****************************************************************************/ |
493 | /*****************************************************************************/ |
482 | |
494 | |
|
|
495 | /* file descriptor info structure */ |
483 | typedef struct |
496 | typedef struct |
484 | { |
497 | { |
485 | WL head; |
498 | WL head; |
486 | unsigned char events; |
499 | unsigned char events; /* the events watched for */ |
487 | unsigned char reify; |
500 | unsigned char reify; /* flag set when this ANFD needs reification */ |
488 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
501 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
489 | unsigned char unused; |
502 | unsigned char unused; |
490 | #if EV_USE_EPOLL |
503 | #if EV_USE_EPOLL |
491 | unsigned int egen; /* generation counter to counter epoll bugs */ |
504 | unsigned int egen; /* generation counter to counter epoll bugs */ |
492 | #endif |
505 | #endif |
493 | #if EV_SELECT_IS_WINSOCKET |
506 | #if EV_SELECT_IS_WINSOCKET |
494 | SOCKET handle; |
507 | SOCKET handle; |
495 | #endif |
508 | #endif |
496 | } ANFD; |
509 | } ANFD; |
497 | |
510 | |
|
|
511 | /* stores the pending event set for a given watcher */ |
498 | typedef struct |
512 | typedef struct |
499 | { |
513 | { |
500 | W w; |
514 | W w; |
501 | int events; |
515 | int events; /* the pending event set for the given watcher */ |
502 | } ANPENDING; |
516 | } ANPENDING; |
503 | |
517 | |
504 | #if EV_USE_INOTIFY |
518 | #if EV_USE_INOTIFY |
505 | /* hash table entry per inotify-id */ |
519 | /* hash table entry per inotify-id */ |
506 | typedef struct |
520 | typedef struct |
… | |
… | |
509 | } ANFS; |
523 | } ANFS; |
510 | #endif |
524 | #endif |
511 | |
525 | |
512 | /* Heap Entry */ |
526 | /* Heap Entry */ |
513 | #if EV_HEAP_CACHE_AT |
527 | #if EV_HEAP_CACHE_AT |
|
|
528 | /* a heap element */ |
514 | typedef struct { |
529 | typedef struct { |
515 | ev_tstamp at; |
530 | ev_tstamp at; |
516 | WT w; |
531 | WT w; |
517 | } ANHE; |
532 | } ANHE; |
518 | |
533 | |
519 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
534 | #define ANHE_w(he) (he).w /* access watcher, read-write */ |
520 | #define ANHE_at(he) (he).at /* access cached at, read-only */ |
535 | #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 */ |
536 | #define ANHE_at_cache(he) (he).at = (he).w->at /* update at from watcher */ |
522 | #else |
537 | #else |
|
|
538 | /* a heap element */ |
523 | typedef WT ANHE; |
539 | typedef WT ANHE; |
524 | |
540 | |
525 | #define ANHE_w(he) (he) |
541 | #define ANHE_w(he) (he) |
526 | #define ANHE_at(he) (he)->at |
542 | #define ANHE_at(he) (he)->at |
527 | #define ANHE_at_cache(he) |
543 | #define ANHE_at_cache(he) |
… | |
… | |
551 | |
567 | |
552 | static int ev_default_loop_ptr; |
568 | static int ev_default_loop_ptr; |
553 | |
569 | |
554 | #endif |
570 | #endif |
555 | |
571 | |
|
|
572 | #if EV_MINIMAL < 2 |
|
|
573 | # define EV_SUSPEND_CB if (expect_false (suspend_cb)) suspend_cb (EV_A) |
|
|
574 | # define EV_RESUME_CB if (expect_false (resume_cb )) resume_cb (EV_A) |
|
|
575 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
|
|
576 | #else |
|
|
577 | # define EV_SUSPEND_CB (void)0 |
|
|
578 | # define EV_RESUME_CB (void)0 |
|
|
579 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
|
|
580 | #endif |
|
|
581 | |
556 | /*****************************************************************************/ |
582 | /*****************************************************************************/ |
557 | |
583 | |
|
|
584 | #ifndef EV_HAVE_EV_TIME |
558 | ev_tstamp |
585 | ev_tstamp |
559 | ev_time (void) |
586 | ev_time (void) |
560 | { |
587 | { |
561 | #if EV_USE_REALTIME |
588 | #if EV_USE_REALTIME |
562 | if (expect_true (have_realtime)) |
589 | if (expect_true (have_realtime)) |
… | |
… | |
569 | |
596 | |
570 | struct timeval tv; |
597 | struct timeval tv; |
571 | gettimeofday (&tv, 0); |
598 | gettimeofday (&tv, 0); |
572 | return tv.tv_sec + tv.tv_usec * 1e-6; |
599 | return tv.tv_sec + tv.tv_usec * 1e-6; |
573 | } |
600 | } |
|
|
601 | #endif |
574 | |
602 | |
575 | inline_size ev_tstamp |
603 | inline_size ev_tstamp |
576 | get_clock (void) |
604 | get_clock (void) |
577 | { |
605 | { |
578 | #if EV_USE_MONOTONIC |
606 | #if EV_USE_MONOTONIC |
… | |
… | |
614 | |
642 | |
615 | tv.tv_sec = (time_t)delay; |
643 | tv.tv_sec = (time_t)delay; |
616 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
644 | tv.tv_usec = (long)((delay - (ev_tstamp)(tv.tv_sec)) * 1e6); |
617 | |
645 | |
618 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
646 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
619 | /* somehting nto guaranteed by newer posix versions, but guaranteed */ |
647 | /* somehting not guaranteed by newer posix versions, but guaranteed */ |
620 | /* by older ones */ |
648 | /* by older ones */ |
621 | select (0, 0, 0, 0, &tv); |
649 | select (0, 0, 0, 0, &tv); |
622 | #endif |
650 | #endif |
623 | } |
651 | } |
624 | } |
652 | } |
625 | |
653 | |
626 | /*****************************************************************************/ |
654 | /*****************************************************************************/ |
627 | |
655 | |
628 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
656 | #define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ |
629 | |
657 | |
|
|
658 | /* find a suitable new size for the given array, */ |
|
|
659 | /* hopefully by rounding to a ncie-to-malloc size */ |
630 | inline_size int |
660 | inline_size int |
631 | array_nextsize (int elem, int cur, int cnt) |
661 | array_nextsize (int elem, int cur, int cnt) |
632 | { |
662 | { |
633 | int ncur = cur + 1; |
663 | int ncur = cur + 1; |
634 | |
664 | |
… | |
… | |
680 | #define array_free(stem, idx) \ |
710 | #define array_free(stem, idx) \ |
681 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
711 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
682 | |
712 | |
683 | /*****************************************************************************/ |
713 | /*****************************************************************************/ |
684 | |
714 | |
|
|
715 | /* dummy callback for pending events */ |
|
|
716 | static void noinline |
|
|
717 | pendingcb (EV_P_ ev_prepare *w, int revents) |
|
|
718 | { |
|
|
719 | } |
|
|
720 | |
685 | void noinline |
721 | void noinline |
686 | ev_feed_event (EV_P_ void *w, int revents) |
722 | ev_feed_event (EV_P_ void *w, int revents) |
687 | { |
723 | { |
688 | W w_ = (W)w; |
724 | W w_ = (W)w; |
689 | int pri = ABSPRI (w_); |
725 | int pri = ABSPRI (w_); |
… | |
… | |
745 | { |
781 | { |
746 | if (fd >= 0 && fd < anfdmax) |
782 | if (fd >= 0 && fd < anfdmax) |
747 | fd_event (EV_A_ fd, revents); |
783 | fd_event (EV_A_ fd, revents); |
748 | } |
784 | } |
749 | |
785 | |
|
|
786 | /* make sure the external fd watch events are in-sync */ |
|
|
787 | /* with the kernel/libev internal state */ |
750 | inline_size void |
788 | inline_size void |
751 | fd_reify (EV_P) |
789 | fd_reify (EV_P) |
752 | { |
790 | { |
753 | int i; |
791 | int i; |
754 | |
792 | |
… | |
… | |
789 | } |
827 | } |
790 | |
828 | |
791 | fdchangecnt = 0; |
829 | fdchangecnt = 0; |
792 | } |
830 | } |
793 | |
831 | |
|
|
832 | /* something about the given fd changed */ |
794 | inline_size void |
833 | inline_size void |
795 | fd_change (EV_P_ int fd, int flags) |
834 | fd_change (EV_P_ int fd, int flags) |
796 | { |
835 | { |
797 | unsigned char reify = anfds [fd].reify; |
836 | unsigned char reify = anfds [fd].reify; |
798 | anfds [fd].reify |= flags; |
837 | anfds [fd].reify |= flags; |
… | |
… | |
803 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
842 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
804 | fdchanges [fdchangecnt - 1] = fd; |
843 | fdchanges [fdchangecnt - 1] = fd; |
805 | } |
844 | } |
806 | } |
845 | } |
807 | |
846 | |
|
|
847 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
808 | inline_speed void |
848 | inline_speed void |
809 | fd_kill (EV_P_ int fd) |
849 | fd_kill (EV_P_ int fd) |
810 | { |
850 | { |
811 | ev_io *w; |
851 | ev_io *w; |
812 | |
852 | |
… | |
… | |
815 | ev_io_stop (EV_A_ w); |
855 | ev_io_stop (EV_A_ w); |
816 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
856 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
817 | } |
857 | } |
818 | } |
858 | } |
819 | |
859 | |
|
|
860 | /* check whether the given fd is atcually valid, for error recovery */ |
820 | inline_size int |
861 | inline_size int |
821 | fd_valid (int fd) |
862 | fd_valid (int fd) |
822 | { |
863 | { |
823 | #ifdef _WIN32 |
864 | #ifdef _WIN32 |
824 | return _get_osfhandle (fd) != -1; |
865 | return _get_osfhandle (fd) != -1; |
… | |
… | |
989 | |
1030 | |
990 | heap [k] = he; |
1031 | heap [k] = he; |
991 | ev_active (ANHE_w (he)) = k; |
1032 | ev_active (ANHE_w (he)) = k; |
992 | } |
1033 | } |
993 | |
1034 | |
|
|
1035 | /* move an element suitably so it is in a correct place */ |
994 | inline_size void |
1036 | inline_size void |
995 | adjustheap (ANHE *heap, int N, int k) |
1037 | adjustheap (ANHE *heap, int N, int k) |
996 | { |
1038 | { |
997 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
1039 | if (k > HEAP0 && ANHE_at (heap [HPARENT (k)]) >= ANHE_at (heap [k])) |
998 | upheap (heap, k); |
1040 | upheap (heap, k); |
… | |
… | |
1012 | upheap (heap, i + HEAP0); |
1054 | upheap (heap, i + HEAP0); |
1013 | } |
1055 | } |
1014 | |
1056 | |
1015 | /*****************************************************************************/ |
1057 | /*****************************************************************************/ |
1016 | |
1058 | |
|
|
1059 | /* associate signal watchers to a signal signal */ |
1017 | typedef struct |
1060 | typedef struct |
1018 | { |
1061 | { |
1019 | WL head; |
1062 | WL head; |
1020 | EV_ATOMIC_T gotsig; |
1063 | EV_ATOMIC_T gotsig; |
1021 | } ANSIG; |
1064 | } ANSIG; |
… | |
… | |
1025 | |
1068 | |
1026 | static EV_ATOMIC_T gotsig; |
1069 | static EV_ATOMIC_T gotsig; |
1027 | |
1070 | |
1028 | /*****************************************************************************/ |
1071 | /*****************************************************************************/ |
1029 | |
1072 | |
|
|
1073 | /* used to prepare libev internal fd's */ |
|
|
1074 | /* this is not fork-safe */ |
1030 | inline_speed void |
1075 | inline_speed void |
1031 | fd_intern (int fd) |
1076 | fd_intern (int fd) |
1032 | { |
1077 | { |
1033 | #ifdef _WIN32 |
1078 | #ifdef _WIN32 |
1034 | unsigned long arg = 1; |
1079 | unsigned long arg = 1; |
… | |
… | |
1040 | } |
1085 | } |
1041 | |
1086 | |
1042 | static void noinline |
1087 | static void noinline |
1043 | evpipe_init (EV_P) |
1088 | evpipe_init (EV_P) |
1044 | { |
1089 | { |
1045 | if (!ev_is_active (&pipeev)) |
1090 | if (!ev_is_active (&pipe_w)) |
1046 | { |
1091 | { |
1047 | #if EV_USE_EVENTFD |
1092 | #if EV_USE_EVENTFD |
1048 | if ((evfd = eventfd (0, 0)) >= 0) |
1093 | if ((evfd = eventfd (0, 0)) >= 0) |
1049 | { |
1094 | { |
1050 | evpipe [0] = -1; |
1095 | evpipe [0] = -1; |
1051 | fd_intern (evfd); |
1096 | fd_intern (evfd); |
1052 | ev_io_set (&pipeev, evfd, EV_READ); |
1097 | ev_io_set (&pipe_w, evfd, EV_READ); |
1053 | } |
1098 | } |
1054 | else |
1099 | else |
1055 | #endif |
1100 | #endif |
1056 | { |
1101 | { |
1057 | while (pipe (evpipe)) |
1102 | while (pipe (evpipe)) |
1058 | ev_syserr ("(libev) error creating signal/async pipe"); |
1103 | ev_syserr ("(libev) error creating signal/async pipe"); |
1059 | |
1104 | |
1060 | fd_intern (evpipe [0]); |
1105 | fd_intern (evpipe [0]); |
1061 | fd_intern (evpipe [1]); |
1106 | fd_intern (evpipe [1]); |
1062 | ev_io_set (&pipeev, evpipe [0], EV_READ); |
1107 | ev_io_set (&pipe_w, evpipe [0], EV_READ); |
1063 | } |
1108 | } |
1064 | |
1109 | |
1065 | ev_io_start (EV_A_ &pipeev); |
1110 | ev_io_start (EV_A_ &pipe_w); |
1066 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1111 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
1067 | } |
1112 | } |
1068 | } |
1113 | } |
1069 | |
1114 | |
1070 | inline_size void |
1115 | inline_size void |
… | |
… | |
1088 | |
1133 | |
1089 | errno = old_errno; |
1134 | errno = old_errno; |
1090 | } |
1135 | } |
1091 | } |
1136 | } |
1092 | |
1137 | |
|
|
1138 | /* called whenever the libev signal pipe */ |
|
|
1139 | /* got some events (signal, async) */ |
1093 | static void |
1140 | static void |
1094 | pipecb (EV_P_ ev_io *iow, int revents) |
1141 | pipecb (EV_P_ ev_io *iow, int revents) |
1095 | { |
1142 | { |
1096 | #if EV_USE_EVENTFD |
1143 | #if EV_USE_EVENTFD |
1097 | if (evfd >= 0) |
1144 | if (evfd >= 0) |
… | |
… | |
1179 | |
1226 | |
1180 | #ifndef WIFCONTINUED |
1227 | #ifndef WIFCONTINUED |
1181 | # define WIFCONTINUED(status) 0 |
1228 | # define WIFCONTINUED(status) 0 |
1182 | #endif |
1229 | #endif |
1183 | |
1230 | |
|
|
1231 | /* handle a single child status event */ |
1184 | inline_speed void |
1232 | inline_speed void |
1185 | child_reap (EV_P_ int chain, int pid, int status) |
1233 | child_reap (EV_P_ int chain, int pid, int status) |
1186 | { |
1234 | { |
1187 | ev_child *w; |
1235 | ev_child *w; |
1188 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
1236 | int traced = WIFSTOPPED (status) || WIFCONTINUED (status); |
… | |
… | |
1202 | |
1250 | |
1203 | #ifndef WCONTINUED |
1251 | #ifndef WCONTINUED |
1204 | # define WCONTINUED 0 |
1252 | # define WCONTINUED 0 |
1205 | #endif |
1253 | #endif |
1206 | |
1254 | |
|
|
1255 | /* called on sigchld etc., calls waitpid */ |
1207 | static void |
1256 | static void |
1208 | childcb (EV_P_ ev_signal *sw, int revents) |
1257 | childcb (EV_P_ ev_signal *sw, int revents) |
1209 | { |
1258 | { |
1210 | int pid, status; |
1259 | int pid, status; |
1211 | |
1260 | |
… | |
… | |
1318 | ev_backend (EV_P) |
1367 | ev_backend (EV_P) |
1319 | { |
1368 | { |
1320 | return backend; |
1369 | return backend; |
1321 | } |
1370 | } |
1322 | |
1371 | |
|
|
1372 | #if EV_MINIMAL < 2 |
1323 | unsigned int |
1373 | unsigned int |
1324 | ev_loop_count (EV_P) |
1374 | ev_loop_count (EV_P) |
1325 | { |
1375 | { |
1326 | return loop_count; |
1376 | return loop_count; |
1327 | } |
1377 | } |
1328 | |
1378 | |
|
|
1379 | unsigned int |
|
|
1380 | ev_loop_depth (EV_P) |
|
|
1381 | { |
|
|
1382 | return loop_depth; |
|
|
1383 | } |
|
|
1384 | |
1329 | void |
1385 | void |
1330 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
1386 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
1331 | { |
1387 | { |
1332 | io_blocktime = interval; |
1388 | io_blocktime = interval; |
1333 | } |
1389 | } |
… | |
… | |
1336 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
1392 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
1337 | { |
1393 | { |
1338 | timeout_blocktime = interval; |
1394 | timeout_blocktime = interval; |
1339 | } |
1395 | } |
1340 | |
1396 | |
|
|
1397 | void |
|
|
1398 | ev_set_userdata (EV_P_ void *data) |
|
|
1399 | { |
|
|
1400 | userdata = data; |
|
|
1401 | } |
|
|
1402 | |
|
|
1403 | void * |
|
|
1404 | ev_userdata (EV_P) |
|
|
1405 | { |
|
|
1406 | return userdata; |
|
|
1407 | } |
|
|
1408 | |
|
|
1409 | void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
|
|
1410 | { |
|
|
1411 | invoke_cb = invoke_pending_cb; |
|
|
1412 | } |
|
|
1413 | |
|
|
1414 | void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P)) |
|
|
1415 | { |
|
|
1416 | suspend_cb = suspend_cb_; |
|
|
1417 | resume_cb = resume_cb_; |
|
|
1418 | } |
|
|
1419 | #endif |
|
|
1420 | |
|
|
1421 | /* initialise a loop structure, must be zero-initialised */ |
1341 | static void noinline |
1422 | static void noinline |
1342 | loop_init (EV_P_ unsigned int flags) |
1423 | loop_init (EV_P_ unsigned int flags) |
1343 | { |
1424 | { |
1344 | if (!backend) |
1425 | if (!backend) |
1345 | { |
1426 | { |
… | |
… | |
1365 | |
1446 | |
1366 | ev_rt_now = ev_time (); |
1447 | ev_rt_now = ev_time (); |
1367 | mn_now = get_clock (); |
1448 | mn_now = get_clock (); |
1368 | now_floor = mn_now; |
1449 | now_floor = mn_now; |
1369 | rtmn_diff = ev_rt_now - mn_now; |
1450 | rtmn_diff = ev_rt_now - mn_now; |
|
|
1451 | #if EV_MINIMAL < 2 |
|
|
1452 | invoke_cb = ev_invoke_pending; |
|
|
1453 | #endif |
1370 | |
1454 | |
1371 | io_blocktime = 0.; |
1455 | io_blocktime = 0.; |
1372 | timeout_blocktime = 0.; |
1456 | timeout_blocktime = 0.; |
1373 | backend = 0; |
1457 | backend = 0; |
1374 | backend_fd = -1; |
1458 | backend_fd = -1; |
… | |
… | |
1405 | #endif |
1489 | #endif |
1406 | #if EV_USE_SELECT |
1490 | #if EV_USE_SELECT |
1407 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1491 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
1408 | #endif |
1492 | #endif |
1409 | |
1493 | |
|
|
1494 | ev_prepare_init (&pending_w, pendingcb); |
|
|
1495 | |
1410 | ev_init (&pipeev, pipecb); |
1496 | ev_init (&pipe_w, pipecb); |
1411 | ev_set_priority (&pipeev, EV_MAXPRI); |
1497 | ev_set_priority (&pipe_w, EV_MAXPRI); |
1412 | } |
1498 | } |
1413 | } |
1499 | } |
1414 | |
1500 | |
|
|
1501 | /* free up a loop structure */ |
1415 | static void noinline |
1502 | static void noinline |
1416 | loop_destroy (EV_P) |
1503 | loop_destroy (EV_P) |
1417 | { |
1504 | { |
1418 | int i; |
1505 | int i; |
1419 | |
1506 | |
1420 | if (ev_is_active (&pipeev)) |
1507 | if (ev_is_active (&pipe_w)) |
1421 | { |
1508 | { |
1422 | ev_ref (EV_A); /* signal watcher */ |
1509 | ev_ref (EV_A); /* signal watcher */ |
1423 | ev_io_stop (EV_A_ &pipeev); |
1510 | ev_io_stop (EV_A_ &pipe_w); |
1424 | |
1511 | |
1425 | #if EV_USE_EVENTFD |
1512 | #if EV_USE_EVENTFD |
1426 | if (evfd >= 0) |
1513 | if (evfd >= 0) |
1427 | close (evfd); |
1514 | close (evfd); |
1428 | #endif |
1515 | #endif |
… | |
… | |
1505 | #endif |
1592 | #endif |
1506 | #if EV_USE_INOTIFY |
1593 | #if EV_USE_INOTIFY |
1507 | infy_fork (EV_A); |
1594 | infy_fork (EV_A); |
1508 | #endif |
1595 | #endif |
1509 | |
1596 | |
1510 | if (ev_is_active (&pipeev)) |
1597 | if (ev_is_active (&pipe_w)) |
1511 | { |
1598 | { |
1512 | /* this "locks" the handlers against writing to the pipe */ |
1599 | /* this "locks" the handlers against writing to the pipe */ |
1513 | /* while we modify the fd vars */ |
1600 | /* while we modify the fd vars */ |
1514 | gotsig = 1; |
1601 | gotsig = 1; |
1515 | #if EV_ASYNC_ENABLE |
1602 | #if EV_ASYNC_ENABLE |
1516 | gotasync = 1; |
1603 | gotasync = 1; |
1517 | #endif |
1604 | #endif |
1518 | |
1605 | |
1519 | ev_ref (EV_A); |
1606 | ev_ref (EV_A); |
1520 | ev_io_stop (EV_A_ &pipeev); |
1607 | ev_io_stop (EV_A_ &pipe_w); |
1521 | |
1608 | |
1522 | #if EV_USE_EVENTFD |
1609 | #if EV_USE_EVENTFD |
1523 | if (evfd >= 0) |
1610 | if (evfd >= 0) |
1524 | close (evfd); |
1611 | close (evfd); |
1525 | #endif |
1612 | #endif |
… | |
… | |
1530 | close (evpipe [1]); |
1617 | close (evpipe [1]); |
1531 | } |
1618 | } |
1532 | |
1619 | |
1533 | evpipe_init (EV_A); |
1620 | evpipe_init (EV_A); |
1534 | /* now iterate over everything, in case we missed something */ |
1621 | /* now iterate over everything, in case we missed something */ |
1535 | pipecb (EV_A_ &pipeev, EV_READ); |
1622 | pipecb (EV_A_ &pipe_w, EV_READ); |
1536 | } |
1623 | } |
1537 | |
1624 | |
1538 | postfork = 0; |
1625 | postfork = 0; |
1539 | } |
1626 | } |
1540 | |
1627 | |
… | |
… | |
1565 | void |
1652 | void |
1566 | ev_loop_fork (EV_P) |
1653 | ev_loop_fork (EV_P) |
1567 | { |
1654 | { |
1568 | postfork = 1; /* must be in line with ev_default_fork */ |
1655 | postfork = 1; /* must be in line with ev_default_fork */ |
1569 | } |
1656 | } |
|
|
1657 | #endif /* multiplicity */ |
1570 | |
1658 | |
1571 | #if EV_VERIFY |
1659 | #if EV_VERIFY |
1572 | static void noinline |
1660 | static void noinline |
1573 | verify_watcher (EV_P_ W w) |
1661 | verify_watcher (EV_P_ W w) |
1574 | { |
1662 | { |
… | |
… | |
1602 | verify_watcher (EV_A_ ws [cnt]); |
1690 | verify_watcher (EV_A_ ws [cnt]); |
1603 | } |
1691 | } |
1604 | } |
1692 | } |
1605 | #endif |
1693 | #endif |
1606 | |
1694 | |
|
|
1695 | #if EV_MINIMAL < 2 |
1607 | void |
1696 | void |
1608 | ev_loop_verify (EV_P) |
1697 | ev_loop_verify (EV_P) |
1609 | { |
1698 | { |
1610 | #if EV_VERIFY |
1699 | #if EV_VERIFY |
1611 | int i; |
1700 | int i; |
… | |
… | |
1664 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1753 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
1665 | for (signum = signalmax; signum--; ) if (signals [signum].gotsig) |
1754 | for (signum = signalmax; signum--; ) if (signals [signum].gotsig) |
1666 | # endif |
1755 | # endif |
1667 | #endif |
1756 | #endif |
1668 | } |
1757 | } |
1669 | |
1758 | #endif |
1670 | #endif /* multiplicity */ |
|
|
1671 | |
1759 | |
1672 | #if EV_MULTIPLICITY |
1760 | #if EV_MULTIPLICITY |
1673 | struct ev_loop * |
1761 | struct ev_loop * |
1674 | ev_default_loop_init (unsigned int flags) |
1762 | ev_default_loop_init (unsigned int flags) |
1675 | #else |
1763 | #else |
… | |
… | |
1736 | ev_invoke (EV_P_ void *w, int revents) |
1824 | ev_invoke (EV_P_ void *w, int revents) |
1737 | { |
1825 | { |
1738 | EV_CB_INVOKE ((W)w, revents); |
1826 | EV_CB_INVOKE ((W)w, revents); |
1739 | } |
1827 | } |
1740 | |
1828 | |
1741 | inline_speed void |
1829 | void noinline |
1742 | call_pending (EV_P) |
1830 | ev_invoke_pending (EV_P) |
1743 | { |
1831 | { |
1744 | int pri; |
1832 | int pri; |
1745 | |
1833 | |
1746 | for (pri = NUMPRI; pri--; ) |
1834 | for (pri = NUMPRI; pri--; ) |
1747 | while (pendingcnt [pri]) |
1835 | while (pendingcnt [pri]) |
1748 | { |
1836 | { |
1749 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1837 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1750 | |
1838 | |
1751 | if (expect_true (p->w)) |
|
|
1752 | { |
|
|
1753 | /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/ |
1839 | /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/ |
|
|
1840 | /* ^ this is no longer true, as pending_w could be here */ |
1754 | |
1841 | |
1755 | p->w->pending = 0; |
1842 | p->w->pending = 0; |
1756 | EV_CB_INVOKE (p->w, p->events); |
1843 | EV_CB_INVOKE (p->w, p->events); |
1757 | EV_FREQUENT_CHECK; |
1844 | EV_FREQUENT_CHECK; |
1758 | } |
|
|
1759 | } |
1845 | } |
1760 | } |
1846 | } |
1761 | |
1847 | |
1762 | #if EV_IDLE_ENABLE |
1848 | #if EV_IDLE_ENABLE |
|
|
1849 | /* make idle watchers pending. this handles the "call-idle */ |
|
|
1850 | /* only when higher priorities are idle" logic */ |
1763 | inline_size void |
1851 | inline_size void |
1764 | idle_reify (EV_P) |
1852 | idle_reify (EV_P) |
1765 | { |
1853 | { |
1766 | if (expect_false (idleall)) |
1854 | if (expect_false (idleall)) |
1767 | { |
1855 | { |
… | |
… | |
1780 | } |
1868 | } |
1781 | } |
1869 | } |
1782 | } |
1870 | } |
1783 | #endif |
1871 | #endif |
1784 | |
1872 | |
|
|
1873 | /* make timers pending */ |
1785 | inline_size void |
1874 | inline_size void |
1786 | timers_reify (EV_P) |
1875 | timers_reify (EV_P) |
1787 | { |
1876 | { |
1788 | EV_FREQUENT_CHECK; |
1877 | EV_FREQUENT_CHECK; |
1789 | |
1878 | |
… | |
… | |
1818 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
1907 | feed_reverse_done (EV_A_ EV_TIMEOUT); |
1819 | } |
1908 | } |
1820 | } |
1909 | } |
1821 | |
1910 | |
1822 | #if EV_PERIODIC_ENABLE |
1911 | #if EV_PERIODIC_ENABLE |
|
|
1912 | /* make periodics pending */ |
1823 | inline_size void |
1913 | inline_size void |
1824 | periodics_reify (EV_P) |
1914 | periodics_reify (EV_P) |
1825 | { |
1915 | { |
1826 | EV_FREQUENT_CHECK; |
1916 | EV_FREQUENT_CHECK; |
1827 | |
1917 | |
… | |
… | |
1874 | |
1964 | |
1875 | feed_reverse_done (EV_A_ EV_PERIODIC); |
1965 | feed_reverse_done (EV_A_ EV_PERIODIC); |
1876 | } |
1966 | } |
1877 | } |
1967 | } |
1878 | |
1968 | |
|
|
1969 | /* simply recalculate all periodics */ |
|
|
1970 | /* TODO: maybe ensure that at leats one event happens when jumping forward? */ |
1879 | static void noinline |
1971 | static void noinline |
1880 | periodics_reschedule (EV_P) |
1972 | periodics_reschedule (EV_P) |
1881 | { |
1973 | { |
1882 | int i; |
1974 | int i; |
1883 | |
1975 | |
… | |
… | |
1896 | |
1988 | |
1897 | reheap (periodics, periodiccnt); |
1989 | reheap (periodics, periodiccnt); |
1898 | } |
1990 | } |
1899 | #endif |
1991 | #endif |
1900 | |
1992 | |
|
|
1993 | /* adjust all timers by a given offset */ |
1901 | static void noinline |
1994 | static void noinline |
1902 | timers_reschedule (EV_P_ ev_tstamp adjust) |
1995 | timers_reschedule (EV_P_ ev_tstamp adjust) |
1903 | { |
1996 | { |
1904 | int i; |
1997 | int i; |
1905 | |
1998 | |
… | |
… | |
1909 | ANHE_w (*he)->at += adjust; |
2002 | ANHE_w (*he)->at += adjust; |
1910 | ANHE_at_cache (*he); |
2003 | ANHE_at_cache (*he); |
1911 | } |
2004 | } |
1912 | } |
2005 | } |
1913 | |
2006 | |
|
|
2007 | /* fetch new monotonic and realtime times from the kernel */ |
|
|
2008 | /* also detetc if there was a timejump, and act accordingly */ |
1914 | inline_speed void |
2009 | inline_speed void |
1915 | time_update (EV_P_ ev_tstamp max_block) |
2010 | time_update (EV_P_ ev_tstamp max_block) |
1916 | { |
2011 | { |
1917 | int i; |
|
|
1918 | |
|
|
1919 | #if EV_USE_MONOTONIC |
2012 | #if EV_USE_MONOTONIC |
1920 | if (expect_true (have_monotonic)) |
2013 | if (expect_true (have_monotonic)) |
1921 | { |
2014 | { |
|
|
2015 | int i; |
1922 | ev_tstamp odiff = rtmn_diff; |
2016 | ev_tstamp odiff = rtmn_diff; |
1923 | |
2017 | |
1924 | mn_now = get_clock (); |
2018 | mn_now = get_clock (); |
1925 | |
2019 | |
1926 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
2020 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
… | |
… | |
1976 | |
2070 | |
1977 | mn_now = ev_rt_now; |
2071 | mn_now = ev_rt_now; |
1978 | } |
2072 | } |
1979 | } |
2073 | } |
1980 | |
2074 | |
1981 | static int loop_done; |
|
|
1982 | |
|
|
1983 | void |
2075 | void |
1984 | ev_loop (EV_P_ int flags) |
2076 | ev_loop (EV_P_ int flags) |
1985 | { |
2077 | { |
|
|
2078 | #if EV_MINIMAL < 2 |
|
|
2079 | ++loop_depth; |
|
|
2080 | #endif |
|
|
2081 | |
1986 | loop_done = EVUNLOOP_CANCEL; |
2082 | loop_done = EVUNLOOP_CANCEL; |
1987 | |
2083 | |
1988 | call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ |
2084 | EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ |
1989 | |
2085 | |
1990 | do |
2086 | do |
1991 | { |
2087 | { |
1992 | #if EV_VERIFY >= 2 |
2088 | #if EV_VERIFY >= 2 |
1993 | ev_loop_verify (EV_A); |
2089 | ev_loop_verify (EV_A); |
… | |
… | |
2006 | /* we might have forked, so queue fork handlers */ |
2102 | /* we might have forked, so queue fork handlers */ |
2007 | if (expect_false (postfork)) |
2103 | if (expect_false (postfork)) |
2008 | if (forkcnt) |
2104 | if (forkcnt) |
2009 | { |
2105 | { |
2010 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2106 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
2011 | call_pending (EV_A); |
2107 | EV_INVOKE_PENDING; |
2012 | } |
2108 | } |
2013 | #endif |
2109 | #endif |
2014 | |
2110 | |
2015 | /* queue prepare watchers (and execute them) */ |
2111 | /* queue prepare watchers (and execute them) */ |
2016 | if (expect_false (preparecnt)) |
2112 | if (expect_false (preparecnt)) |
2017 | { |
2113 | { |
2018 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2114 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
2019 | call_pending (EV_A); |
2115 | EV_INVOKE_PENDING; |
2020 | } |
2116 | } |
2021 | |
2117 | |
2022 | /* we might have forked, so reify kernel state if necessary */ |
2118 | /* we might have forked, so reify kernel state if necessary */ |
2023 | if (expect_false (postfork)) |
2119 | if (expect_false (postfork)) |
2024 | loop_fork (EV_A); |
2120 | loop_fork (EV_A); |
… | |
… | |
2031 | ev_tstamp waittime = 0.; |
2127 | ev_tstamp waittime = 0.; |
2032 | ev_tstamp sleeptime = 0.; |
2128 | ev_tstamp sleeptime = 0.; |
2033 | |
2129 | |
2034 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2130 | if (expect_true (!(flags & EVLOOP_NONBLOCK || idleall || !activecnt))) |
2035 | { |
2131 | { |
|
|
2132 | /* remember old timestamp for io_blocktime calculation */ |
|
|
2133 | ev_tstamp prev_mn_now = mn_now; |
|
|
2134 | |
2036 | /* update time to cancel out callback processing overhead */ |
2135 | /* update time to cancel out callback processing overhead */ |
2037 | time_update (EV_A_ 1e100); |
2136 | time_update (EV_A_ 1e100); |
|
|
2137 | |
|
|
2138 | waittime = MAX_BLOCKTIME; |
2038 | |
2139 | |
2039 | if (timercnt) |
2140 | if (timercnt) |
2040 | { |
2141 | { |
2041 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
2142 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now + backend_fudge; |
2042 | if (waittime > to) waittime = to; |
2143 | if (waittime > to) waittime = to; |
… | |
… | |
2048 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2149 | ev_tstamp to = ANHE_at (periodics [HEAP0]) - ev_rt_now + backend_fudge; |
2049 | if (waittime > to) waittime = to; |
2150 | if (waittime > to) waittime = to; |
2050 | } |
2151 | } |
2051 | #endif |
2152 | #endif |
2052 | |
2153 | |
|
|
2154 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
2053 | if (expect_false (waittime < timeout_blocktime)) |
2155 | if (expect_false (waittime < timeout_blocktime)) |
2054 | waittime = timeout_blocktime; |
2156 | waittime = timeout_blocktime; |
2055 | |
2157 | |
2056 | sleeptime = waittime - backend_fudge; |
2158 | /* extra check because io_blocktime is commonly 0 */ |
2057 | |
|
|
2058 | if (expect_true (sleeptime > io_blocktime)) |
2159 | if (expect_false (io_blocktime)) |
2059 | sleeptime = io_blocktime; |
|
|
2060 | |
|
|
2061 | if (sleeptime) |
|
|
2062 | { |
2160 | { |
|
|
2161 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
|
|
2162 | |
|
|
2163 | if (sleeptime > waittime - backend_fudge) |
|
|
2164 | sleeptime = waittime - backend_fudge; |
|
|
2165 | |
|
|
2166 | if (expect_true (sleeptime > 0.)) |
|
|
2167 | { |
2063 | ev_sleep (sleeptime); |
2168 | ev_sleep (sleeptime); |
2064 | waittime -= sleeptime; |
2169 | waittime -= sleeptime; |
|
|
2170 | } |
2065 | } |
2171 | } |
2066 | } |
2172 | } |
2067 | |
2173 | |
|
|
2174 | #if EV_MINIMAL < 2 |
2068 | ++loop_count; |
2175 | ++loop_count; |
|
|
2176 | #endif |
2069 | backend_poll (EV_A_ waittime); |
2177 | backend_poll (EV_A_ waittime); |
2070 | |
2178 | |
2071 | /* update ev_rt_now, do magic */ |
2179 | /* update ev_rt_now, do magic */ |
2072 | time_update (EV_A_ waittime + sleeptime); |
2180 | time_update (EV_A_ waittime + sleeptime); |
2073 | } |
2181 | } |
… | |
… | |
2085 | |
2193 | |
2086 | /* queue check watchers, to be executed first */ |
2194 | /* queue check watchers, to be executed first */ |
2087 | if (expect_false (checkcnt)) |
2195 | if (expect_false (checkcnt)) |
2088 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2196 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
2089 | |
2197 | |
2090 | call_pending (EV_A); |
2198 | EV_INVOKE_PENDING; |
2091 | } |
2199 | } |
2092 | while (expect_true ( |
2200 | while (expect_true ( |
2093 | activecnt |
2201 | activecnt |
2094 | && !loop_done |
2202 | && !loop_done |
2095 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2203 | && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) |
2096 | )); |
2204 | )); |
2097 | |
2205 | |
2098 | if (loop_done == EVUNLOOP_ONE) |
2206 | if (loop_done == EVUNLOOP_ONE) |
2099 | loop_done = EVUNLOOP_CANCEL; |
2207 | loop_done = EVUNLOOP_CANCEL; |
|
|
2208 | |
|
|
2209 | #if EV_MINIMAL < 2 |
|
|
2210 | --loop_depth; |
|
|
2211 | #endif |
2100 | } |
2212 | } |
2101 | |
2213 | |
2102 | void |
2214 | void |
2103 | ev_unloop (EV_P_ int how) |
2215 | ev_unloop (EV_P_ int how) |
2104 | { |
2216 | { |
… | |
… | |
2135 | ev_tstamp mn_prev = mn_now; |
2247 | ev_tstamp mn_prev = mn_now; |
2136 | |
2248 | |
2137 | ev_now_update (EV_A); |
2249 | ev_now_update (EV_A); |
2138 | timers_reschedule (EV_A_ mn_now - mn_prev); |
2250 | timers_reschedule (EV_A_ mn_now - mn_prev); |
2139 | #if EV_PERIODIC_ENABLE |
2251 | #if EV_PERIODIC_ENABLE |
|
|
2252 | /* TODO: really do this? */ |
2140 | periodics_reschedule (EV_A); |
2253 | periodics_reschedule (EV_A); |
2141 | #endif |
2254 | #endif |
2142 | } |
2255 | } |
2143 | |
2256 | |
2144 | /*****************************************************************************/ |
2257 | /*****************************************************************************/ |
|
|
2258 | /* singly-linked list management, used when the expected list length is short */ |
2145 | |
2259 | |
2146 | inline_size void |
2260 | inline_size void |
2147 | wlist_add (WL *head, WL elem) |
2261 | wlist_add (WL *head, WL elem) |
2148 | { |
2262 | { |
2149 | elem->next = *head; |
2263 | elem->next = *head; |
… | |
… | |
2163 | |
2277 | |
2164 | head = &(*head)->next; |
2278 | head = &(*head)->next; |
2165 | } |
2279 | } |
2166 | } |
2280 | } |
2167 | |
2281 | |
|
|
2282 | /* internal, faster, version of ev_clear_pending */ |
2168 | inline_speed void |
2283 | inline_speed void |
2169 | clear_pending (EV_P_ W w) |
2284 | clear_pending (EV_P_ W w) |
2170 | { |
2285 | { |
2171 | if (w->pending) |
2286 | if (w->pending) |
2172 | { |
2287 | { |
2173 | pendings [ABSPRI (w)][w->pending - 1].w = 0; |
2288 | pendings [ABSPRI (w)][w->pending - 1].w = (W)&pending_w; |
2174 | w->pending = 0; |
2289 | w->pending = 0; |
2175 | } |
2290 | } |
2176 | } |
2291 | } |
2177 | |
2292 | |
2178 | int |
2293 | int |
… | |
… | |
2182 | int pending = w_->pending; |
2297 | int pending = w_->pending; |
2183 | |
2298 | |
2184 | if (expect_true (pending)) |
2299 | if (expect_true (pending)) |
2185 | { |
2300 | { |
2186 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
2301 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
|
|
2302 | p->w = (W)&pending_w; |
2187 | w_->pending = 0; |
2303 | w_->pending = 0; |
2188 | p->w = 0; |
|
|
2189 | return p->events; |
2304 | return p->events; |
2190 | } |
2305 | } |
2191 | else |
2306 | else |
2192 | return 0; |
2307 | return 0; |
2193 | } |
2308 | } |
2194 | |
2309 | |
2195 | inline_size void |
2310 | inline_size void |
2196 | pri_adjust (EV_P_ W w) |
2311 | pri_adjust (EV_P_ W w) |
2197 | { |
2312 | { |
2198 | int pri = w->priority; |
2313 | int pri = ev_priority (w); |
2199 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
2314 | pri = pri < EV_MINPRI ? EV_MINPRI : pri; |
2200 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
2315 | pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; |
2201 | w->priority = pri; |
2316 | ev_set_priority (w, pri); |
2202 | } |
2317 | } |
2203 | |
2318 | |
2204 | inline_speed void |
2319 | inline_speed void |
2205 | ev_start (EV_P_ W w, int active) |
2320 | ev_start (EV_P_ W w, int active) |
2206 | { |
2321 | { |
… | |
… | |
3199 | } |
3314 | } |
3200 | } |
3315 | } |
3201 | |
3316 | |
3202 | /*****************************************************************************/ |
3317 | /*****************************************************************************/ |
3203 | |
3318 | |
3204 | #if 0 |
3319 | #if EV_WALK_ENABLE |
3205 | void |
3320 | void |
3206 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
3321 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
3207 | { |
3322 | { |
3208 | int i, j; |
3323 | int i, j; |
3209 | ev_watcher_list *wl, *wn; |
3324 | ev_watcher_list *wl, *wn; |
… | |
… | |
3225 | #if EV_USE_INOTIFY |
3340 | #if EV_USE_INOTIFY |
3226 | if (ev_cb ((ev_io *)wl) == infy_cb) |
3341 | if (ev_cb ((ev_io *)wl) == infy_cb) |
3227 | ; |
3342 | ; |
3228 | else |
3343 | else |
3229 | #endif |
3344 | #endif |
3230 | if ((ev_io *)wl != &pipeev) |
3345 | if ((ev_io *)wl != &pipe_w) |
3231 | if (types & EV_IO) |
3346 | if (types & EV_IO) |
3232 | cb (EV_A_ EV_IO, wl); |
3347 | cb (EV_A_ EV_IO, wl); |
3233 | |
3348 | |
3234 | wl = wn; |
3349 | wl = wn; |
3235 | } |
3350 | } |