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

Comparing libev/ev.c (file contents):
Revision 1.248 by root, Wed May 21 23:25:21 2008 UTC vs.
Revision 1.250 by root, Thu May 22 02:44:57 2008 UTC

126# define EV_USE_EVENTFD 1 126# define EV_USE_EVENTFD 1
127# else 127# else
128# define EV_USE_EVENTFD 0 128# define EV_USE_EVENTFD 0
129# endif 129# endif
130# endif 130# endif
131 131
132#endif 132#endif
133 133
134#include <math.h> 134#include <math.h>
135#include <stdlib.h> 135#include <stdlib.h>
136#include <fcntl.h> 136#include <fcntl.h>
235# else 235# else
236# define EV_USE_EVENTFD 0 236# define EV_USE_EVENTFD 0
237# endif 237# endif
238#endif 238#endif
239 239
240#if 0 /* debugging */
241# define EV_VERIFY 3
242# define EV_USE_4HEAP 1
243# define EV_HEAP_CACHE_AT 1
244#endif
245
246#ifndef EV_VERIFY
247# define EV_VERIFY !EV_MINIMAL
248#endif
249
240#ifndef EV_USE_4HEAP 250#ifndef EV_USE_4HEAP
241# define EV_USE_4HEAP !EV_MINIMAL 251# define EV_USE_4HEAP !EV_MINIMAL
242#endif 252#endif
243 253
244#ifndef EV_HEAP_CACHE_AT 254#ifndef EV_HEAP_CACHE_AT
288# endif 298# endif
289#endif 299#endif
290 300
291/**/ 301/**/
292 302
293/* undefined or zero: no verification done or available */
294/* 1 or higher: ev_loop_verify function available */
295/* 2 or higher: ev_loop_verify is called frequently */
296#define EV_VERIFY 1
297
298#if EV_VERIFY > 1 303#if EV_VERIFY >= 3
299# define EV_FREQUENT_CHECK ev_loop_verify (EV_A) 304# define EV_FREQUENT_CHECK ev_loop_verify (EV_A)
300#else 305#else
301# define EV_FREQUENT_CHECK do { } while (0) 306# define EV_FREQUENT_CHECK do { } while (0)
302#endif 307#endif
303 308
1478 1483
1479 postfork = 0; 1484 postfork = 0;
1480} 1485}
1481 1486
1482#if EV_MULTIPLICITY 1487#if EV_MULTIPLICITY
1488
1483struct ev_loop * 1489struct ev_loop *
1484ev_loop_new (unsigned int flags) 1490ev_loop_new (unsigned int flags)
1485{ 1491{
1486 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 1492 struct ev_loop *loop = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
1487 1493
1513array_check (W **ws, int cnt) 1519array_check (W **ws, int cnt)
1514{ 1520{
1515 while (cnt--) 1521 while (cnt--)
1516 assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 1522 assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1));
1517} 1523}
1524#endif
1518 1525
1519static void 1526void
1520ev_loop_verify (EV_P) 1527ev_loop_verify (EV_P)
1521{ 1528{
1529#if EV_VERIFY
1522 int i; 1530 int i;
1523 1531
1524 checkheap (timers, timercnt); 1532 checkheap (timers, timercnt);
1525#if EV_PERIODIC_ENABLE 1533#if EV_PERIODIC_ENABLE
1526 checkheap (periodics, periodiccnt); 1534 checkheap (periodics, periodiccnt);
1531 array_check ((W **)idles [i], idlecnt [i]); 1539 array_check ((W **)idles [i], idlecnt [i]);
1532#endif 1540#endif
1533#if EV_FORK_ENABLE 1541#if EV_FORK_ENABLE
1534 array_check ((W **)forks, forkcnt); 1542 array_check ((W **)forks, forkcnt);
1535#endif 1543#endif
1544#if EV_ASYNC_ENABLE
1545 array_check ((W **)asyncs, asynccnt);
1546#endif
1536 array_check ((W **)prepares, preparecnt); 1547 array_check ((W **)prepares, preparecnt);
1537 array_check ((W **)checks, checkcnt); 1548 array_check ((W **)checks, checkcnt);
1538#if EV_ASYNC_ENABLE
1539 array_check ((W **)asyncs, asynccnt);
1540#endif 1549#endif
1541} 1550}
1542#endif
1543 1551
1544#endif 1552#endif /* multiplicity */
1545 1553
1546#if EV_MULTIPLICITY 1554#if EV_MULTIPLICITY
1547struct ev_loop * 1555struct ev_loop *
1548ev_default_loop_init (unsigned int flags) 1556ev_default_loop_init (unsigned int flags)
1549#else 1557#else
1614void inline_speed 1622void inline_speed
1615call_pending (EV_P) 1623call_pending (EV_P)
1616{ 1624{
1617 int pri; 1625 int pri;
1618 1626
1619 EV_FREQUENT_CHECK;
1620
1621 for (pri = NUMPRI; pri--; ) 1627 for (pri = NUMPRI; pri--; )
1622 while (pendingcnt [pri]) 1628 while (pendingcnt [pri])
1623 { 1629 {
1624 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 1630 ANPENDING *p = pendings [pri] + --pendingcnt [pri];
1625 1631
1627 { 1633 {
1628 /*assert (("non-pending watcher on pending list", p->w->pending));*/ 1634 /*assert (("non-pending watcher on pending list", p->w->pending));*/
1629 1635
1630 p->w->pending = 0; 1636 p->w->pending = 0;
1631 EV_CB_INVOKE (p->w, p->events); 1637 EV_CB_INVOKE (p->w, p->events);
1638 EV_FREQUENT_CHECK;
1632 } 1639 }
1633 } 1640 }
1634
1635 EV_FREQUENT_CHECK;
1636} 1641}
1637 1642
1638#if EV_IDLE_ENABLE 1643#if EV_IDLE_ENABLE
1639void inline_size 1644void inline_size
1640idle_reify (EV_P) 1645idle_reify (EV_P)
1692#if EV_PERIODIC_ENABLE 1697#if EV_PERIODIC_ENABLE
1693void inline_size 1698void inline_size
1694periodics_reify (EV_P) 1699periodics_reify (EV_P)
1695{ 1700{
1696 EV_FREQUENT_CHECK; 1701 EV_FREQUENT_CHECK;
1702
1697 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) 1703 while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now)
1698 { 1704 {
1699 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); 1705 ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]);
1700 1706
1701 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ 1707 /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/
1707 1713
1708 assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now)); 1714 assert (("ev_periodic reschedule callback returned time in the past", ev_at (w) >= ev_rt_now));
1709 1715
1710 ANHE_at_cache (periodics [HEAP0]); 1716 ANHE_at_cache (periodics [HEAP0]);
1711 downheap (periodics, periodiccnt, HEAP0); 1717 downheap (periodics, periodiccnt, HEAP0);
1712 EV_FREQUENT_CHECK;
1713 } 1718 }
1714 else if (w->interval) 1719 else if (w->interval)
1715 { 1720 {
1716 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; 1721 ev_at (w) = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1717 /* if next trigger time is not sufficiently in the future, put it there */ 1722 /* if next trigger time is not sufficiently in the future, put it there */
1853 1858
1854 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */ 1859 call_pending (EV_A); /* in case we recurse, ensure ordering stays nice and clean */
1855 1860
1856 do 1861 do
1857 { 1862 {
1863#if EV_VERIFY >= 2
1864 ev_loop_verify (EV_A);
1865#endif
1866
1858#ifndef _WIN32 1867#ifndef _WIN32
1859 if (expect_false (curpid)) /* penalise the forking check even more */ 1868 if (expect_false (curpid)) /* penalise the forking check even more */
1860 if (expect_false (getpid () != curpid)) 1869 if (expect_false (getpid () != curpid))
1861 { 1870 {
1862 curpid = getpid (); 1871 curpid = getpid ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines