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.368 by root, Mon Jan 17 12:11:11 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, */
1369#endif 1377#endif
1370} 1378}
1371 1379
1372/*****************************************************************************/ 1380/*****************************************************************************/
1373 1381
1382void
1383ev_feed_signal (int signum)
1384{
1385#if EV_MULTIPLICITY
1386 EV_P = signals [signum - 1].loop;
1387
1388 if (!EV_A)
1389 return;
1390#endif
1391
1392 signals [signum - 1].pending = 1;
1393 evpipe_write (EV_A_ &sig_pending);
1394}
1395
1374static void 1396static void
1375ev_sighandler (int signum) 1397ev_sighandler (int signum)
1376{ 1398{
1377#if EV_MULTIPLICITY
1378 EV_P = signals [signum - 1].loop;
1379#endif
1380
1381#ifdef _WIN32 1399#ifdef _WIN32
1382 signal (signum, ev_sighandler); 1400 signal (signum, ev_sighandler);
1383#endif 1401#endif
1384 1402
1385 signals [signum - 1].pending = 1; 1403 ev_feed_signal (signum);
1386 evpipe_write (EV_A_ &sig_pending);
1387} 1404}
1388 1405
1389void noinline 1406void noinline
1390ev_feed_signal_event (EV_P_ int signum) 1407ev_feed_signal_event (EV_P_ int signum)
1391{ 1408{
1643static void noinline 1660static void noinline
1644loop_init (EV_P_ unsigned int flags) 1661loop_init (EV_P_ unsigned int flags)
1645{ 1662{
1646 if (!backend) 1663 if (!backend)
1647 { 1664 {
1665 origflags = flags;
1666
1648#if EV_USE_REALTIME 1667#if EV_USE_REALTIME
1649 if (!have_realtime) 1668 if (!have_realtime)
1650 { 1669 {
1651 struct timespec ts; 1670 struct timespec ts;
1652 1671
1697#endif 1716#endif
1698#if EV_USE_SIGNALFD 1717#if EV_USE_SIGNALFD
1699 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 1718 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
1700#endif 1719#endif
1701 1720
1702 if (!(flags & 0x0000ffffU)) 1721 if (!(flags & EVBACKEND_MASK))
1703 flags |= ev_recommended_backends (); 1722 flags |= ev_recommended_backends ();
1704 1723
1705#if EV_USE_IOCP 1724#if EV_USE_IOCP
1706 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 1725 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
1707#endif 1726#endif
2099 2118
2100 for (pri = NUMPRI; pri--; ) 2119 for (pri = NUMPRI; pri--; )
2101 while (pendingcnt [pri]) 2120 while (pendingcnt [pri])
2102 { 2121 {
2103 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2122 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 2123
2108 p->w->pending = 0; 2124 p->w->pending = 0;
2109 EV_CB_INVOKE (p->w, p->events); 2125 EV_CB_INVOKE (p->w, p->events);
2110 EV_FREQUENT_CHECK; 2126 EV_FREQUENT_CHECK;
2111 } 2127 }
2879 sa.sa_handler = ev_sighandler; 2895 sa.sa_handler = ev_sighandler;
2880 sigfillset (&sa.sa_mask); 2896 sigfillset (&sa.sa_mask);
2881 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */ 2897 sa.sa_flags = SA_RESTART; /* if restarting works we save one iteration */
2882 sigaction (w->signum, &sa, 0); 2898 sigaction (w->signum, &sa, 0);
2883 2899
2900 if (origflags & EVFLAG_NOSIGMASK)
2901 {
2884 sigemptyset (&sa.sa_mask); 2902 sigemptyset (&sa.sa_mask);
2885 sigaddset (&sa.sa_mask, w->signum); 2903 sigaddset (&sa.sa_mask, w->signum);
2886 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0); 2904 sigprocmask (SIG_UNBLOCK, &sa.sa_mask, 0);
2905 }
2887#endif 2906#endif
2888 } 2907 }
2889 2908
2890 EV_FREQUENT_CHECK; 2909 EV_FREQUENT_CHECK;
2891} 2910}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines