… | |
… | |
1074 | { |
1074 | { |
1075 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1075 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
1076 | |
1076 | |
1077 | if (expect_true (p->w)) |
1077 | if (expect_true (p->w)) |
1078 | { |
1078 | { |
|
|
1079 | assert (("non-pending watcher on pending list", p->w->pending)); |
|
|
1080 | |
1079 | p->w->pending = 0; |
1081 | p->w->pending = 0; |
1080 | EV_CB_INVOKE (p->w, p->events); |
1082 | EV_CB_INVOKE (p->w, p->events); |
1081 | } |
1083 | } |
1082 | } |
1084 | } |
1083 | } |
1085 | } |
… | |
… | |
1189 | { |
1191 | { |
1190 | if (time_update_monotonic (EV_A)) |
1192 | if (time_update_monotonic (EV_A)) |
1191 | { |
1193 | { |
1192 | ev_tstamp odiff = rtmn_diff; |
1194 | ev_tstamp odiff = rtmn_diff; |
1193 | |
1195 | |
1194 | for (i = 4; --i; ) /* loop a few times, before making important decisions */ |
1196 | /* loop a few times, before making important decisions. |
|
|
1197 | * on the choice of "4": one iteration isn't enough, |
|
|
1198 | * in case we get preempted during the calls to |
|
|
1199 | * ev_time and get_clock. a second call is almost guarenteed |
|
|
1200 | * to succeed in that case, though. and looping a few more times |
|
|
1201 | * doesn't hurt either as we only do this on time-jumps or |
|
|
1202 | * in the unlikely event of getting preempted here. |
|
|
1203 | */ |
|
|
1204 | for (i = 4; --i; ) |
1195 | { |
1205 | { |
1196 | rtmn_diff = ev_rt_now - mn_now; |
1206 | rtmn_diff = ev_rt_now - mn_now; |
1197 | |
1207 | |
1198 | if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) |
1208 | if (fabs (odiff - rtmn_diff) < MIN_TIMEJUMP) |
1199 | return; /* all is well */ |
1209 | return; /* all is well */ |
… | |
… | |
1315 | timers_reify (EV_A); /* relative timers called last */ |
1325 | timers_reify (EV_A); /* relative timers called last */ |
1316 | #if EV_PERIODICS |
1326 | #if EV_PERIODICS |
1317 | periodics_reify (EV_A); /* absolute timers called first */ |
1327 | periodics_reify (EV_A); /* absolute timers called first */ |
1318 | #endif |
1328 | #endif |
1319 | |
1329 | |
1320 | /* queue idle watchers unless io or timers are pending */ |
1330 | /* queue idle watchers unless other events are pending */ |
1321 | if (idlecnt && !any_pending (EV_A)) |
1331 | if (idlecnt && !any_pending (EV_A)) |
1322 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1332 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1323 | |
1333 | |
1324 | /* queue check watchers, to be executed first */ |
1334 | /* queue check watchers, to be executed first */ |
1325 | if (expect_false (checkcnt)) |
1335 | if (expect_false (checkcnt)) |
… | |
… | |
1551 | { |
1561 | { |
1552 | ev_clear_pending (EV_A_ (W)w); |
1562 | ev_clear_pending (EV_A_ (W)w); |
1553 | if (expect_false (!ev_is_active (w))) |
1563 | if (expect_false (!ev_is_active (w))) |
1554 | return; |
1564 | return; |
1555 | |
1565 | |
|
|
1566 | { |
|
|
1567 | int active = ((W)w)->active; |
1556 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1568 | idles [active - 1] = idles [--idlecnt]; |
|
|
1569 | ((W)idles [active - 1])->active = active; |
|
|
1570 | } |
|
|
1571 | |
1557 | ev_stop (EV_A_ (W)w); |
1572 | ev_stop (EV_A_ (W)w); |
1558 | } |
1573 | } |
1559 | |
1574 | |
1560 | void |
1575 | void |
1561 | ev_prepare_start (EV_P_ ev_prepare *w) |
1576 | ev_prepare_start (EV_P_ ev_prepare *w) |
… | |
… | |
1573 | { |
1588 | { |
1574 | ev_clear_pending (EV_A_ (W)w); |
1589 | ev_clear_pending (EV_A_ (W)w); |
1575 | if (expect_false (!ev_is_active (w))) |
1590 | if (expect_false (!ev_is_active (w))) |
1576 | return; |
1591 | return; |
1577 | |
1592 | |
|
|
1593 | { |
|
|
1594 | int active = ((W)w)->active; |
1578 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1595 | prepares [active - 1] = prepares [--preparecnt]; |
|
|
1596 | ((W)prepares [active - 1])->active = active; |
|
|
1597 | } |
|
|
1598 | |
1579 | ev_stop (EV_A_ (W)w); |
1599 | ev_stop (EV_A_ (W)w); |
1580 | } |
1600 | } |
1581 | |
1601 | |
1582 | void |
1602 | void |
1583 | ev_check_start (EV_P_ ev_check *w) |
1603 | ev_check_start (EV_P_ ev_check *w) |
… | |
… | |
1595 | { |
1615 | { |
1596 | ev_clear_pending (EV_A_ (W)w); |
1616 | ev_clear_pending (EV_A_ (W)w); |
1597 | if (expect_false (!ev_is_active (w))) |
1617 | if (expect_false (!ev_is_active (w))) |
1598 | return; |
1618 | return; |
1599 | |
1619 | |
|
|
1620 | { |
|
|
1621 | int active = ((W)w)->active; |
1600 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1622 | checks [active - 1] = checks [--checkcnt]; |
|
|
1623 | ((W)checks [active - 1])->active = active; |
|
|
1624 | } |
|
|
1625 | |
1601 | ev_stop (EV_A_ (W)w); |
1626 | ev_stop (EV_A_ (W)w); |
1602 | } |
1627 | } |
1603 | |
1628 | |
1604 | #ifndef SA_RESTART |
1629 | #ifndef SA_RESTART |
1605 | # define SA_RESTART 0 |
1630 | # define SA_RESTART 0 |
… | |
… | |
1672 | ev_stop (EV_A_ (W)w); |
1697 | ev_stop (EV_A_ (W)w); |
1673 | } |
1698 | } |
1674 | |
1699 | |
1675 | #if EV_MULTIPLICITY |
1700 | #if EV_MULTIPLICITY |
1676 | void |
1701 | void |
1677 | ev_embed_loop (EV_P_ ev_embed *w) |
1702 | ev_embed_sweep (EV_P_ ev_embed *w) |
1678 | { |
1703 | { |
1679 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
1704 | ev_loop (w->loop, EVLOOP_NONBLOCK); |
1680 | } |
1705 | } |
1681 | |
1706 | |
1682 | static void |
1707 | static void |
… | |
… | |
1685 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
1710 | ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io)); |
1686 | |
1711 | |
1687 | if (ev_cb (w)) |
1712 | if (ev_cb (w)) |
1688 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
1713 | ev_feed_event (EV_A_ (W)w, EV_EMBED); |
1689 | else |
1714 | else |
1690 | ev_embed_loop (loop, w); |
1715 | ev_embed_sweep (loop, w); |
1691 | } |
1716 | } |
1692 | |
1717 | |
1693 | void |
1718 | void |
1694 | ev_embed_start (EV_P_ ev_embed *w) |
1719 | ev_embed_start (EV_P_ ev_embed *w) |
1695 | { |
1720 | { |