ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.280 by root, Sat Mar 14 04:45:39 2009 UTC vs.
Revision 1.290 by root, Mon Jun 29 04:41:34 2009 UTC

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 */
483typedef struct 491typedef 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 */
498typedef struct 507typedef 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 */
506typedef struct 515typedef 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)
570 struct timeval tv; 581 struct timeval tv;
571 gettimeofday (&tv, 0); 582 gettimeofday (&tv, 0);
572 return tv.tv_sec + tv.tv_usec * 1e-6; 583 return tv.tv_sec + tv.tv_usec * 1e-6;
573} 584}
574 585
575ev_tstamp inline_size 586inline_size ev_tstamp
576get_clock (void) 587get_clock (void)
577{ 588{
578#if EV_USE_MONOTONIC 589#if EV_USE_MONOTONIC
579 if (expect_true (have_monotonic)) 590 if (expect_true (have_monotonic))
580 { 591 {
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
630int inline_size 641/* find a suitable new size for the given array, */
642/* hopefully by rounding to a ncie-to-malloc size */
643inline_size int
631array_nextsize (int elem, int cur, int cnt) 644array_nextsize (int elem, int cur, int cnt)
632{ 645{
633 int ncur = cur + 1; 646 int ncur = cur + 1;
634 647
635 do 648 do
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 */
699static void noinline
700pendingcb (EV_P_ ev_prepare *w, int revents)
701{
702}
703
685void noinline 704void noinline
686ev_feed_event (EV_P_ void *w, int revents) 705ev_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_);
697 pendings [pri][w_->pending - 1].w = w_; 716 pendings [pri][w_->pending - 1].w = w_;
698 pendings [pri][w_->pending - 1].events = revents; 717 pendings [pri][w_->pending - 1].events = revents;
699 } 718 }
700} 719}
701 720
702void inline_speed 721inline_speed void
722feed_reverse (EV_P_ W w)
723{
724 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2);
725 rfeeds [rfeedcnt++] = w;
726}
727
728inline_size void
729feed_reverse_done (EV_P_ int revents)
730{
731 do
732 ev_feed_event (EV_A_ rfeeds [--rfeedcnt], revents);
733 while (rfeedcnt);
734}
735
736inline_speed void
703queue_events (EV_P_ W *events, int eventcnt, int type) 737queue_events (EV_P_ W *events, int eventcnt, int type)
704{ 738{
705 int i; 739 int i;
706 740
707 for (i = 0; i < eventcnt; ++i) 741 for (i = 0; i < eventcnt; ++i)
708 ev_feed_event (EV_A_ events [i], type); 742 ev_feed_event (EV_A_ events [i], type);
709} 743}
710 744
711/*****************************************************************************/ 745/*****************************************************************************/
712 746
713void inline_speed 747inline_speed void
714fd_event (EV_P_ int fd, int revents) 748fd_event (EV_P_ int fd, int revents)
715{ 749{
716 ANFD *anfd = anfds + fd; 750 ANFD *anfd = anfds + fd;
717 ev_io *w; 751 ev_io *w;
718 752
730{ 764{
731 if (fd >= 0 && fd < anfdmax) 765 if (fd >= 0 && fd < anfdmax)
732 fd_event (EV_A_ fd, revents); 766 fd_event (EV_A_ fd, revents);
733} 767}
734 768
735void inline_size 769/* make sure the external fd watch events are in-sync */
770/* with the kernel/libev internal state */
771inline_size void
736fd_reify (EV_P) 772fd_reify (EV_P)
737{ 773{
738 int i; 774 int i;
739 775
740 for (i = 0; i < fdchangecnt; ++i) 776 for (i = 0; i < fdchangecnt; ++i)
766 unsigned char o_reify = anfd->reify; 802 unsigned char o_reify = anfd->reify;
767 803
768 anfd->reify = 0; 804 anfd->reify = 0;
769 anfd->events = events; 805 anfd->events = events;
770 806
771 if (o_events != events || o_reify & EV_IOFDSET) 807 if (o_events != events || o_reify & EV__IOFDSET)
772 backend_modify (EV_A_ fd, o_events, events); 808 backend_modify (EV_A_ fd, o_events, events);
773 } 809 }
774 } 810 }
775 811
776 fdchangecnt = 0; 812 fdchangecnt = 0;
777} 813}
778 814
779void inline_size 815/* something about the given fd changed */
816inline_size void
780fd_change (EV_P_ int fd, int flags) 817fd_change (EV_P_ int fd, int flags)
781{ 818{
782 unsigned char reify = anfds [fd].reify; 819 unsigned char reify = anfds [fd].reify;
783 anfds [fd].reify |= flags; 820 anfds [fd].reify |= flags;
784 821
788 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 825 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2);
789 fdchanges [fdchangecnt - 1] = fd; 826 fdchanges [fdchangecnt - 1] = fd;
790 } 827 }
791} 828}
792 829
793void inline_speed 830/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
831inline_speed void
794fd_kill (EV_P_ int fd) 832fd_kill (EV_P_ int fd)
795{ 833{
796 ev_io *w; 834 ev_io *w;
797 835
798 while ((w = (ev_io *)anfds [fd].head)) 836 while ((w = (ev_io *)anfds [fd].head))
800 ev_io_stop (EV_A_ w); 838 ev_io_stop (EV_A_ w);
801 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);
802 } 840 }
803} 841}
804 842
805int inline_size 843/* check whether the given fd is atcually valid, for error recovery */
844inline_size int
806fd_valid (int fd) 845fd_valid (int fd)
807{ 846{
808#ifdef _WIN32 847#ifdef _WIN32
809 return _get_osfhandle (fd) != -1; 848 return _get_osfhandle (fd) != -1;
810#else 849#else
847 for (fd = 0; fd < anfdmax; ++fd) 886 for (fd = 0; fd < anfdmax; ++fd)
848 if (anfds [fd].events) 887 if (anfds [fd].events)
849 { 888 {
850 anfds [fd].events = 0; 889 anfds [fd].events = 0;
851 anfds [fd].emask = 0; 890 anfds [fd].emask = 0;
852 fd_change (EV_A_ fd, EV_IOFDSET | 1); 891 fd_change (EV_A_ fd, EV__IOFDSET | 1);
853 } 892 }
854} 893}
855 894
856/*****************************************************************************/ 895/*****************************************************************************/
857 896
873#define HEAP0 (DHEAP - 1) /* index of first element in heap */ 912#define HEAP0 (DHEAP - 1) /* index of first element in heap */
874#define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0) 913#define HPARENT(k) ((((k) - HEAP0 - 1) / DHEAP) + HEAP0)
875#define UPHEAP_DONE(p,k) ((p) == (k)) 914#define UPHEAP_DONE(p,k) ((p) == (k))
876 915
877/* away from the root */ 916/* away from the root */
878void inline_speed 917inline_speed void
879downheap (ANHE *heap, int N, int k) 918downheap (ANHE *heap, int N, int k)
880{ 919{
881 ANHE he = heap [k]; 920 ANHE he = heap [k];
882 ANHE *E = heap + N + HEAP0; 921 ANHE *E = heap + N + HEAP0;
883 922
923#define HEAP0 1 962#define HEAP0 1
924#define HPARENT(k) ((k) >> 1) 963#define HPARENT(k) ((k) >> 1)
925#define UPHEAP_DONE(p,k) (!(p)) 964#define UPHEAP_DONE(p,k) (!(p))
926 965
927/* away from the root */ 966/* away from the root */
928void inline_speed 967inline_speed void
929downheap (ANHE *heap, int N, int k) 968downheap (ANHE *heap, int N, int k)
930{ 969{
931 ANHE he = heap [k]; 970 ANHE he = heap [k];
932 971
933 for (;;) 972 for (;;)
953 ev_active (ANHE_w (he)) = k; 992 ev_active (ANHE_w (he)) = k;
954} 993}
955#endif 994#endif
956 995
957/* towards the root */ 996/* towards the root */
958void inline_speed 997inline_speed void
959upheap (ANHE *heap, int k) 998upheap (ANHE *heap, int k)
960{ 999{
961 ANHE he = heap [k]; 1000 ANHE he = heap [k];
962 1001
963 for (;;) 1002 for (;;)
974 1013
975 heap [k] = he; 1014 heap [k] = he;
976 ev_active (ANHE_w (he)) = k; 1015 ev_active (ANHE_w (he)) = k;
977} 1016}
978 1017
979void inline_size 1018/* move an element suitably so it is in a correct place */
1019inline_size void
980adjustheap (ANHE *heap, int N, int k) 1020adjustheap (ANHE *heap, int N, int k)
981{ 1021{
982 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]))
983 upheap (heap, k); 1023 upheap (heap, k);
984 else 1024 else
985 downheap (heap, N, k); 1025 downheap (heap, N, k);
986} 1026}
987 1027
988/* rebuild the heap: this function is used only once and executed rarely */ 1028/* rebuild the heap: this function is used only once and executed rarely */
989void inline_size 1029inline_size void
990reheap (ANHE *heap, int N) 1030reheap (ANHE *heap, int N)
991{ 1031{
992 int i; 1032 int i;
993 1033
994 /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */ 1034 /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */
997 upheap (heap, i + HEAP0); 1037 upheap (heap, i + HEAP0);
998} 1038}
999 1039
1000/*****************************************************************************/ 1040/*****************************************************************************/
1001 1041
1042/* associate signal watchers to a signal signal */
1002typedef struct 1043typedef struct
1003{ 1044{
1004 WL head; 1045 WL head;
1005 EV_ATOMIC_T gotsig; 1046 EV_ATOMIC_T gotsig;
1006} ANSIG; 1047} ANSIG;
1010 1051
1011static EV_ATOMIC_T gotsig; 1052static EV_ATOMIC_T gotsig;
1012 1053
1013/*****************************************************************************/ 1054/*****************************************************************************/
1014 1055
1015void inline_speed 1056/* used to prepare libev internal fd's */
1057/* this is not fork-safe */
1058inline_speed void
1016fd_intern (int fd) 1059fd_intern (int fd)
1017{ 1060{
1018#ifdef _WIN32 1061#ifdef _WIN32
1019 unsigned long arg = 1; 1062 unsigned long arg = 1;
1020 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 1063 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
1025} 1068}
1026 1069
1027static void noinline 1070static void noinline
1028evpipe_init (EV_P) 1071evpipe_init (EV_P)
1029{ 1072{
1030 if (!ev_is_active (&pipeev)) 1073 if (!ev_is_active (&pipe_w))
1031 { 1074 {
1032#if EV_USE_EVENTFD 1075#if EV_USE_EVENTFD
1033 if ((evfd = eventfd (0, 0)) >= 0) 1076 if ((evfd = eventfd (0, 0)) >= 0)
1034 { 1077 {
1035 evpipe [0] = -1; 1078 evpipe [0] = -1;
1036 fd_intern (evfd); 1079 fd_intern (evfd);
1037 ev_io_set (&pipeev, evfd, EV_READ); 1080 ev_io_set (&pipe_w, evfd, EV_READ);
1038 } 1081 }
1039 else 1082 else
1040#endif 1083#endif
1041 { 1084 {
1042 while (pipe (evpipe)) 1085 while (pipe (evpipe))
1043 ev_syserr ("(libev) error creating signal/async pipe"); 1086 ev_syserr ("(libev) error creating signal/async pipe");
1044 1087
1045 fd_intern (evpipe [0]); 1088 fd_intern (evpipe [0]);
1046 fd_intern (evpipe [1]); 1089 fd_intern (evpipe [1]);
1047 ev_io_set (&pipeev, evpipe [0], EV_READ); 1090 ev_io_set (&pipe_w, evpipe [0], EV_READ);
1048 } 1091 }
1049 1092
1050 ev_io_start (EV_A_ &pipeev); 1093 ev_io_start (EV_A_ &pipe_w);
1051 ev_unref (EV_A); /* watcher should not keep loop alive */ 1094 ev_unref (EV_A); /* watcher should not keep loop alive */
1052 } 1095 }
1053} 1096}
1054 1097
1055void inline_size 1098inline_size void
1056evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1099evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1057{ 1100{
1058 if (!*flag) 1101 if (!*flag)
1059 { 1102 {
1060 int old_errno = errno; /* save errno because write might clobber it */ 1103 int old_errno = errno; /* save errno because write might clobber it */
1073 1116
1074 errno = old_errno; 1117 errno = old_errno;
1075 } 1118 }
1076} 1119}
1077 1120
1121/* called whenever the libev signal pipe */
1122/* got some events (signal, async) */
1078static void 1123static void
1079pipecb (EV_P_ ev_io *iow, int revents) 1124pipecb (EV_P_ ev_io *iow, int revents)
1080{ 1125{
1081#if EV_USE_EVENTFD 1126#if EV_USE_EVENTFD
1082 if (evfd >= 0) 1127 if (evfd >= 0)
1164 1209
1165#ifndef WIFCONTINUED 1210#ifndef WIFCONTINUED
1166# define WIFCONTINUED(status) 0 1211# define WIFCONTINUED(status) 0
1167#endif 1212#endif
1168 1213
1169void inline_speed 1214/* handle a single child status event */
1215inline_speed void
1170child_reap (EV_P_ int chain, int pid, int status) 1216child_reap (EV_P_ int chain, int pid, int status)
1171{ 1217{
1172 ev_child *w; 1218 ev_child *w;
1173 int traced = WIFSTOPPED (status) || WIFCONTINUED (status); 1219 int traced = WIFSTOPPED (status) || WIFCONTINUED (status);
1174 1220
1187 1233
1188#ifndef WCONTINUED 1234#ifndef WCONTINUED
1189# define WCONTINUED 0 1235# define WCONTINUED 0
1190#endif 1236#endif
1191 1237
1238/* called on sigchld etc., calls waitpid */
1192static void 1239static void
1193childcb (EV_P_ ev_signal *sw, int revents) 1240childcb (EV_P_ ev_signal *sw, int revents)
1194{ 1241{
1195 int pid, status; 1242 int pid, status;
1196 1243
1321ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 1368ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval)
1322{ 1369{
1323 timeout_blocktime = interval; 1370 timeout_blocktime = interval;
1324} 1371}
1325 1372
1373/* initialise a loop structure, must be zero-initialised */
1326static void noinline 1374static void noinline
1327loop_init (EV_P_ unsigned int flags) 1375loop_init (EV_P_ unsigned int flags)
1328{ 1376{
1329 if (!backend) 1377 if (!backend)
1330 { 1378 {
1390#endif 1438#endif
1391#if EV_USE_SELECT 1439#if EV_USE_SELECT
1392 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 1440 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags);
1393#endif 1441#endif
1394 1442
1443 ev_prepare_init (&pending_w, pendingcb);
1444
1395 ev_init (&pipeev, pipecb); 1445 ev_init (&pipe_w, pipecb);
1396 ev_set_priority (&pipeev, EV_MAXPRI); 1446 ev_set_priority (&pipe_w, EV_MAXPRI);
1397 } 1447 }
1398} 1448}
1399 1449
1450/* free up a loop structure */
1400static void noinline 1451static void noinline
1401loop_destroy (EV_P) 1452loop_destroy (EV_P)
1402{ 1453{
1403 int i; 1454 int i;
1404 1455
1405 if (ev_is_active (&pipeev)) 1456 if (ev_is_active (&pipe_w))
1406 { 1457 {
1407 ev_ref (EV_A); /* signal watcher */ 1458 ev_ref (EV_A); /* signal watcher */
1408 ev_io_stop (EV_A_ &pipeev); 1459 ev_io_stop (EV_A_ &pipe_w);
1409 1460
1410#if EV_USE_EVENTFD 1461#if EV_USE_EVENTFD
1411 if (evfd >= 0) 1462 if (evfd >= 0)
1412 close (evfd); 1463 close (evfd);
1413#endif 1464#endif
1452 } 1503 }
1453 1504
1454 ev_free (anfds); anfdmax = 0; 1505 ev_free (anfds); anfdmax = 0;
1455 1506
1456 /* have to use the microsoft-never-gets-it-right macro */ 1507 /* have to use the microsoft-never-gets-it-right macro */
1508 array_free (rfeed, EMPTY);
1457 array_free (fdchange, EMPTY); 1509 array_free (fdchange, EMPTY);
1458 array_free (timer, EMPTY); 1510 array_free (timer, EMPTY);
1459#if EV_PERIODIC_ENABLE 1511#if EV_PERIODIC_ENABLE
1460 array_free (periodic, EMPTY); 1512 array_free (periodic, EMPTY);
1461#endif 1513#endif
1470 1522
1471 backend = 0; 1523 backend = 0;
1472} 1524}
1473 1525
1474#if EV_USE_INOTIFY 1526#if EV_USE_INOTIFY
1475void inline_size infy_fork (EV_P); 1527inline_size void infy_fork (EV_P);
1476#endif 1528#endif
1477 1529
1478void inline_size 1530inline_size void
1479loop_fork (EV_P) 1531loop_fork (EV_P)
1480{ 1532{
1481#if EV_USE_PORT 1533#if EV_USE_PORT
1482 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 1534 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
1483#endif 1535#endif
1489#endif 1541#endif
1490#if EV_USE_INOTIFY 1542#if EV_USE_INOTIFY
1491 infy_fork (EV_A); 1543 infy_fork (EV_A);
1492#endif 1544#endif
1493 1545
1494 if (ev_is_active (&pipeev)) 1546 if (ev_is_active (&pipe_w))
1495 { 1547 {
1496 /* this "locks" the handlers against writing to the pipe */ 1548 /* this "locks" the handlers against writing to the pipe */
1497 /* while we modify the fd vars */ 1549 /* while we modify the fd vars */
1498 gotsig = 1; 1550 gotsig = 1;
1499#if EV_ASYNC_ENABLE 1551#if EV_ASYNC_ENABLE
1500 gotasync = 1; 1552 gotasync = 1;
1501#endif 1553#endif
1502 1554
1503 ev_ref (EV_A); 1555 ev_ref (EV_A);
1504 ev_io_stop (EV_A_ &pipeev); 1556 ev_io_stop (EV_A_ &pipe_w);
1505 1557
1506#if EV_USE_EVENTFD 1558#if EV_USE_EVENTFD
1507 if (evfd >= 0) 1559 if (evfd >= 0)
1508 close (evfd); 1560 close (evfd);
1509#endif 1561#endif
1514 close (evpipe [1]); 1566 close (evpipe [1]);
1515 } 1567 }
1516 1568
1517 evpipe_init (EV_A); 1569 evpipe_init (EV_A);
1518 /* now iterate over everything, in case we missed something */ 1570 /* now iterate over everything, in case we missed something */
1519 pipecb (EV_A_ &pipeev, EV_READ); 1571 pipecb (EV_A_ &pipe_w, EV_READ);
1520 } 1572 }
1521 1573
1522 postfork = 0; 1574 postfork = 0;
1523} 1575}
1524 1576
1720ev_invoke (EV_P_ void *w, int revents) 1772ev_invoke (EV_P_ void *w, int revents)
1721{ 1773{
1722 EV_CB_INVOKE ((W)w, revents); 1774 EV_CB_INVOKE ((W)w, revents);
1723} 1775}
1724 1776
1725void inline_speed 1777inline_speed void
1726call_pending (EV_P) 1778call_pending (EV_P)
1727{ 1779{
1728 int pri; 1780 int pri;
1729 1781
1730 for (pri = NUMPRI; pri--; ) 1782 for (pri = NUMPRI; pri--; )
1731 while (pendingcnt [pri]) 1783 while (pendingcnt [pri])
1732 { 1784 {
1733 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 1785 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
1734 1786
1735 if (expect_true (p->w))
1736 {
1737 /*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 */
1738 1789
1739 p->w->pending = 0; 1790 p->w->pending = 0;
1740 EV_CB_INVOKE (p->w, p->events); 1791 EV_CB_INVOKE (p->w, p->events);
1741 EV_FREQUENT_CHECK; 1792 EV_FREQUENT_CHECK;
1742 }
1743 } 1793 }
1744} 1794}
1745 1795
1746#if EV_IDLE_ENABLE 1796#if EV_IDLE_ENABLE
1747void inline_size 1797/* make idle watchers pending. this handles the "call-idle */
1798/* only when higher priorities are idle" logic */
1799inline_size void
1748idle_reify (EV_P) 1800idle_reify (EV_P)
1749{ 1801{
1750 if (expect_false (idleall)) 1802 if (expect_false (idleall))
1751 { 1803 {
1752 int pri; 1804 int pri;
1764 } 1816 }
1765 } 1817 }
1766} 1818}
1767#endif 1819#endif
1768 1820
1769void inline_size 1821/* make timers pending */
1822inline_size void
1770timers_reify (EV_P) 1823timers_reify (EV_P)
1771{ 1824{
1772 EV_FREQUENT_CHECK; 1825 EV_FREQUENT_CHECK;
1773 1826
1774 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now) 1827 if (timercnt && ANHE_at (timers [HEAP0]) < mn_now)
1775 { 1828 {
1776 ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]); 1829 do
1777
1778 /*assert (("libev: inactive timer on timer heap detected", ev_is_active (w)));*/
1779
1780 /* first reschedule or stop timer */
1781 if (w->repeat)
1782 { 1830 {
1831 ev_timer *w = (ev_timer *)ANHE_w (timers [HEAP0]);
1832
1833 /*assert (("libev: inactive timer on timer heap detected", ev_is_active (w)));*/
1834
1835 /* first reschedule or stop timer */
1836 if (w->repeat)
1837 {
1783 ev_at (w) += w->repeat; 1838 ev_at (w) += w->repeat;
1784 if (ev_at (w) < mn_now) 1839 if (ev_at (w) < mn_now)
1785 ev_at (w) = mn_now; 1840 ev_at (w) = mn_now;
1786 1841
1787 assert (("libev: negative ev_timer repeat value found while processing timers", w->repeat > 0.)); 1842 assert (("libev: negative ev_timer repeat value found while processing timers", w->repeat > 0.));
1788 1843
1789 ANHE_at_cache (timers [HEAP0]); 1844 ANHE_at_cache (timers [HEAP0]);
1790 downheap (timers, timercnt, HEAP0); 1845 downheap (timers, timercnt, HEAP0);
1846 }
1847 else
1848 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1849
1850 EV_FREQUENT_CHECK;
1851 feed_reverse (EV_A_ (W)w);
1791 } 1852 }
1792 else 1853 while (timercnt && ANHE_at (timers [HEAP0]) < mn_now);
1793 ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */
1794 1854
1795 EV_FREQUENT_CHECK;
1796 ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); 1855 feed_reverse_done (EV_A_ EV_TIMEOUT);
1797 } 1856 }
1798} 1857}
1799 1858
1800#if EV_PERIODIC_ENABLE 1859#if EV_PERIODIC_ENABLE
1801void inline_size 1860/* make periodics pending */
1861inline_size void
1802periodics_reify (EV_P) 1862periodics_reify (EV_P)
1803{ 1863{
1804 EV_FREQUENT_CHECK; 1864 EV_FREQUENT_CHECK;
1805 1865
1806 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) 1866 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now)
1807 { 1867 {
1808 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); 1868 int feed_count = 0;
1809 1869
1810 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ 1870 do
1811
1812 /* first reschedule or stop timer */
1813 if (w->reschedule_cb)
1814 { 1871 {
1872 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]);
1873
1874 /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/
1875
1876 /* first reschedule or stop timer */
1877 if (w->reschedule_cb)
1878 {
1815 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 1879 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
1816 1880
1817 assert (("libev: ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); 1881 assert (("libev: ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now));
1818 1882
1819 ANHE_at_cache (periodics [HEAP0]); 1883 ANHE_at_cache (periodics [HEAP0]);
1820 downheap (periodics, periodiccnt, HEAP0); 1884 downheap (periodics, periodiccnt, HEAP0);
1885 }
1886 else if (w->interval)
1887 {
1888 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1889 /* if next trigger time is not sufficiently in the future, put it there */
1890 /* this might happen because of floating point inexactness */
1891 if (ev_at (w) - ev_rt_now < TIME_EPSILON)
1892 {
1893 ev_at (w) += w->interval;
1894
1895 /* if interval is unreasonably low we might still have a time in the past */
1896 /* so correct this. this will make the periodic very inexact, but the user */
1897 /* has effectively asked to get triggered more often than possible */
1898 if (ev_at (w) < ev_rt_now)
1899 ev_at (w) = ev_rt_now;
1900 }
1901
1902 ANHE_at_cache (periodics [HEAP0]);
1903 downheap (periodics, periodiccnt, HEAP0);
1904 }
1905 else
1906 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1907
1908 EV_FREQUENT_CHECK;
1909 feed_reverse (EV_A_ (W)w);
1821 } 1910 }
1822 else if (w->interval) 1911 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now);
1823 {
1824 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1825 /* if next trigger time is not sufficiently in the future, put it there */
1826 /* this might happen because of floating point inexactness */
1827 if (ev_at (w) - ev_rt_now < TIME_EPSILON)
1828 {
1829 ev_at (w) += w->interval;
1830 1912
1831 /* if interval is unreasonably low we might still have a time in the past */
1832 /* so correct this. this will make the periodic very inexact, but the user */
1833 /* has effectively asked to get triggered more often than possible */
1834 if (ev_at (w) < ev_rt_now)
1835 ev_at (w) = ev_rt_now;
1836 }
1837
1838 ANHE_at_cache (periodics [HEAP0]);
1839 downheap (periodics, periodiccnt, HEAP0);
1840 }
1841 else
1842 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1843
1844 EV_FREQUENT_CHECK;
1845 ev_feed_event (EV_A_ (W)w, EV_PERIODIC); 1913 feed_reverse_done (EV_A_ EV_PERIODIC);
1846 } 1914 }
1847} 1915}
1848 1916
1917/* simply recalculate all periodics */
1918/* TODO: maybe ensure that at leats one event happens when jumping forward? */
1849static void noinline 1919static void noinline
1850periodics_reschedule (EV_P) 1920periodics_reschedule (EV_P)
1851{ 1921{
1852 int i; 1922 int i;
1853 1923
1866 1936
1867 reheap (periodics, periodiccnt); 1937 reheap (periodics, periodiccnt);
1868} 1938}
1869#endif 1939#endif
1870 1940
1871void inline_speed 1941/* adjust all timers by a given offset */
1942static void noinline
1943timers_reschedule (EV_P_ ev_tstamp adjust)
1944{
1945 int i;
1946
1947 for (i = 0; i < timercnt; ++i)
1948 {
1949 ANHE *he = timers + i + HEAP0;
1950 ANHE_w (*he)->at += adjust;
1951 ANHE_at_cache (*he);
1952 }
1953}
1954
1955/* fetch new monotonic and realtime times from the kernel */
1956/* also detetc if there was a timejump, and act accordingly */
1957inline_speed void
1872time_update (EV_P_ ev_tstamp max_block) 1958time_update (EV_P_ ev_tstamp max_block)
1873{ 1959{
1874 int i;
1875
1876#if EV_USE_MONOTONIC 1960#if EV_USE_MONOTONIC
1877 if (expect_true (have_monotonic)) 1961 if (expect_true (have_monotonic))
1878 { 1962 {
1963 int i;
1879 ev_tstamp odiff = rtmn_diff; 1964 ev_tstamp odiff = rtmn_diff;
1880 1965
1881 mn_now = get_clock (); 1966 mn_now = get_clock ();
1882 1967
1883 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ 1968 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */
1909 ev_rt_now = ev_time (); 1994 ev_rt_now = ev_time ();
1910 mn_now = get_clock (); 1995 mn_now = get_clock ();
1911 now_floor = mn_now; 1996 now_floor = mn_now;
1912 } 1997 }
1913 1998
1999 /* no timer adjustment, as the monotonic clock doesn't jump */
2000 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
1914# if EV_PERIODIC_ENABLE 2001# if EV_PERIODIC_ENABLE
1915 periodics_reschedule (EV_A); 2002 periodics_reschedule (EV_A);
1916# endif 2003# endif
1917 /* no timer adjustment, as the monotonic clock doesn't jump */
1918 /* timers_reschedule (EV_A_ rtmn_diff - odiff) */
1919 } 2004 }
1920 else 2005 else
1921#endif 2006#endif
1922 { 2007 {
1923 ev_rt_now = ev_time (); 2008 ev_rt_now = ev_time ();
1924 2009
1925 if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) 2010 if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP))
1926 { 2011 {
2012 /* adjust timers. this is easy, as the offset is the same for all of them */
2013 timers_reschedule (EV_A_ ev_rt_now - mn_now);
1927#if EV_PERIODIC_ENABLE 2014#if EV_PERIODIC_ENABLE
1928 periodics_reschedule (EV_A); 2015 periodics_reschedule (EV_A);
1929#endif 2016#endif
1930 /* adjust timers. this is easy, as the offset is the same for all of them */
1931 for (i = 0; i < timercnt; ++i)
1932 {
1933 ANHE *he = timers + i + HEAP0;
1934 ANHE_w (*he)->at += ev_rt_now - mn_now;
1935 ANHE_at_cache (*he);
1936 }
1937 } 2017 }
1938 2018
1939 mn_now = ev_rt_now; 2019 mn_now = ev_rt_now;
1940 } 2020 }
1941}
1942
1943void
1944ev_ref (EV_P)
1945{
1946 ++activecnt;
1947}
1948
1949void
1950ev_unref (EV_P)
1951{
1952 --activecnt;
1953}
1954
1955void
1956ev_now_update (EV_P)
1957{
1958 time_update (EV_A_ 1e100);
1959} 2021}
1960 2022
1961static int loop_done; 2023static int loop_done;
1962 2024
1963void 2025void
1997 { 2059 {
1998 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 2060 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1999 call_pending (EV_A); 2061 call_pending (EV_A);
2000 } 2062 }
2001 2063
2002 if (expect_false (!activecnt))
2003 break;
2004
2005 /* we might have forked, so reify kernel state if necessary */ 2064 /* we might have forked, so reify kernel state if necessary */
2006 if (expect_false (postfork)) 2065 if (expect_false (postfork))
2007 loop_fork (EV_A); 2066 loop_fork (EV_A);
2008 2067
2009 /* update fd-related kernel structures */ 2068 /* update fd-related kernel structures */
2088ev_unloop (EV_P_ int how) 2147ev_unloop (EV_P_ int how)
2089{ 2148{
2090 loop_done = how; 2149 loop_done = how;
2091} 2150}
2092 2151
2152void
2153ev_ref (EV_P)
2154{
2155 ++activecnt;
2156}
2157
2158void
2159ev_unref (EV_P)
2160{
2161 --activecnt;
2162}
2163
2164void
2165ev_now_update (EV_P)
2166{
2167 time_update (EV_A_ 1e100);
2168}
2169
2170void
2171ev_suspend (EV_P)
2172{
2173 ev_now_update (EV_A);
2174}
2175
2176void
2177ev_resume (EV_P)
2178{
2179 ev_tstamp mn_prev = mn_now;
2180
2181 ev_now_update (EV_A);
2182 timers_reschedule (EV_A_ mn_now - mn_prev);
2183#if EV_PERIODIC_ENABLE
2184 /* TODO: really do this? */
2185 periodics_reschedule (EV_A);
2186#endif
2187}
2188
2093/*****************************************************************************/ 2189/*****************************************************************************/
2190/* singly-linked list management, used when the expected list length is short */
2094 2191
2095void inline_size 2192inline_size void
2096wlist_add (WL *head, WL elem) 2193wlist_add (WL *head, WL elem)
2097{ 2194{
2098 elem->next = *head; 2195 elem->next = *head;
2099 *head = elem; 2196 *head = elem;
2100} 2197}
2101 2198
2102void inline_size 2199inline_size void
2103wlist_del (WL *head, WL elem) 2200wlist_del (WL *head, WL elem)
2104{ 2201{
2105 while (*head) 2202 while (*head)
2106 { 2203 {
2107 if (*head == elem) 2204 if (*head == elem)
2112 2209
2113 head = &(*head)->next; 2210 head = &(*head)->next;
2114 } 2211 }
2115} 2212}
2116 2213
2117void inline_speed 2214/* internal, faster, version of ev_clear_pending */
2215inline_speed void
2118clear_pending (EV_P_ W w) 2216clear_pending (EV_P_ W w)
2119{ 2217{
2120 if (w->pending) 2218 if (w->pending)
2121 { 2219 {
2122 pendings [ABSPRI (w)][w->pending - 1].w = 0; 2220 pendings [ABSPRI (w)][w->pending - 1].w = (W)&pending_w;
2123 w->pending = 0; 2221 w->pending = 0;
2124 } 2222 }
2125} 2223}
2126 2224
2127int 2225int
2131 int pending = w_->pending; 2229 int pending = w_->pending;
2132 2230
2133 if (expect_true (pending)) 2231 if (expect_true (pending))
2134 { 2232 {
2135 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; 2233 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
2234 p->w = (W)&pending_w;
2136 w_->pending = 0; 2235 w_->pending = 0;
2137 p->w = 0;
2138 return p->events; 2236 return p->events;
2139 } 2237 }
2140 else 2238 else
2141 return 0; 2239 return 0;
2142} 2240}
2143 2241
2144void inline_size 2242inline_size void
2145pri_adjust (EV_P_ W w) 2243pri_adjust (EV_P_ W w)
2146{ 2244{
2147 int pri = w->priority; 2245 int pri = w->priority;
2148 pri = pri < EV_MINPRI ? EV_MINPRI : pri; 2246 pri = pri < EV_MINPRI ? EV_MINPRI : pri;
2149 pri = pri > EV_MAXPRI ? EV_MAXPRI : pri; 2247 pri = pri > EV_MAXPRI ? EV_MAXPRI : pri;
2150 w->priority = pri; 2248 w->priority = pri;
2151} 2249}
2152 2250
2153void inline_speed 2251inline_speed void
2154ev_start (EV_P_ W w, int active) 2252ev_start (EV_P_ W w, int active)
2155{ 2253{
2156 pri_adjust (EV_A_ w); 2254 pri_adjust (EV_A_ w);
2157 w->active = active; 2255 w->active = active;
2158 ev_ref (EV_A); 2256 ev_ref (EV_A);
2159} 2257}
2160 2258
2161void inline_size 2259inline_size void
2162ev_stop (EV_P_ W w) 2260ev_stop (EV_P_ W w)
2163{ 2261{
2164 ev_unref (EV_A); 2262 ev_unref (EV_A);
2165 w->active = 0; 2263 w->active = 0;
2166} 2264}
2174 2272
2175 if (expect_false (ev_is_active (w))) 2273 if (expect_false (ev_is_active (w)))
2176 return; 2274 return;
2177 2275
2178 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 2276 assert (("libev: ev_io_start called with negative fd", fd >= 0));
2179 assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV_IOFDSET | EV_READ | EV_WRITE)))); 2277 assert (("libev: ev_io start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
2180 2278
2181 EV_FREQUENT_CHECK; 2279 EV_FREQUENT_CHECK;
2182 2280
2183 ev_start (EV_A_ (W)w, 1); 2281 ev_start (EV_A_ (W)w, 1);
2184 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 2282 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
2185 wlist_add (&anfds[fd].head, (WL)w); 2283 wlist_add (&anfds[fd].head, (WL)w);
2186 2284
2187 fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); 2285 fd_change (EV_A_ fd, w->events & EV__IOFDSET | 1);
2188 w->events &= ~EV_IOFDSET; 2286 w->events &= ~EV__IOFDSET;
2189 2287
2190 EV_FREQUENT_CHECK; 2288 EV_FREQUENT_CHECK;
2191} 2289}
2192 2290
2193void noinline 2291void noinline
2591 2689
2592 for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len) 2690 for (ofs = 0; ofs < len; ofs += sizeof (struct inotify_event) + ev->len)
2593 infy_wd (EV_A_ ev->wd, ev->wd, ev); 2691 infy_wd (EV_A_ ev->wd, ev->wd, ev);
2594} 2692}
2595 2693
2596void inline_size 2694inline_size void
2597check_2625 (EV_P) 2695check_2625 (EV_P)
2598{ 2696{
2599 /* kernels < 2.6.25 are borked 2697 /* kernels < 2.6.25 are borked
2600 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 2698 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
2601 */ 2699 */
2614 return; 2712 return;
2615 2713
2616 fs_2625 = 1; 2714 fs_2625 = 1;
2617} 2715}
2618 2716
2619void inline_size 2717inline_size void
2620infy_init (EV_P) 2718infy_init (EV_P)
2621{ 2719{
2622 if (fs_fd != -2) 2720 if (fs_fd != -2)
2623 return; 2721 return;
2624 2722
2634 ev_set_priority (&fs_w, EV_MAXPRI); 2732 ev_set_priority (&fs_w, EV_MAXPRI);
2635 ev_io_start (EV_A_ &fs_w); 2733 ev_io_start (EV_A_ &fs_w);
2636 } 2734 }
2637} 2735}
2638 2736
2639void inline_size 2737inline_size void
2640infy_fork (EV_P) 2738infy_fork (EV_P)
2641{ 2739{
2642 int slot; 2740 int slot;
2643 2741
2644 if (fs_fd < 0) 2742 if (fs_fd < 0)
3146 ev_timer_set (&once->to, timeout, 0.); 3244 ev_timer_set (&once->to, timeout, 0.);
3147 ev_timer_start (EV_A_ &once->to); 3245 ev_timer_start (EV_A_ &once->to);
3148 } 3246 }
3149} 3247}
3150 3248
3249/*****************************************************************************/
3250
3251#if EV_WALK_ENABLE
3252void
3253ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w))
3254{
3255 int i, j;
3256 ev_watcher_list *wl, *wn;
3257
3258 if (types & (EV_IO | EV_EMBED))
3259 for (i = 0; i < anfdmax; ++i)
3260 for (wl = anfds [i].head; wl; )
3261 {
3262 wn = wl->next;
3263
3264#if EV_EMBED_ENABLE
3265 if (ev_cb ((ev_io *)wl) == embed_io_cb)
3266 {
3267 if (types & EV_EMBED)
3268 cb (EV_A_ EV_EMBED, ((char *)wl) - offsetof (struct ev_embed, io));
3269 }
3270 else
3271#endif
3272#if EV_USE_INOTIFY
3273 if (ev_cb ((ev_io *)wl) == infy_cb)
3274 ;
3275 else
3276#endif
3277 if ((ev_io *)wl != &pipe_w)
3278 if (types & EV_IO)
3279 cb (EV_A_ EV_IO, wl);
3280
3281 wl = wn;
3282 }
3283
3284 if (types & (EV_TIMER | EV_STAT))
3285 for (i = timercnt + HEAP0; i-- > HEAP0; )
3286#if EV_STAT_ENABLE
3287 /*TODO: timer is not always active*/
3288 if (ev_cb ((ev_timer *)ANHE_w (timers [i])) == stat_timer_cb)
3289 {
3290 if (types & EV_STAT)
3291 cb (EV_A_ EV_STAT, ((char *)ANHE_w (timers [i])) - offsetof (struct ev_stat, timer));
3292 }
3293 else
3294#endif
3295 if (types & EV_TIMER)
3296 cb (EV_A_ EV_TIMER, ANHE_w (timers [i]));
3297
3298#if EV_PERIODIC_ENABLE
3299 if (types & EV_PERIODIC)
3300 for (i = periodiccnt + HEAP0; i-- > HEAP0; )
3301 cb (EV_A_ EV_PERIODIC, ANHE_w (periodics [i]));
3302#endif
3303
3304#if EV_IDLE_ENABLE
3305 if (types & EV_IDLE)
3306 for (j = NUMPRI; i--; )
3307 for (i = idlecnt [j]; i--; )
3308 cb (EV_A_ EV_IDLE, idles [j][i]);
3309#endif
3310
3311#if EV_FORK_ENABLE
3312 if (types & EV_FORK)
3313 for (i = forkcnt; i--; )
3314 if (ev_cb (forks [i]) != embed_fork_cb)
3315 cb (EV_A_ EV_FORK, forks [i]);
3316#endif
3317
3318#if EV_ASYNC_ENABLE
3319 if (types & EV_ASYNC)
3320 for (i = asynccnt; i--; )
3321 cb (EV_A_ EV_ASYNC, asyncs [i]);
3322#endif
3323
3324 if (types & EV_PREPARE)
3325 for (i = preparecnt; i--; )
3326#if EV_EMBED_ENABLE
3327 if (ev_cb (prepares [i]) != embed_prepare_cb)
3328#endif
3329 cb (EV_A_ EV_PREPARE, prepares [i]);
3330
3331 if (types & EV_CHECK)
3332 for (i = checkcnt; i--; )
3333 cb (EV_A_ EV_CHECK, checks [i]);
3334
3335 if (types & EV_SIGNAL)
3336 for (i = 0; i < signalmax; ++i)
3337 for (wl = signals [i].head; wl; )
3338 {
3339 wn = wl->next;
3340 cb (EV_A_ EV_SIGNAL, wl);
3341 wl = wn;
3342 }
3343
3344 if (types & EV_CHILD)
3345 for (i = EV_PID_HASHSIZE; i--; )
3346 for (wl = childs [i]; wl; )
3347 {
3348 wn = wl->next;
3349 cb (EV_A_ EV_CHILD, wl);
3350 wl = wn;
3351 }
3352/* EV_STAT 0x00001000 /* stat data changed */
3353/* EV_EMBED 0x00010000 /* embedded event loop needs sweep */
3354}
3355#endif
3356
3151#if EV_MULTIPLICITY 3357#if EV_MULTIPLICITY
3152 #include "ev_wrap.h" 3358 #include "ev_wrap.h"
3153#endif 3359#endif
3154 3360
3155#ifdef __cplusplus 3361#ifdef __cplusplus

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines