… | |
… | |
652 | k = p; |
652 | k = p; |
653 | } |
653 | } |
654 | |
654 | |
655 | heap [k] = w; |
655 | heap [k] = w; |
656 | ((W)heap [k])->active = k + 1; |
656 | ((W)heap [k])->active = k + 1; |
657 | |
|
|
658 | } |
657 | } |
659 | |
658 | |
660 | void inline_speed |
659 | void inline_speed |
661 | downheap (WT *heap, int N, int k) |
660 | downheap (WT *heap, int N, int k) |
662 | { |
661 | { |
… | |
… | |
1215 | void inline_size |
1214 | void inline_size |
1216 | timers_reify (EV_P) |
1215 | timers_reify (EV_P) |
1217 | { |
1216 | { |
1218 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1217 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1219 | { |
1218 | { |
1220 | ev_timer *w = timers [0]; |
1219 | ev_timer *w = (ev_timer *)timers [0]; |
1221 | |
1220 | |
1222 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1221 | /*assert (("inactive timer on timer heap detected", ev_is_active (w)));*/ |
1223 | |
1222 | |
1224 | /* first reschedule or stop timer */ |
1223 | /* first reschedule or stop timer */ |
1225 | if (w->repeat) |
1224 | if (w->repeat) |
… | |
… | |
1228 | |
1227 | |
1229 | ((WT)w)->at += w->repeat; |
1228 | ((WT)w)->at += w->repeat; |
1230 | if (((WT)w)->at < mn_now) |
1229 | if (((WT)w)->at < mn_now) |
1231 | ((WT)w)->at = mn_now; |
1230 | ((WT)w)->at = mn_now; |
1232 | |
1231 | |
1233 | downheap ((WT *)timers, timercnt, 0); |
1232 | downheap (timers, timercnt, 0); |
1234 | } |
1233 | } |
1235 | else |
1234 | else |
1236 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1235 | ev_timer_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1237 | |
1236 | |
1238 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1237 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
… | |
… | |
1243 | void inline_size |
1242 | void inline_size |
1244 | periodics_reify (EV_P) |
1243 | periodics_reify (EV_P) |
1245 | { |
1244 | { |
1246 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1245 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1247 | { |
1246 | { |
1248 | ev_periodic *w = periodics [0]; |
1247 | ev_periodic *w = (ev_periodic *)periodics [0]; |
1249 | |
1248 | |
1250 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1249 | /*assert (("inactive timer on periodic heap detected", ev_is_active (w)));*/ |
1251 | |
1250 | |
1252 | /* first reschedule or stop timer */ |
1251 | /* first reschedule or stop timer */ |
1253 | if (w->reschedule_cb) |
1252 | if (w->reschedule_cb) |
1254 | { |
1253 | { |
1255 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1254 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now + TIME_EPSILON); |
1256 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1255 | assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); |
1257 | downheap ((WT *)periodics, periodiccnt, 0); |
1256 | downheap (periodics, periodiccnt, 0); |
1258 | } |
1257 | } |
1259 | else if (w->interval) |
1258 | else if (w->interval) |
1260 | { |
1259 | { |
1261 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1260 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1262 | if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; |
1261 | if (((WT)w)->at - ev_rt_now <= TIME_EPSILON) ((WT)w)->at += w->interval; |
1263 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1262 | assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); |
1264 | downheap ((WT *)periodics, periodiccnt, 0); |
1263 | downheap (periodics, periodiccnt, 0); |
1265 | } |
1264 | } |
1266 | else |
1265 | else |
1267 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1266 | ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ |
1268 | |
1267 | |
1269 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
1268 | ev_feed_event (EV_A_ (W)w, EV_PERIODIC); |
… | |
… | |
1276 | int i; |
1275 | int i; |
1277 | |
1276 | |
1278 | /* adjust periodics after time jump */ |
1277 | /* adjust periodics after time jump */ |
1279 | for (i = 0; i < periodiccnt; ++i) |
1278 | for (i = 0; i < periodiccnt; ++i) |
1280 | { |
1279 | { |
1281 | ev_periodic *w = periodics [i]; |
1280 | ev_periodic *w = (ev_periodic *)periodics [i]; |
1282 | |
1281 | |
1283 | if (w->reschedule_cb) |
1282 | if (w->reschedule_cb) |
1284 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1283 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1285 | else if (w->interval) |
1284 | else if (w->interval) |
1286 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1285 | ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval; |
1287 | } |
1286 | } |
1288 | |
1287 | |
1289 | /* now rebuild the heap */ |
1288 | /* now rebuild the heap */ |
1290 | for (i = periodiccnt >> 1; i--; ) |
1289 | for (i = periodiccnt >> 1; i--; ) |
1291 | downheap ((WT *)periodics, periodiccnt, i); |
1290 | downheap (periodics, periodiccnt, i); |
1292 | } |
1291 | } |
1293 | #endif |
1292 | #endif |
1294 | |
1293 | |
1295 | #if EV_IDLE_ENABLE |
1294 | #if EV_IDLE_ENABLE |
1296 | void inline_size |
1295 | void inline_size |
… | |
… | |
1629 | ((WT)w)->at += mn_now; |
1628 | ((WT)w)->at += mn_now; |
1630 | |
1629 | |
1631 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1630 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1632 | |
1631 | |
1633 | ev_start (EV_A_ (W)w, ++timercnt); |
1632 | ev_start (EV_A_ (W)w, ++timercnt); |
1634 | array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2); |
1633 | array_needsize (WT, timers, timermax, timercnt, EMPTY2); |
1635 | timers [timercnt - 1] = w; |
1634 | timers [timercnt - 1] = (WT)w; |
1636 | upheap ((WT *)timers, timercnt - 1); |
1635 | upheap (timers, timercnt - 1); |
1637 | |
1636 | |
1638 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1637 | /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ |
1639 | } |
1638 | } |
1640 | |
1639 | |
1641 | void noinline |
1640 | void noinline |
… | |
… | |
1643 | { |
1642 | { |
1644 | clear_pending (EV_A_ (W)w); |
1643 | clear_pending (EV_A_ (W)w); |
1645 | if (expect_false (!ev_is_active (w))) |
1644 | if (expect_false (!ev_is_active (w))) |
1646 | return; |
1645 | return; |
1647 | |
1646 | |
1648 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1647 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == (WT)w)); |
1649 | |
1648 | |
1650 | { |
1649 | { |
1651 | int active = ((W)w)->active; |
1650 | int active = ((W)w)->active; |
1652 | |
1651 | |
1653 | if (expect_true (--active < --timercnt)) |
1652 | if (expect_true (--active < --timercnt)) |
1654 | { |
1653 | { |
1655 | timers [active] = timers [timercnt]; |
1654 | timers [active] = timers [timercnt]; |
1656 | adjustheap ((WT *)timers, timercnt, active); |
1655 | adjustheap (timers, timercnt, active); |
1657 | } |
1656 | } |
1658 | } |
1657 | } |
1659 | |
1658 | |
1660 | ((WT)w)->at -= mn_now; |
1659 | ((WT)w)->at -= mn_now; |
1661 | |
1660 | |
… | |
… | |
1668 | if (ev_is_active (w)) |
1667 | if (ev_is_active (w)) |
1669 | { |
1668 | { |
1670 | if (w->repeat) |
1669 | if (w->repeat) |
1671 | { |
1670 | { |
1672 | ((WT)w)->at = mn_now + w->repeat; |
1671 | ((WT)w)->at = mn_now + w->repeat; |
1673 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1672 | adjustheap (timers, timercnt, ((W)w)->active - 1); |
1674 | } |
1673 | } |
1675 | else |
1674 | else |
1676 | ev_timer_stop (EV_A_ w); |
1675 | ev_timer_stop (EV_A_ w); |
1677 | } |
1676 | } |
1678 | else if (w->repeat) |
1677 | else if (w->repeat) |
… | |
… | |
1699 | } |
1698 | } |
1700 | else |
1699 | else |
1701 | ((WT)w)->at = w->offset; |
1700 | ((WT)w)->at = w->offset; |
1702 | |
1701 | |
1703 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1702 | ev_start (EV_A_ (W)w, ++periodiccnt); |
1704 | array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); |
1703 | array_needsize (WT, periodics, periodicmax, periodiccnt, EMPTY2); |
1705 | periodics [periodiccnt - 1] = w; |
1704 | periodics [periodiccnt - 1] = (WT)w; |
1706 | upheap ((WT *)periodics, periodiccnt - 1); |
1705 | upheap (periodics, periodiccnt - 1); |
1707 | |
1706 | |
1708 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1707 | /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ |
1709 | } |
1708 | } |
1710 | |
1709 | |
1711 | void noinline |
1710 | void noinline |
… | |
… | |
1713 | { |
1712 | { |
1714 | clear_pending (EV_A_ (W)w); |
1713 | clear_pending (EV_A_ (W)w); |
1715 | if (expect_false (!ev_is_active (w))) |
1714 | if (expect_false (!ev_is_active (w))) |
1716 | return; |
1715 | return; |
1717 | |
1716 | |
1718 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1717 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == (WT)w)); |
1719 | |
1718 | |
1720 | { |
1719 | { |
1721 | int active = ((W)w)->active; |
1720 | int active = ((W)w)->active; |
1722 | |
1721 | |
1723 | if (expect_true (--active < --periodiccnt)) |
1722 | if (expect_true (--active < --periodiccnt)) |
1724 | { |
1723 | { |
1725 | periodics [active] = periodics [periodiccnt]; |
1724 | periodics [active] = periodics [periodiccnt]; |
1726 | adjustheap ((WT *)periodics, periodiccnt, active); |
1725 | adjustheap (periodics, periodiccnt, active); |
1727 | } |
1726 | } |
1728 | } |
1727 | } |
1729 | |
1728 | |
1730 | ev_stop (EV_A_ (W)w); |
1729 | ev_stop (EV_A_ (W)w); |
1731 | } |
1730 | } |