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

Comparing libev/ev.c (file contents):
Revision 1.365 by root, Sun Oct 31 22:01:20 2010 UTC vs.
Revision 1.369 by root, Sun Jan 23 18:53:06 2011 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
815 select (0, 0, 0, 0, &tv); 815 select (0, 0, 0, 0, &tv);
816#endif 816#endif
817 } 817 }
818} 818}
819 819
820inline_speed int
821ev_timeout_to_ms (ev_tstamp timeout)
822{
823 int ms = timeout * 1000. + .999999;
824
825 return expect_true (ms) ? ms : timeout < 1e-6 ? 0 : 1;
826}
827
820/*****************************************************************************/ 828/*****************************************************************************/
821 829
822#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */ 830#define MALLOC_ROUND 4096 /* prefer to allocate in chunks of this size, must be 2**n and >> 4 longs */
823 831
824/* find a suitable new size for the given array, */ 832/* find a suitable new size for the given array, */
1343 char dummy; 1351 char dummy;
1344 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1352 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1345 read (evpipe [0], &dummy, 1); 1353 read (evpipe [0], &dummy, 1);
1346 } 1354 }
1347 1355
1356#if EV_SIGNAL_ENABLE
1348 if (sig_pending) 1357 if (sig_pending)
1349 { 1358 {
1350 sig_pending = 0; 1359 sig_pending = 0;
1351 1360
1352 for (i = EV_NSIG - 1; i--; ) 1361 for (i = EV_NSIG - 1; i--; )
1353 if (expect_false (signals [i].pending)) 1362 if (expect_false (signals [i].pending))
1354 ev_feed_signal_event (EV_A_ i + 1); 1363 ev_feed_signal_event (EV_A_ i + 1);
1355 } 1364 }
1365#endif
1356 1366
1357#if EV_ASYNC_ENABLE 1367#if EV_ASYNC_ENABLE
1358 if (async_pending) 1368 if (async_pending)
1359 { 1369 {
1360 async_pending = 0; 1370 async_pending = 0;
1369#endif 1379#endif
1370} 1380}
1371 1381
1372/*****************************************************************************/ 1382/*****************************************************************************/
1373 1383
1384void
1385ev_feed_signal (int signum)
1386{
1387#if EV_MULTIPLICITY
1388 EV_P = signals [signum - 1].loop;
1389
1390 if (!EV_A)
1391 return;
1392#endif
1393
1394 signals [signum - 1].pending = 1;
1395 evpipe_write (EV_A_ &sig_pending);
1396}
1397
1374static void 1398static void
1375ev_sighandler (int signum) 1399ev_sighandler (int signum)
1376{ 1400{
1377#if EV_MULTIPLICITY
1378 EV_P = signals [signum - 1].loop;
1379#endif
1380
1381#ifdef _WIN32 1401#ifdef _WIN32
1382 signal (signum, ev_sighandler); 1402 signal (signum, ev_sighandler);
1383#endif 1403#endif
1384 1404
1385 signals [signum - 1].pending = 1; 1405 ev_feed_signal (signum);
1386 evpipe_write (EV_A_ &sig_pending);
1387} 1406}
1388 1407
1389void noinline 1408void noinline
1390ev_feed_signal_event (EV_P_ int signum) 1409ev_feed_signal_event (EV_P_ int signum)
1391{ 1410{
1643static void noinline 1662static void noinline
1644loop_init (EV_P_ unsigned int flags) 1663loop_init (EV_P_ unsigned int flags)
1645{ 1664{
1646 if (!backend) 1665 if (!backend)
1647 { 1666 {
1667 origflags = flags;
1668
1648#if EV_USE_REALTIME 1669#if EV_USE_REALTIME
1649 if (!have_realtime) 1670 if (!have_realtime)
1650 { 1671 {
1651 struct timespec ts; 1672 struct timespec ts;
1652 1673
1697#endif 1718#endif
1698#if EV_USE_SIGNALFD 1719#if EV_USE_SIGNALFD
1699 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 1720 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
1700#endif 1721#endif
1701 1722
1702 if (!(flags & 0x0000ffffU)) 1723 if (!(flags & EVBACKEND_MASK))
1703 flags |= ev_recommended_backends (); 1724 flags |= ev_recommended_backends ();
1704 1725
1705#if EV_USE_IOCP 1726#if EV_USE_IOCP
1706 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 1727 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
1707#endif 1728#endif
2099 2120
2100 for (pri = NUMPRI; pri--; ) 2121 for (pri = NUMPRI; pri--; )
2101 while (pendingcnt [pri]) 2122 while (pendingcnt [pri])
2102 { 2123 {
2103 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2124 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
2104
2105 /*assert (("libev: non-pending watcher on pending list", p->w->pending));*/
2106 /* ^ this is no longer true, as pending_w could be here */
2107 2125
2108 p->w->pending = 0; 2126 p->w->pending = 0;
2109 EV_CB_INVOKE (p->w, p->events); 2127 EV_CB_INVOKE (p->w, p->events);
2110 EV_FREQUENT_CHECK; 2128 EV_FREQUENT_CHECK;
2111 } 2129 }
2879 sa.sa_handler = ev_sighandler; 2897 sa.sa_handler = ev_sighandler;
2880 sigfillset (&sa.sa_mask); 2898 sigfillset (&sa.sa_mask);
2881 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 2899 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
2882 sigaction (w->signum, &sa, 0); 2900 sigaction (w->signum, &sa, 0);
2883 2901
2902 if (origflags & EVFLAG_NOSIGMASK)
2903 {
2884 sigemptyset (&sa.sa_mask); 2904 sigemptyset (&sa.sa_mask);
2885 sigaddset (&sa.sa_mask, w->signum); 2905 sigaddset (&sa.sa_mask, w->signum);
2886 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); 2906 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
2907 }
2887#endif 2908#endif
2888 } 2909 }
2889 2910
2890 EV_FREQUENT_CHECK; 2911 EV_FREQUENT_CHECK;
2891} 2912}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines