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

Comparing libev/ev.c (file contents):
Revision 1.306 by root, Sun Jul 19 06:35:25 2009 UTC vs.
Revision 1.307 by root, Sun Jul 19 07:20:41 2009 UTC

187#endif 187#endif
188 188
189/* this block tries to deduce configuration from header-defined symbols and defaults */ 189/* this block tries to deduce configuration from header-defined symbols and defaults */
190 190
191/* try to deduce the maximum number of signals on this platform */ 191/* try to deduce the maximum number of signals on this platform */
192/* one some platforms, NSIG is one too large. we do not bother */
193#if defined (EV_NSIG) 192#if defined (EV_NSIG)
194/* use what's provided */ 193/* use what's provided */
195#elif defined (NSIG) 194#elif defined (NSIG)
196# define EV_NSIG (NSIG) 195# define EV_NSIG (NSIG)
197#elif defined(_NSIG) 196#elif defined(_NSIG)
958 957
959 for (fd = anfdmax; fd--; ) 958 for (fd = anfdmax; fd--; )
960 if (anfds [fd].events) 959 if (anfds [fd].events)
961 { 960 {
962 fd_kill (EV_A_ fd); 961 fd_kill (EV_A_ fd);
963 return; 962 break;
964 } 963 }
965} 964}
966 965
967/* usually called after fork if backend needs to re-arm all fds from scratch */ 966/* usually called after fork if backend needs to re-arm all fds from scratch */
968static void noinline 967static void noinline
1127/*****************************************************************************/ 1126/*****************************************************************************/
1128 1127
1129/* associate signal watchers to a signal signal */ 1128/* associate signal watchers to a signal signal */
1130typedef struct 1129typedef struct
1131{ 1130{
1131 EV_ATOMIC_T pending;
1132#if EV_MULTIPLICITY 1132#if EV_MULTIPLICITY
1133 EV_P; 1133 EV_P;
1134#endif 1134#endif
1135 WL head; 1135 WL head;
1136 EV_ATOMIC_T gotsig;
1137} ANSIG; 1136} ANSIG;
1138 1137
1139static ANSIG signals [EV_NSIG - 1]; 1138static ANSIG signals [EV_NSIG - 1];
1140static EV_ATOMIC_T gotsig;
1141 1139
1142/*****************************************************************************/ 1140/*****************************************************************************/
1143 1141
1144/* used to prepare libev internal fd's */ 1142/* used to prepare libev internal fd's */
1145/* this is not fork-safe */ 1143/* this is not fork-safe */
1213/* called whenever the libev signal pipe */ 1211/* called whenever the libev signal pipe */
1214/* got some events (signal, async) */ 1212/* got some events (signal, async) */
1215static void 1213static void
1216pipecb (EV_P_ ev_io *iow, int revents) 1214pipecb (EV_P_ ev_io *iow, int revents)
1217{ 1215{
1216 int i;
1217
1218#if EV_USE_EVENTFD 1218#if EV_USE_EVENTFD
1219 if (evfd >= 0) 1219 if (evfd >= 0)
1220 { 1220 {
1221 uint64_t counter; 1221 uint64_t counter;
1222 read (evfd, &counter, sizeof (uint64_t)); 1222 read (evfd, &counter, sizeof (uint64_t));
1226 { 1226 {
1227 char dummy; 1227 char dummy;
1228 read (evpipe [0], &dummy, 1); 1228 read (evpipe [0], &dummy, 1);
1229 } 1229 }
1230 1230
1231 if (gotsig && ev_is_default_loop (EV_A)) 1231 if (sig_pending)
1232 { 1232 {
1233 int signum; 1233 sig_pending = 0;
1234 gotsig = 0;
1235 1234
1236 for (signum = EV_NSIG - 1; signum--; ) 1235 for (i = EV_NSIG - 1; i--; )
1237 if (signals [signum].gotsig) 1236 if (expect_false (signals [i].pending))
1238 ev_feed_signal_event (EV_A_ signum + 1); 1237 ev_feed_signal_event (EV_A_ i + 1);
1239 } 1238 }
1240 1239
1241#if EV_ASYNC_ENABLE 1240#if EV_ASYNC_ENABLE
1242 if (gotasync) 1241 if (async_pending)
1243 { 1242 {
1244 int i; 1243 async_pending = 0;
1245 gotasync = 0;
1246 1244
1247 for (i = asynccnt; i--; ) 1245 for (i = asynccnt; i--; )
1248 if (asyncs [i]->sent) 1246 if (asyncs [i]->sent)
1249 { 1247 {
1250 asyncs [i]->sent = 0; 1248 asyncs [i]->sent = 0;
1265 1263
1266#if _WIN32 1264#if _WIN32
1267 signal (signum, ev_sighandler); 1265 signal (signum, ev_sighandler);
1268#endif 1266#endif
1269 1267
1270 signals [signum - 1].gotsig = 1; 1268 signals [signum - 1].pending = 1;
1271 evpipe_write (EV_A_ &gotsig); 1269 evpipe_write (EV_A_ &sig_pending);
1272} 1270}
1273 1271
1274void noinline 1272void noinline
1275ev_feed_signal_event (EV_P_ int signum) 1273ev_feed_signal_event (EV_P_ int signum)
1276{ 1274{
1277 WL w; 1275 WL w;
1278 1276
1277 if (expect_false (signum <= 0 || signum > EV_NSIG))
1278 return;
1279
1280 --signum;
1281
1279#if EV_MULTIPLICITY 1282#if EV_MULTIPLICITY
1280 assert (("libev: feeding signal events is only supported in the default loop", loop == ev_default_loop_ptr)); 1283 /* it is permissible to try to feed a signal to the wrong loop */
1281#endif 1284 /* or, likely more useful, feeding a signal nobody is waiting for */
1282 1285
1283 if (signum <= 0 || signum > EV_NSIG) 1286 if (expect_false (signals [signum].loop != EV_A))
1284 return; 1287 return;
1288#endif
1285 1289
1286 --signum;
1287
1288 signals [signum].gotsig = 0; 1290 signals [signum].pending = 0;
1289 1291
1290 for (w = signals [signum].head; w; w = w->next) 1292 for (w = signals [signum].head; w; w = w->next)
1291 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 1293 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
1292} 1294}
1293 1295
1560 1562
1561 io_blocktime = 0.; 1563 io_blocktime = 0.;
1562 timeout_blocktime = 0.; 1564 timeout_blocktime = 0.;
1563 backend = 0; 1565 backend = 0;
1564 backend_fd = -1; 1566 backend_fd = -1;
1565 gotasync = 0; 1567 sig_pending = 0;
1568#if EV_ASYNC_ENABLE
1569 async_pending = 0;
1570#endif
1566#if EV_USE_INOTIFY 1571#if EV_USE_INOTIFY
1567 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; 1572 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
1568#endif 1573#endif
1569#if EV_USE_SIGNALFD 1574#if EV_USE_SIGNALFD
1570 sigfd = flags & EVFLAG_NOSIGFD ? -1 : -2; 1575 sigfd = flags & EVFLAG_NOSIGFD ? -1 : -2;
1704 1709
1705 if (ev_is_active (&pipe_w)) 1710 if (ev_is_active (&pipe_w))
1706 { 1711 {
1707 /* this "locks" the handlers against writing to the pipe */ 1712 /* this "locks" the handlers against writing to the pipe */
1708 /* while we modify the fd vars */ 1713 /* while we modify the fd vars */
1709 gotsig = 1; 1714 sig_pending = 1;
1710#if EV_ASYNC_ENABLE 1715#if EV_ASYNC_ENABLE
1711 gotasync = 1; 1716 async_pending = 1;
1712#endif 1717#endif
1713 1718
1714 ev_ref (EV_A); 1719 ev_ref (EV_A);
1715 ev_io_stop (EV_A_ &pipe_w); 1720 ev_io_stop (EV_A_ &pipe_w);
1716 1721
1856 assert (checkmax >= checkcnt); 1861 assert (checkmax >= checkcnt);
1857 array_verify (EV_A_ (W *)checks, checkcnt); 1862 array_verify (EV_A_ (W *)checks, checkcnt);
1858 1863
1859# if 0 1864# if 0
1860 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1865 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
1861 for (signum = EV_NSIG; signum--; ) if (signals [signum].gotsig) 1866 for (signum = EV_NSIG; signum--; ) if (signals [signum].pending)
1862# endif 1867# endif
1863#endif 1868#endif
1864} 1869}
1865#endif 1870#endif
1866 1871
2393inline_size void 2398inline_size void
2394wlist_del (WL *head, WL elem) 2399wlist_del (WL *head, WL elem)
2395{ 2400{
2396 while (*head) 2401 while (*head)
2397 { 2402 {
2398 if (*head == elem) 2403 if (expect_true (*head == elem))
2399 { 2404 {
2400 *head = elem->next; 2405 *head = elem->next;
2401 return; 2406 break;
2402 } 2407 }
2403 2408
2404 head = &(*head)->next; 2409 head = &(*head)->next;
2405 } 2410 }
2406} 2411}
2747 wlist_del (&signals [w->signum - 1].head, (WL)w); 2752 wlist_del (&signals [w->signum - 1].head, (WL)w);
2748 ev_stop (EV_A_ (W)w); 2753 ev_stop (EV_A_ (W)w);
2749 2754
2750 if (!signals [w->signum - 1].head) 2755 if (!signals [w->signum - 1].head)
2751 { 2756 {
2752 #if EV_MULTIPLICITY 2757#if EV_MULTIPLICITY
2753 signals [w->signum - 1].loop = 0; /* unattach from signal */ 2758 signals [w->signum - 1].loop = 0; /* unattach from signal */
2754 #endif 2759#endif
2755 #if EV_USE_SIGNALFD 2760#if EV_USE_SIGNALFD
2756 if (sigfd >= 0) 2761 if (sigfd >= 0)
2757 { 2762 {
2758 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D 2763 sigprocmask (SIG_UNBLOCK, &sigfd_set, 0);//D
2759 sigdelset (&sigfd_set, w->signum); 2764 sigdelset (&sigfd_set, w->signum);
2760 signalfd (sigfd, &sigfd_set, 0); 2765 signalfd (sigfd, &sigfd_set, 0);
2761 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D 2766 sigprocmask (SIG_BLOCK, &sigfd_set, 0);//D
2762 /*TODO: maybe unblock signal? */ 2767 /*TODO: maybe unblock signal? */
2763 } 2768 }
2764 else 2769 else
2765 #endif 2770#endif
2766 signal (w->signum, SIG_DFL); 2771 signal (w->signum, SIG_DFL);
2767 } 2772 }
2768 2773
2769 EV_FREQUENT_CHECK; 2774 EV_FREQUENT_CHECK;
2770} 2775}
3416 3421
3417void 3422void
3418ev_async_send (EV_P_ ev_async *w) 3423ev_async_send (EV_P_ ev_async *w)
3419{ 3424{
3420 w->sent = 1; 3425 w->sent = 1;
3421 evpipe_write (EV_A_ &gotasync); 3426 evpipe_write (EV_A_ &async_pending);
3422} 3427}
3423#endif 3428#endif
3424 3429
3425/*****************************************************************************/ 3430/*****************************************************************************/
3426 3431

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines