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

Comparing libev/ev.c (file contents):
Revision 1.296 by root, Thu Jul 9 09:11:20 2009 UTC vs.
Revision 1.297 by root, Fri Jul 10 00:36:21 2009 UTC

567 567
568 static int ev_default_loop_ptr; 568 static int ev_default_loop_ptr;
569 569
570#endif 570#endif
571 571
572#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)
575# define EV_INVOKE_PENDING invoke_cb (EV_A)
576#else
577# define EV_SUSPEND_CB (void)0
578# define EV_RESUME_CB (void)0
579# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
580#endif
581
572/*****************************************************************************/ 582/*****************************************************************************/
573 583
574#ifndef EV_HAVE_EV_TIME 584#ifndef EV_HAVE_EV_TIME
575ev_tstamp 585ev_tstamp
576ev_time (void) 586ev_time (void)
1357ev_backend (EV_P) 1367ev_backend (EV_P)
1358{ 1368{
1359 return backend; 1369 return backend;
1360} 1370}
1361 1371
1372#if EV_MINIMAL < 2
1362unsigned int 1373unsigned int
1363ev_loop_count (EV_P) 1374ev_loop_count (EV_P)
1364{ 1375{
1365 return loop_count; 1376 return loop_count;
1366} 1377}
1380void 1391void
1381ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 1392ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval)
1382{ 1393{
1383 timeout_blocktime = interval; 1394 timeout_blocktime = interval;
1384} 1395}
1396
1397void
1398ev_set_userdata (EV_P_ void *data)
1399{
1400 userdata = data;
1401}
1402
1403void *
1404ev_userdata (EV_P)
1405{
1406 return userdata;
1407}
1408
1409void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P))
1410{
1411 invoke_cb = invoke_pending_cb;
1412}
1413
1414void ev_set_blocking_cb (EV_P_ void (*suspend_cb_)(EV_P), void (*resume_cb_)(EV_P))
1415{
1416 suspend_cb = suspend_cb_;
1417 resume_cb = resume_cb_;
1418}
1419#endif
1385 1420
1386/* initialise a loop structure, must be zero-initialised */ 1421/* initialise a loop structure, must be zero-initialised */
1387static void noinline 1422static void noinline
1388loop_init (EV_P_ unsigned int flags) 1423loop_init (EV_P_ unsigned int flags)
1389{ 1424{
1411 1446
1412 ev_rt_now = ev_time (); 1447 ev_rt_now = ev_time ();
1413 mn_now = get_clock (); 1448 mn_now = get_clock ();
1414 now_floor = mn_now; 1449 now_floor = mn_now;
1415 rtmn_diff = ev_rt_now - mn_now; 1450 rtmn_diff = ev_rt_now - mn_now;
1451#if EV_MINIMAL < 2
1416 invoke_cb = ev_invoke_pending; 1452 invoke_cb = ev_invoke_pending;
1453#endif
1417 1454
1418 io_blocktime = 0.; 1455 io_blocktime = 0.;
1419 timeout_blocktime = 0.; 1456 timeout_blocktime = 0.;
1420 backend = 0; 1457 backend = 0;
1421 backend_fd = -1; 1458 backend_fd = -1;
1615void 1652void
1616ev_loop_fork (EV_P) 1653ev_loop_fork (EV_P)
1617{ 1654{
1618 postfork = 1; /* must be in line with ev_default_fork */ 1655 postfork = 1; /* must be in line with ev_default_fork */
1619} 1656}
1657#endif /* multiplicity */
1620 1658
1621#if EV_VERIFY 1659#if EV_VERIFY
1622static void noinline 1660static void noinline
1623verify_watcher (EV_P_ W w) 1661verify_watcher (EV_P_ W w)
1624{ 1662{
1652 verify_watcher (EV_A_ ws [cnt]); 1690 verify_watcher (EV_A_ ws [cnt]);
1653 } 1691 }
1654} 1692}
1655#endif 1693#endif
1656 1694
1695#if EV_MINIMAL < 2
1657void 1696void
1658ev_loop_verify (EV_P) 1697ev_loop_verify (EV_P)
1659{ 1698{
1660#if EV_VERIFY 1699#if EV_VERIFY
1661 int i; 1700 int i;
1714 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 1753 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
1715 for (signum = signalmax; signum--; ) if (signals [signum].gotsig) 1754 for (signum = signalmax; signum--; ) if (signals [signum].gotsig)
1716# endif 1755# endif
1717#endif 1756#endif
1718} 1757}
1719 1758#endif
1720#endif /* multiplicity */
1721 1759
1722#if EV_MULTIPLICITY 1760#if EV_MULTIPLICITY
1723struct ev_loop * 1761struct ev_loop *
1724ev_default_loop_init (unsigned int flags) 1762ev_default_loop_init (unsigned int flags)
1725#else 1763#else
1786ev_invoke (EV_P_ void *w, int revents) 1824ev_invoke (EV_P_ void *w, int revents)
1787{ 1825{
1788 EV_CB_INVOKE ((W)w, revents); 1826 EV_CB_INVOKE ((W)w, revents);
1789} 1827}
1790 1828
1791void 1829void noinline
1792ev_invoke_pending (EV_P) 1830ev_invoke_pending (EV_P)
1793{ 1831{
1794 int pri; 1832 int pri;
1795 1833
1796 for (pri = NUMPRI; pri--; ) 1834 for (pri = NUMPRI; pri--; )
2035} 2073}
2036 2074
2037void 2075void
2038ev_loop (EV_P_ int flags) 2076ev_loop (EV_P_ int flags)
2039{ 2077{
2078#if EV_MINIMAL < 2
2040 ++loop_depth; 2079 ++loop_depth;
2080#endif
2041 2081
2042 loop_done = EVUNLOOP_CANCEL; 2082 loop_done = EVUNLOOP_CANCEL;
2043 2083
2044 invoke_cb (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ 2084 EV_INVOKE_PENDING; /* in case we recurse, ensure ordering stays nice and clean */
2045 2085
2046 do 2086 do
2047 { 2087 {
2048#if EV_VERIFY >= 2 2088#if EV_VERIFY >= 2
2049 ev_loop_verify (EV_A); 2089 ev_loop_verify (EV_A);
2062 /* we might have forked, so queue fork handlers */ 2102 /* we might have forked, so queue fork handlers */
2063 if (expect_false (postfork)) 2103 if (expect_false (postfork))
2064 if (forkcnt) 2104 if (forkcnt)
2065 { 2105 {
2066 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 2106 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
2067 invoke_cb (EV_A); 2107 EV_INVOKE_PENDING;
2068 } 2108 }
2069#endif 2109#endif
2070 2110
2071 /* queue prepare watchers (and execute them) */ 2111 /* queue prepare watchers (and execute them) */
2072 if (expect_false (preparecnt)) 2112 if (expect_false (preparecnt))
2073 { 2113 {
2074 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 2114 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
2075 invoke_cb (EV_A); 2115 EV_INVOKE_PENDING;
2076 } 2116 }
2077 2117
2078 /* we might have forked, so reify kernel state if necessary */ 2118 /* we might have forked, so reify kernel state if necessary */
2079 if (expect_false (postfork)) 2119 if (expect_false (postfork))
2080 loop_fork (EV_A); 2120 loop_fork (EV_A);
2129 waittime -= sleeptime; 2169 waittime -= sleeptime;
2130 } 2170 }
2131 } 2171 }
2132 } 2172 }
2133 2173
2174#if EV_MINIMAL < 2
2134 ++loop_count; 2175 ++loop_count;
2176#endif
2135 backend_poll (EV_A_ waittime); 2177 backend_poll (EV_A_ waittime);
2136 2178
2137 /* update ev_rt_now, do magic */ 2179 /* update ev_rt_now, do magic */
2138 time_update (EV_A_ waittime + sleeptime); 2180 time_update (EV_A_ waittime + sleeptime);
2139 } 2181 }
2151 2193
2152 /* queue check watchers, to be executed first */ 2194 /* queue check watchers, to be executed first */
2153 if (expect_false (checkcnt)) 2195 if (expect_false (checkcnt))
2154 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 2196 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
2155 2197
2156 invoke_cb (EV_A); 2198 EV_INVOKE_PENDING;
2157 } 2199 }
2158 while (expect_true ( 2200 while (expect_true (
2159 activecnt 2201 activecnt
2160 && !loop_done 2202 && !loop_done
2161 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)) 2203 && !(flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK))
2162 )); 2204 ));
2163 2205
2164 if (loop_done == EVUNLOOP_ONE) 2206 if (loop_done == EVUNLOOP_ONE)
2165 loop_done = EVUNLOOP_CANCEL; 2207 loop_done = EVUNLOOP_CANCEL;
2166 2208
2209#if EV_MINIMAL < 2
2167 --loop_depth; 2210 --loop_depth;
2211#endif
2168} 2212}
2169 2213
2170void 2214void
2171ev_unloop (EV_P_ int how) 2215ev_unloop (EV_P_ int how)
2172{ 2216{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines