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.251 by root, Thu May 22 03:42:34 2008 UTC

937/* rebuild the heap: this function is used only once and executed rarely */ 937/* rebuild the heap: this function is used only once and executed rarely */
938void inline_size 938void inline_size
939reheap (ANHE *heap, int N) 939reheap (ANHE *heap, int N)
940{ 940{
941 int i; 941 int i;
942
942 /* we don't use floyds algorithm, upheap is simpler and is more cache-efficient */ 943 /* 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 */ 944 /* also, this is easy to implement and correct for both 2-heaps and 4-heaps */
944 for (i = 0; i < N; ++i) 945 for (i = 0; i < N; ++i)
945 upheap (heap, i + HEAP0); 946 upheap (heap, i + HEAP0);
946} 947}
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 948
963/*****************************************************************************/ 949/*****************************************************************************/
964 950
965typedef struct 951typedef struct
966{ 952{
1513{ 1499{
1514 postfork = 1; /* must be in line with ev_default_fork */ 1500 postfork = 1; /* must be in line with ev_default_fork */
1515} 1501}
1516 1502
1517#if EV_VERIFY 1503#if EV_VERIFY
1518static void 1504void noinline
1505verify_watcher (EV_P_ W w)
1506{
1507 assert (("watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
1508
1509 if (w->pending)
1510 assert (("pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
1511}
1512
1513static void noinline
1514verify_heap (EV_P_ ANHE *heap, int N)
1515{
1516 int i;
1517
1518 for (i = HEAP0; i < N + HEAP0; ++i)
1519 {
1520 assert (("active index mismatch in heap", ev_active (ANHE_w (heap [i])) == i));
1521 assert (("heap condition violated", i == HEAP0 || ANHE_at (heap [HPARENT (i)]) <= ANHE_at (heap [i])));
1522 assert (("heap at cache mismatch", ANHE_at (heap [i]) == ev_at (ANHE_w (heap [i]))));
1523
1524 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
1525 }
1526}
1527
1528static void noinline
1519array_check (W **ws, int cnt) 1529array_verify (EV_P_ W *ws, int cnt)
1520{ 1530{
1521 while (cnt--) 1531 while (cnt--)
1532 {
1522 assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 1533 assert (("active index mismatch", ev_active (ws [cnt]) == cnt + 1));
1534 verify_watcher (EV_A_ ws [cnt]);
1535 }
1523} 1536}
1524#endif 1537#endif
1525 1538
1526void 1539void
1527ev_loop_verify (EV_P) 1540ev_loop_verify (EV_P)
1528{ 1541{
1529#if EV_VERIFY 1542#if EV_VERIFY
1530 int i; 1543 int i;
1544 WL w;
1531 1545
1546 assert (activecnt >= -1);
1547
1548 assert (fdchangemax >= fdchangecnt);
1549 for (i = 0; i < fdchangecnt; ++i)
1550 assert (("negative fd in fdchanges", fdchanges [i] >= 0));
1551
1552 assert (anfdmax >= 0);
1553 for (i = 0; i < anfdmax; ++i)
1554 for (w = anfds [i].head; w; w = w->next)
1555 {
1556 verify_watcher (EV_A_ (W)w);
1557 assert (("inactive fd watcher on anfd list", ev_active (w) == 1));
1558 assert (("fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
1559 }
1560
1561 assert (timermax >= timercnt);
1532 checkheap (timers, timercnt); 1562 verify_heap (EV_A_ timers, timercnt);
1563
1533#if EV_PERIODIC_ENABLE 1564#if EV_PERIODIC_ENABLE
1565 assert (periodicmax >= periodiccnt);
1534 checkheap (periodics, periodiccnt); 1566 verify_heap (EV_A_ periodics, periodiccnt);
1535#endif 1567#endif
1536 1568
1569 for (i = NUMPRI; i--; )
1570 {
1571 assert (pendingmax [i] >= pendingcnt [i]);
1537#if EV_IDLE_ENABLE 1572#if EV_IDLE_ENABLE
1538 for (i = NUMPRI; i--; ) 1573 assert (idlemax [i] >= idlecnt [i]);
1539 array_check ((W **)idles [i], idlecnt [i]); 1574 array_verify (EV_A_ (W *)idles [i], idlecnt [i]);
1540#endif 1575#endif
1576 }
1577
1541#if EV_FORK_ENABLE 1578#if EV_FORK_ENABLE
1579 assert (forkmax >= forkcnt);
1542 array_check ((W **)forks, forkcnt); 1580 array_verify (EV_A_ (W *)forks, forkcnt);
1543#endif 1581#endif
1582
1544#if EV_ASYNC_ENABLE 1583#if EV_ASYNC_ENABLE
1584 assert (asyncmax >= asynccnt);
1545 array_check ((W **)asyncs, asynccnt); 1585 array_verify (EV_A_ (W *)asyncs, asynccnt);
1586#endif
1587
1588 assert (preparemax >= preparecnt);
1589 array_verify (EV_A_ (W *)prepares, preparecnt);
1590
1591 assert (checkmax >= checkcnt);
1592 array_verify (EV_A_ (W *)checks, checkcnt);
1593
1594# if 0
1595 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
1596 for (signum = signalmax; signum--; ) if (signals [signum].gotsig)
1546#endif 1597# endif
1547 array_check ((W **)prepares, preparecnt);
1548 array_check ((W **)checks, checkcnt);
1549#endif 1598#endif
1550} 1599}
1551 1600
1552#endif /* multiplicity */ 1601#endif /* multiplicity */
1553 1602

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines