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

Comparing libev/ev.c (file contents):
Revision 1.297 by root, Fri Jul 10 00:36:21 2009 UTC vs.
Revision 1.298 by root, Fri Jul 10 19:10:19 2009 UTC

490#define ev_malloc(size) ev_realloc (0, (size)) 490#define ev_malloc(size) ev_realloc (0, (size))
491#define ev_free(ptr) ev_realloc ((ptr), 0) 491#define ev_free(ptr) ev_realloc ((ptr), 0)
492 492
493/*****************************************************************************/ 493/*****************************************************************************/
494 494
495/* set in reify when reification needed */
496#define EV_ANFD_REIFY 1
497
495/* file descriptor info structure */ 498/* file descriptor info structure */
496typedef struct 499typedef struct
497{ 500{
498 WL head; 501 WL head;
499 unsigned char events; /* the events watched for */ 502 unsigned char events; /* the events watched for */
500 unsigned char reify; /* flag set when this ANFD needs reification */ 503 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */
501 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 504 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */
502 unsigned char unused; 505 unsigned char unused;
503#if EV_USE_EPOLL 506#if EV_USE_EPOLL
504 unsigned int egen; /* generation counter to counter epoll bugs */ 507 unsigned int egen; /* generation counter to counter epoll bugs */
505#endif 508#endif
568 static int ev_default_loop_ptr; 571 static int ev_default_loop_ptr;
569 572
570#endif 573#endif
571 574
572#if EV_MINIMAL < 2 575#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) 576# define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A)
577# define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A)
575# define EV_INVOKE_PENDING invoke_cb (EV_A) 578# define EV_INVOKE_PENDING invoke_cb (EV_A)
576#else 579#else
577# define EV_SUSPEND_CB (void)0
578# define EV_RESUME_CB (void)0 580# define EV_RELEASE_CB (void)0
581# define EV_ACQUIRE_CB (void)0
579# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 582# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
580#endif 583#endif
584
585#define EVUNLOOP_RECURSE 0x80
581 586
582/*****************************************************************************/ 587/*****************************************************************************/
583 588
584#ifndef EV_HAVE_EV_TIME 589#ifndef EV_HAVE_EV_TIME
585ev_tstamp 590ev_tstamp
760} 765}
761 766
762/*****************************************************************************/ 767/*****************************************************************************/
763 768
764inline_speed void 769inline_speed void
765fd_event (EV_P_ int fd, int revents) 770fd_event_nc (EV_P_ int fd, int revents)
766{ 771{
767 ANFD *anfd = anfds + fd; 772 ANFD *anfd = anfds + fd;
768 ev_io *w; 773 ev_io *w;
769 774
770 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) 775 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
774 if (ev) 779 if (ev)
775 ev_feed_event (EV_A_ (W)w, ev); 780 ev_feed_event (EV_A_ (W)w, ev);
776 } 781 }
777} 782}
778 783
784/* do not submit kernel events for fds that have reify set */
785/* because that means they changed while we were polling for new events */
786inline_speed void
787fd_event (EV_P_ int fd, int revents)
788{
789 ANFD *anfd = anfds + fd;
790
791 if (expect_true (!anfd->reify))
792 fd_event_nc (EV_A_ fd, revents);
793}
794
779void 795void
780ev_feed_fd_event (EV_P_ int fd, int revents) 796ev_feed_fd_event (EV_P_ int fd, int revents)
781{ 797{
782 if (fd >= 0 && fd < anfdmax) 798 if (fd >= 0 && fd < anfdmax)
783 fd_event (EV_A_ fd, revents); 799 fd_event_nc (EV_A_ fd, revents);
784} 800}
785 801
786/* make sure the external fd watch events are in-sync */ 802/* make sure the external fd watch events are in-sync */
787/* with the kernel/libev internal state */ 803/* with the kernel/libev internal state */
788inline_size void 804inline_size void
903 for (fd = 0; fd < anfdmax; ++fd) 919 for (fd = 0; fd < anfdmax; ++fd)
904 if (anfds [fd].events) 920 if (anfds [fd].events)
905 { 921 {
906 anfds [fd].events = 0; 922 anfds [fd].events = 0;
907 anfds [fd].emask = 0; 923 anfds [fd].emask = 0;
908 fd_change (EV_A_ fd, EV__IOFDSET | 1); 924 fd_change (EV_A_ fd, EV__IOFDSET | EV_ANFD_REIFY);
909 } 925 }
910} 926}
911 927
912/*****************************************************************************/ 928/*****************************************************************************/
913 929
1409void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 1425void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P))
1410{ 1426{
1411 invoke_cb = invoke_pending_cb; 1427 invoke_cb = invoke_pending_cb;
1412} 1428}
1413 1429
1414void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P)) 1430void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P))
1415{ 1431{
1416 suspend_cb = suspend_cb_; 1432 release_cb = release;
1417 resume_cb = resume_cb_; 1433 acquire_cb = acquire;
1418} 1434}
1419#endif 1435#endif
1420 1436
1421/* initialise a loop structure, must be zero-initialised */ 1437/* initialise a loop structure, must be zero-initialised */
1422static void noinline 1438static void noinline
2077{ 2093{
2078#if EV_MINIMAL < 2 2094#if EV_MINIMAL < 2
2079 ++loop_depth; 2095 ++loop_depth;
2080#endif 2096#endif
2081 2097
2098 assert (("libev: ev_loop recursion during release detected", loop_done != EVUNLOOP_RECURSE));
2099
2082 loop_done = EVUNLOOP_CANCEL; 2100 loop_done = EVUNLOOP_CANCEL;
2083 2101
2084 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */ 2102 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
2085 2103
2086 do 2104 do
2113 { 2131 {
2114 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 2132 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
2115 EV_INVOKE_PENDING; 2133 EV_INVOKE_PENDING;
2116 } 2134 }
2117 2135
2136 if (expect_false (loop_done))
2137 break;
2138
2118 /* we might have forked, so reify kernel state if necessary */ 2139 /* we might have forked, so reify kernel state if necessary */
2119 if (expect_false (postfork)) 2140 if (expect_false (postfork))
2120 loop_fork (EV_A); 2141 loop_fork (EV_A);
2121 2142
2122 /* update fd-related kernel structures */ 2143 /* update fd-related kernel structures */
2172 } 2193 }
2173 2194
2174#if EV_MINIMAL < 2 2195#if EV_MINIMAL < 2
2175 ++loop_count; 2196 ++loop_count;
2176#endif 2197#endif
2198 assert ((loop_done = EVUNLOOP_RECURSE, 1)); /* assert for side effect */
2177 backend_poll (EV_A_ waittime); 2199 backend_poll (EV_A_ waittime);
2200 assert ((loop_done = EVUNLOOP_CANCEL, 1)); /* assert for side effect */
2178 2201
2179 /* update ev_rt_now, do magic */ 2202 /* update ev_rt_now, do magic */
2180 time_update (EV_A_ waittime + sleeptime); 2203 time_update (EV_A_ waittime + sleeptime);
2181 } 2204 }
2182 2205
2348 2371
2349 ev_start (EV_A_ (W)w, 1); 2372 ev_start (EV_A_ (W)w, 1);
2350 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 2373 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
2351 wlist_add (&anfds[fd].head, (WL)w); 2374 wlist_add (&anfds[fd].head, (WL)w);
2352 2375
2353 fd_change (EV_A_ fd, w->events & EV__IOFDSET | 1); 2376 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY);
2354 w->events &= ~EV__IOFDSET; 2377 w->events &= ~EV__IOFDSET;
2355 2378
2356 EV_FREQUENT_CHECK; 2379 EV_FREQUENT_CHECK;
2357} 2380}
2358 2381

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines