… | |
… | |
39 | # if HAVE_CLOCK_GETTIME |
39 | # if HAVE_CLOCK_GETTIME |
40 | # define EV_USE_MONOTONIC 1 |
40 | # define EV_USE_MONOTONIC 1 |
41 | # define EV_USE_REALTIME 1 |
41 | # define EV_USE_REALTIME 1 |
42 | # endif |
42 | # endif |
43 | |
43 | |
44 | # if HAVE_SELECT && HAVE_SYS_SELECT_H |
44 | # if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) |
45 | # define EV_USE_SELECT 1 |
45 | # define EV_USE_SELECT 1 |
46 | # endif |
46 | # endif |
47 | |
47 | |
48 | # if HAVE_POLL && HAVE_POLL_H |
48 | # if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) |
49 | # define EV_USE_POLL 1 |
49 | # define EV_USE_POLL 1 |
50 | # endif |
50 | # endif |
51 | |
51 | |
52 | # if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H |
52 | # if HAVE_EPOLL && HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) |
53 | # define EV_USE_EPOLL 1 |
53 | # define EV_USE_EPOLL 1 |
54 | # endif |
54 | # endif |
55 | |
55 | |
56 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H |
56 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
57 | # define EV_USE_KQUEUE 1 |
57 | # define EV_USE_KQUEUE 1 |
58 | # endif |
58 | # endif |
59 | |
59 | |
60 | #endif |
60 | #endif |
61 | |
61 | |
… | |
… | |
249 | |
249 | |
250 | #endif |
250 | #endif |
251 | |
251 | |
252 | /*****************************************************************************/ |
252 | /*****************************************************************************/ |
253 | |
253 | |
254 | inline ev_tstamp |
254 | ev_tstamp |
255 | ev_time (void) |
255 | ev_time (void) |
256 | { |
256 | { |
257 | #if EV_USE_REALTIME |
257 | #if EV_USE_REALTIME |
258 | struct timespec ts; |
258 | struct timespec ts; |
259 | clock_gettime (CLOCK_REALTIME, &ts); |
259 | clock_gettime (CLOCK_REALTIME, &ts); |
… | |
… | |
804 | array_free (pending, [i]); |
804 | array_free (pending, [i]); |
805 | |
805 | |
806 | /* have to use the microsoft-never-gets-it-right macro */ |
806 | /* have to use the microsoft-never-gets-it-right macro */ |
807 | array_free_microshit (fdchange); |
807 | array_free_microshit (fdchange); |
808 | array_free_microshit (timer); |
808 | array_free_microshit (timer); |
|
|
809 | #if EV_PERIODICS |
809 | array_free_microshit (periodic); |
810 | array_free_microshit (periodic); |
|
|
811 | #endif |
810 | array_free_microshit (idle); |
812 | array_free_microshit (idle); |
811 | array_free_microshit (prepare); |
813 | array_free_microshit (prepare); |
812 | array_free_microshit (check); |
814 | array_free_microshit (check); |
813 | |
815 | |
814 | method = 0; |
816 | method = 0; |
… | |
… | |
1001 | |
1003 | |
1002 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1004 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1003 | } |
1005 | } |
1004 | } |
1006 | } |
1005 | |
1007 | |
|
|
1008 | #if EV_PERIODICS |
1006 | static void |
1009 | static void |
1007 | periodics_reify (EV_P) |
1010 | periodics_reify (EV_P) |
1008 | { |
1011 | { |
1009 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1012 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1010 | { |
1013 | { |
… | |
… | |
1051 | |
1054 | |
1052 | /* now rebuild the heap */ |
1055 | /* now rebuild the heap */ |
1053 | for (i = periodiccnt >> 1; i--; ) |
1056 | for (i = periodiccnt >> 1; i--; ) |
1054 | downheap ((WT *)periodics, periodiccnt, i); |
1057 | downheap ((WT *)periodics, periodiccnt, i); |
1055 | } |
1058 | } |
|
|
1059 | #endif |
1056 | |
1060 | |
1057 | inline int |
1061 | inline int |
1058 | time_update_monotonic (EV_P) |
1062 | time_update_monotonic (EV_P) |
1059 | { |
1063 | { |
1060 | mn_now = get_clock (); |
1064 | mn_now = get_clock (); |
… | |
… | |
1094 | ev_rt_now = ev_time (); |
1098 | ev_rt_now = ev_time (); |
1095 | mn_now = get_clock (); |
1099 | mn_now = get_clock (); |
1096 | now_floor = mn_now; |
1100 | now_floor = mn_now; |
1097 | } |
1101 | } |
1098 | |
1102 | |
|
|
1103 | # if EV_PERIODICS |
1099 | periodics_reschedule (EV_A); |
1104 | periodics_reschedule (EV_A); |
|
|
1105 | # endif |
1100 | /* no timer adjustment, as the monotonic clock doesn't jump */ |
1106 | /* no timer adjustment, as the monotonic clock doesn't jump */ |
1101 | /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ |
1107 | /* timers_reschedule (EV_A_ rtmn_diff - odiff) */ |
1102 | } |
1108 | } |
1103 | } |
1109 | } |
1104 | else |
1110 | else |
… | |
… | |
1106 | { |
1112 | { |
1107 | ev_rt_now = ev_time (); |
1113 | ev_rt_now = ev_time (); |
1108 | |
1114 | |
1109 | if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) |
1115 | if (expect_false (mn_now > ev_rt_now || mn_now < ev_rt_now - MAX_BLOCKTIME - MIN_TIMEJUMP)) |
1110 | { |
1116 | { |
|
|
1117 | #if EV_PERIODICS |
1111 | periodics_reschedule (EV_A); |
1118 | periodics_reschedule (EV_A); |
|
|
1119 | #endif |
1112 | |
1120 | |
1113 | /* adjust timers. this is easy, as the offset is the same for all */ |
1121 | /* adjust timers. this is easy, as the offset is the same for all */ |
1114 | for (i = 0; i < timercnt; ++i) |
1122 | for (i = 0; i < timercnt; ++i) |
1115 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1123 | ((WT)timers [i])->at += ev_rt_now - mn_now; |
1116 | } |
1124 | } |
… | |
… | |
1179 | { |
1187 | { |
1180 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
1188 | ev_tstamp to = ((WT)timers [0])->at - mn_now + method_fudge; |
1181 | if (block > to) block = to; |
1189 | if (block > to) block = to; |
1182 | } |
1190 | } |
1183 | |
1191 | |
|
|
1192 | #if EV_PERIODICS |
1184 | if (periodiccnt) |
1193 | if (periodiccnt) |
1185 | { |
1194 | { |
1186 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1195 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1187 | if (block > to) block = to; |
1196 | if (block > to) block = to; |
1188 | } |
1197 | } |
|
|
1198 | #endif |
1189 | |
1199 | |
1190 | if (block < 0.) block = 0.; |
1200 | if (block < 0.) block = 0.; |
1191 | } |
1201 | } |
1192 | |
1202 | |
1193 | method_poll (EV_A_ block); |
1203 | method_poll (EV_A_ block); |
… | |
… | |
1195 | /* update ev_rt_now, do magic */ |
1205 | /* update ev_rt_now, do magic */ |
1196 | time_update (EV_A); |
1206 | time_update (EV_A); |
1197 | |
1207 | |
1198 | /* queue pending timers and reschedule them */ |
1208 | /* queue pending timers and reschedule them */ |
1199 | timers_reify (EV_A); /* relative timers called last */ |
1209 | timers_reify (EV_A); /* relative timers called last */ |
|
|
1210 | #if EV_PERIODICS |
1200 | periodics_reify (EV_A); /* absolute timers called first */ |
1211 | periodics_reify (EV_A); /* absolute timers called first */ |
|
|
1212 | #endif |
1201 | |
1213 | |
1202 | /* queue idle watchers unless io or timers are pending */ |
1214 | /* queue idle watchers unless io or timers are pending */ |
1203 | if (idlecnt && !any_pending (EV_A)) |
1215 | if (idlecnt && !any_pending (EV_A)) |
1204 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1216 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1205 | |
1217 | |
… | |
… | |
1356 | } |
1368 | } |
1357 | else if (w->repeat) |
1369 | else if (w->repeat) |
1358 | ev_timer_start (EV_A_ w); |
1370 | ev_timer_start (EV_A_ w); |
1359 | } |
1371 | } |
1360 | |
1372 | |
|
|
1373 | #if EV_PERIODICS |
1361 | void |
1374 | void |
1362 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1375 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1363 | { |
1376 | { |
1364 | if (ev_is_active (w)) |
1377 | if (ev_is_active (w)) |
1365 | return; |
1378 | return; |
… | |
… | |
1404 | { |
1417 | { |
1405 | /* TODO: use adjustheap and recalculation */ |
1418 | /* TODO: use adjustheap and recalculation */ |
1406 | ev_periodic_stop (EV_A_ w); |
1419 | ev_periodic_stop (EV_A_ w); |
1407 | ev_periodic_start (EV_A_ w); |
1420 | ev_periodic_start (EV_A_ w); |
1408 | } |
1421 | } |
|
|
1422 | #endif |
1409 | |
1423 | |
1410 | void |
1424 | void |
1411 | ev_idle_start (EV_P_ struct ev_idle *w) |
1425 | ev_idle_start (EV_P_ struct ev_idle *w) |
1412 | { |
1426 | { |
1413 | if (ev_is_active (w)) |
1427 | if (ev_is_active (w)) |
… | |
… | |
1464 | |
1478 | |
1465 | void |
1479 | void |
1466 | ev_check_stop (EV_P_ struct ev_check *w) |
1480 | ev_check_stop (EV_P_ struct ev_check *w) |
1467 | { |
1481 | { |
1468 | ev_clear_pending (EV_A_ (W)w); |
1482 | ev_clear_pending (EV_A_ (W)w); |
1469 | if (ev_is_active (w)) |
1483 | if (!ev_is_active (w)) |
1470 | return; |
1484 | return; |
1471 | |
1485 | |
1472 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1486 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1473 | ev_stop (EV_A_ (W)w); |
1487 | ev_stop (EV_A_ (W)w); |
1474 | } |
1488 | } |
… | |
… | |
1535 | |
1549 | |
1536 | void |
1550 | void |
1537 | ev_child_stop (EV_P_ struct ev_child *w) |
1551 | ev_child_stop (EV_P_ struct ev_child *w) |
1538 | { |
1552 | { |
1539 | ev_clear_pending (EV_A_ (W)w); |
1553 | ev_clear_pending (EV_A_ (W)w); |
1540 | if (ev_is_active (w)) |
1554 | if (!ev_is_active (w)) |
1541 | return; |
1555 | return; |
1542 | |
1556 | |
1543 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1557 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1544 | ev_stop (EV_A_ (W)w); |
1558 | ev_stop (EV_A_ (W)w); |
1545 | } |
1559 | } |