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

Comparing libev/ev.c (file contents):
Revision 1.264 by root, Mon Oct 13 23:20:12 2008 UTC vs.
Revision 1.268 by root, Mon Oct 27 13:39:18 2008 UTC

449typedef struct 449typedef struct
450{ 450{
451 WL head; 451 WL head;
452 unsigned char events; 452 unsigned char events;
453 unsigned char reify; 453 unsigned char reify;
454 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */
455 unsigned char egen; /* generation counter to counter epoll bugs */
454#if EV_SELECT_IS_WINSOCKET 456#if EV_SELECT_IS_WINSOCKET
455 SOCKET handle; 457 SOCKET handle;
456#endif 458#endif
457} ANFD; 459} ANFD;
458 460
611{ 613{
612 *cur = array_nextsize (elem, *cur, cnt); 614 *cur = array_nextsize (elem, *cur, cnt);
613 return ev_realloc (base, elem * *cur); 615 return ev_realloc (base, elem * *cur);
614} 616}
615 617
618#define array_init_zero(base,count) \
619 memset ((void *)(base), 0, sizeof (*(base)) * (count))
620
616#define array_needsize(type,base,cur,cnt,init) \ 621#define array_needsize(type,base,cur,cnt,init) \
617 if (expect_false ((cnt) > (cur))) \ 622 if (expect_false ((cnt) > (cur))) \
618 { \ 623 { \
619 int ocur_ = (cur); \ 624 int ocur_ = (cur); \
620 (base) = (type *)array_realloc \ 625 (base) = (type *)array_realloc \
662 for (i = 0; i < eventcnt; ++i) 667 for (i = 0; i < eventcnt; ++i)
663 ev_feed_event (EV_A_ events [i], type); 668 ev_feed_event (EV_A_ events [i], type);
664} 669}
665 670
666/*****************************************************************************/ 671/*****************************************************************************/
667
668void inline_size
669anfds_init (ANFD *base, int count)
670{
671 while (count--)
672 {
673 base->head = 0;
674 base->events = EV_NONE;
675 base->reify = 0;
676
677 ++base;
678 }
679}
680 672
681void inline_speed 673void inline_speed
682fd_event (EV_P_ int fd, int revents) 674fd_event (EV_P_ int fd, int revents)
683{ 675{
684 ANFD *anfd = anfds + fd; 676 ANFD *anfd = anfds + fd;
814 806
815 for (fd = 0; fd < anfdmax; ++fd) 807 for (fd = 0; fd < anfdmax; ++fd)
816 if (anfds [fd].events) 808 if (anfds [fd].events)
817 { 809 {
818 anfds [fd].events = 0; 810 anfds [fd].events = 0;
811 anfds [fd].emask = 0;
819 fd_change (EV_A_ fd, EV_IOFDSET | 1); 812 fd_change (EV_A_ fd, EV_IOFDSET | 1);
820 } 813 }
821} 814}
822 815
823/*****************************************************************************/ 816/*****************************************************************************/
975static ANSIG *signals; 968static ANSIG *signals;
976static int signalmax; 969static int signalmax;
977 970
978static EV_ATOMIC_T gotsig; 971static EV_ATOMIC_T gotsig;
979 972
980void inline_size
981signals_init (ANSIG *base, int count)
982{
983 while (count--)
984 {
985 base->head = 0;
986 base->gotsig = 0;
987
988 ++base;
989 }
990}
991
992/*****************************************************************************/ 973/*****************************************************************************/
993 974
994void inline_speed 975void inline_speed
995fd_intern (int fd) 976fd_intern (int fd)
996{ 977{
1657ev_default_destroy (void) 1638ev_default_destroy (void)
1658{ 1639{
1659#if EV_MULTIPLICITY 1640#if EV_MULTIPLICITY
1660 struct ev_loop *loop = ev_default_loop_ptr; 1641 struct ev_loop *loop = ev_default_loop_ptr;
1661#endif 1642#endif
1643
1644 ev_default_loop_ptr = 0;
1662 1645
1663#ifndef _WIN32 1646#ifndef _WIN32
1664 ev_ref (EV_A); /* child watcher */ 1647 ev_ref (EV_A); /* child watcher */
1665 ev_signal_stop (EV_A_ &childev); 1648 ev_signal_stop (EV_A_ &childev);
1666#endif 1649#endif
2139 2122
2140 if (expect_false (ev_is_active (w))) 2123 if (expect_false (ev_is_active (w)))
2141 return; 2124 return;
2142 2125
2143 assert (("ev_io_start called with negative fd", fd >= 0)); 2126 assert (("ev_io_start called with negative fd", fd >= 0));
2127 assert (("ev_io start called with illegal event mask", !(w->events & ~(EV_IOFDSET | EV_READ | EV_WRITE))));
2144 2128
2145 EV_FREQUENT_CHECK; 2129 EV_FREQUENT_CHECK;
2146 2130
2147 ev_start (EV_A_ (W)w, 1); 2131 ev_start (EV_A_ (W)w, 1);
2148 array_needsize (ANFD, anfds, anfdmax, fd + 1, anfds_init); 2132 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
2149 wlist_add (&anfds[fd].head, (WL)w); 2133 wlist_add (&anfds[fd].head, (WL)w);
2150 2134
2151 fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1); 2135 fd_change (EV_A_ fd, w->events & EV_IOFDSET | 1);
2152 w->events &= ~EV_IOFDSET; 2136 w->events &= ~EV_IOFDSET;
2153 2137
2345 sigset_t full, prev; 2329 sigset_t full, prev;
2346 sigfillset (&full); 2330 sigfillset (&full);
2347 sigprocmask (SIG_SETMASK, &full, &prev); 2331 sigprocmask (SIG_SETMASK, &full, &prev);
2348#endif 2332#endif
2349 2333
2350 array_needsize (ANSIG, signals, signalmax, w->signum, signals_init); 2334 array_needsize (ANSIG, signals, signalmax, w->signum, array_init_zero);
2351 2335
2352#ifndef _WIN32 2336#ifndef _WIN32
2353 sigprocmask (SIG_SETMASK, &prev, 0); 2337 sigprocmask (SIG_SETMASK, &prev, 0);
2354#endif 2338#endif
2355 } 2339 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines