… | |
… | |
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 */ |
938 | void inline_size |
938 | void inline_size |
939 | reheap (ANHE *heap, int N) |
939 | reheap (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 |
|
|
949 | static void |
|
|
950 | checkheap (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 | |
965 | typedef struct |
951 | typedef 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 |
1518 | static void |
1504 | void noinline |
|
|
1505 | verify_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 | |
|
|
1513 | static void noinline |
|
|
1514 | verify_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 | |
|
|
1528 | static void noinline |
1519 | array_check (W **ws, int cnt) |
1529 | array_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 | |
1526 | void |
1539 | void |
1527 | ev_loop_verify (EV_P) |
1540 | ev_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 (idleall >= 0); |
|
|
1574 | assert (idlemax [i] >= idlecnt [i]); |
1539 | array_check ((W **)idles [i], idlecnt [i]); |
1575 | array_verify (EV_A_ (W *)idles [i], idlecnt [i]); |
1540 | #endif |
1576 | #endif |
|
|
1577 | } |
|
|
1578 | |
1541 | #if EV_FORK_ENABLE |
1579 | #if EV_FORK_ENABLE |
|
|
1580 | assert (forkmax >= forkcnt); |
1542 | array_check ((W **)forks, forkcnt); |
1581 | array_verify (EV_A_ (W *)forks, forkcnt); |
1543 | #endif |
1582 | #endif |
|
|
1583 | |
1544 | #if EV_ASYNC_ENABLE |
1584 | #if EV_ASYNC_ENABLE |
|
|
1585 | assert (asyncmax >= asynccnt); |
1545 | array_check ((W **)asyncs, asynccnt); |
1586 | array_verify (EV_A_ (W *)asyncs, asynccnt); |
|
|
1587 | #endif |
|
|
1588 | |
|
|
1589 | assert (preparemax >= preparecnt); |
|
|
1590 | array_verify (EV_A_ (W *)prepares, preparecnt); |
|
|
1591 | |
|
|
1592 | assert (checkmax >= checkcnt); |
|
|
1593 | array_verify (EV_A_ (W *)checks, checkcnt); |
|
|
1594 | |
|
|
1595 | # if 0 |
|
|
1596 | for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) |
|
|
1597 | for (signum = signalmax; signum--; ) if (signals [signum].gotsig) |
1546 | #endif |
1598 | # endif |
1547 | array_check ((W **)prepares, preparecnt); |
|
|
1548 | array_check ((W **)checks, checkcnt); |
|
|
1549 | #endif |
1599 | #endif |
1550 | } |
1600 | } |
1551 | |
1601 | |
1552 | #endif /* multiplicity */ |
1602 | #endif /* multiplicity */ |
1553 | |
1603 | |