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

Comparing libev/ev.c (file contents):
Revision 1.250 by root, Thu May 22 02:44:57 2008 UTC vs.
Revision 1.253 by root, Sat May 31 03:13:27 2008 UTC

164#endif 164#endif
165 165
166/* this block tries to deduce configuration from header-defined symbols and defaults */ 166/* this block tries to deduce configuration from header-defined symbols and defaults */
167 167
168#ifndef EV_USE_MONOTONIC 168#ifndef EV_USE_MONOTONIC
169# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0
170# define EV_USE_MONOTONIC 1
171# else
169# define EV_USE_MONOTONIC 0 172# define EV_USE_MONOTONIC 0
173# endif
170#endif 174#endif
171 175
172#ifndef EV_USE_REALTIME 176#ifndef EV_USE_REALTIME
173# define EV_USE_REALTIME 0 177# define EV_USE_REALTIME 0
174#endif 178#endif
175 179
176#ifndef EV_USE_NANOSLEEP 180#ifndef EV_USE_NANOSLEEP
181# if _POSIX_C_SOURCE >= 199309L
182# define EV_USE_NANOSLEEP 1
183# else
177# define EV_USE_NANOSLEEP 0 184# define EV_USE_NANOSLEEP 0
185# endif
178#endif 186#endif
179 187
180#ifndef EV_USE_SELECT 188#ifndef EV_USE_SELECT
181# define EV_USE_SELECT 1 189# define EV_USE_SELECT 1
182#endif 190#endif
937/* rebuild the heap: this function is used only once and executed rarely */ 945/* rebuild the heap: this function is used only once and executed rarely */
938void inline_size 946void inline_size
939reheap (ANHE *heap, int N) 947reheap (ANHE *heap, int N)
940{ 948{
941 int i; 949 int i;
950
942 /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */ 951 /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */
943 /* also, this is easy to implement and correct for both 2-heaps and 4-heaps */ 952 /* also, this is easy to implement and correct for both 2-heaps and 4-heaps */
944 for (i = 0; i < N; ++i) 953 for (i = 0; i < N; ++i)
945 upheap (heap, i + HEAP0); 954 upheap (heap, i + HEAP0);
946} 955}
947
948#if EV_VERIFY
949static void
950checkheap (ANHE *heap, int N)
951{
952 int i;
953
954 for (i = HEAP0; i < N + HEAP0; ++i)
955 {
956 assert (("active index mismatch in heap", ev_active (ANHE_w (heap [i])) == i));
957 assert (("heap condition violated", i == HEAP0 || ANHE_at (heap [HPARENT (i)]) <= ANHE_at (heap [i])));
958 assert (("heap at cache mismatch", ANHE_at (heap [i]) == ev_at (ANHE_w (heap [i]))));
959 }
960}
961#endif
962 956
963/*****************************************************************************/ 957/*****************************************************************************/
964 958
965typedef struct 959typedef struct
966{ 960{
1513{ 1507{
1514 postfork = 1; /* must be in line with ev_default_fork */ 1508 postfork = 1; /* must be in line with ev_default_fork */
1515} 1509}
1516 1510
1517#if EV_VERIFY 1511#if EV_VERIFY
1518static void 1512void noinline
1513verify_watcher (EV_P_ W w)
1514{
1515 assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
1516
1517 if (w->pending)
1518 assert (("pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
1519}
1520
1521static void noinline
1522verify_heap (EV_P_ ANHE *heap, int N)
1523{
1524 int i;
1525
1526 for (i = HEAP0; i < N + HEAP0; ++i)
1527 {
1528 assert (("active index mismatch in heap", ev_active (ANHE_w (heap [i])) == i));
1529 assert (("heap condition violated", i == HEAP0 || ANHE_at (heap [HPARENT (i)]) <= ANHE_at (heap [i])));
1530 assert (("heap at cache mismatch", ANHE_at (heap [i]) == ev_at (ANHE_w (heap [i]))));
1531
1532 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
1533 }
1534}
1535
1536static void noinline
1519array_check (W **ws, int cnt) 1537array_verify (EV_P_ W *ws, int cnt)
1520{ 1538{
1521 while (cnt--) 1539 while (cnt--)
1540 {
1522 assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 1541 assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1));
1542 verify_watcher (EV_A_ ws [cnt]);
1543 }
1523} 1544}
1524#endif 1545#endif
1525 1546
1526void 1547void
1527ev_loop_verify (EV_P) 1548ev_loop_verify (EV_P)
1528{ 1549{
1529#if EV_VERIFY 1550#if EV_VERIFY
1530 int i; 1551 int i;
1552 WL w;
1531 1553
1554 assert (activecnt >= -1);
1555
1556 assert (fdchangemax >= fdchangecnt);
1557 for (i = 0; i < fdchangecnt; ++i)
1558 assert (("negative fd in fdchanges", fdchanges [i] >= 0));
1559
1560 assert (anfdmax >= 0);
1561 for (i = 0; i < anfdmax; ++i)
1562 for (w = anfds [i].head; w; w = w->next)
1563 {
1564 verify_watcher (EV_A_ (W)w);
1565 assert (("inactive fd watcher on anfd list", ev_active (w) == 1));
1566 assert (("fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
1567 }
1568
1569 assert (timermax >= timercnt);
1532 checkheap (timers, timercnt); 1570 verify_heap (EV_A_ timers, timercnt);
1571
1533#if EV_PERIODIC_ENABLE 1572#if EV_PERIODIC_ENABLE
1573 assert (periodicmax >= periodiccnt);
1534 checkheap (periodics, periodiccnt); 1574 verify_heap (EV_A_ periodics, periodiccnt);
1535#endif 1575#endif
1536 1576
1577 for (i = NUMPRI; i--; )
1578 {
1579 assert (pendingmax [i] >= pendingcnt [i]);
1537#if EV_IDLE_ENABLE 1580#if EV_IDLE_ENABLE
1538 for (i = NUMPRI; i--; ) 1581 assert (idleall >= 0);
1582 assert (idlemax [i] >= idlecnt [i]);
1539 array_check ((W **)idles [i], idlecnt [i]); 1583 array_verify (EV_A_ (W *)idles [i], idlecnt [i]);
1540#endif 1584#endif
1585 }
1586
1541#if EV_FORK_ENABLE 1587#if EV_FORK_ENABLE
1588 assert (forkmax >= forkcnt);
1542 array_check ((W **)forks, forkcnt); 1589 array_verify (EV_A_ (W *)forks, forkcnt);
1543#endif 1590#endif
1591
1544#if EV_ASYNC_ENABLE 1592#if EV_ASYNC_ENABLE
1593 assert (asyncmax >= asynccnt);
1545 array_check ((W **)asyncs, asynccnt); 1594 array_verify (EV_A_ (W *)asyncs, asynccnt);
1595#endif
1596
1597 assert (preparemax >= preparecnt);
1598 array_verify (EV_A_ (W *)prepares, preparecnt);
1599
1600 assert (checkmax >= checkcnt);
1601 array_verify (EV_A_ (W *)checks, checkcnt);
1602
1603# if 0
1604 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
1605 for (signum = signalmax; signum--; ) if (signals [signum].gotsig)
1546#endif 1606# endif
1547 array_check ((W **)prepares, preparecnt);
1548 array_check ((W **)checks, checkcnt);
1549#endif 1607#endif
1550} 1608}
1551 1609
1552#endif /* multiplicity */ 1610#endif /* multiplicity */
1553 1611

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines