… | |
… | |
35 | |
35 | |
36 | #ifndef EV_STANDALONE |
36 | #ifndef EV_STANDALONE |
37 | # include "config.h" |
37 | # include "config.h" |
38 | |
38 | |
39 | # if HAVE_CLOCK_GETTIME |
39 | # if HAVE_CLOCK_GETTIME |
|
|
40 | # ifndef EV_USE_MONOTONIC |
40 | # define EV_USE_MONOTONIC 1 |
41 | # define EV_USE_MONOTONIC 1 |
|
|
42 | # endif |
|
|
43 | # ifndef EV_USE_REALTIME |
41 | # define EV_USE_REALTIME 1 |
44 | # define EV_USE_REALTIME 1 |
|
|
45 | # endif |
42 | # endif |
46 | # endif |
43 | |
47 | |
44 | # if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) |
48 | # if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) |
45 | # define EV_USE_SELECT 1 |
49 | # define EV_USE_SELECT 1 |
46 | # endif |
50 | # endif |
… | |
… | |
157 | typedef struct ev_watcher_list *WL; |
161 | typedef struct ev_watcher_list *WL; |
158 | typedef struct ev_watcher_time *WT; |
162 | typedef struct ev_watcher_time *WT; |
159 | |
163 | |
160 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
164 | static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ |
161 | |
165 | |
|
|
166 | #ifdef WIN32 |
162 | #include "ev_win32.c" |
167 | # include "ev_win32.c" |
|
|
168 | #endif |
163 | |
169 | |
164 | /*****************************************************************************/ |
170 | /*****************************************************************************/ |
165 | |
171 | |
166 | static void (*syserr_cb)(const char *msg); |
172 | static void (*syserr_cb)(const char *msg); |
167 | |
173 | |
… | |
… | |
227 | #if EV_MULTIPLICITY |
233 | #if EV_MULTIPLICITY |
228 | |
234 | |
229 | struct ev_loop |
235 | struct ev_loop |
230 | { |
236 | { |
231 | ev_tstamp ev_rt_now; |
237 | ev_tstamp ev_rt_now; |
|
|
238 | #define ev_rt_now ((loop)->ev_rt_now) |
232 | #define VAR(name,decl) decl; |
239 | #define VAR(name,decl) decl; |
233 | #include "ev_vars.h" |
240 | #include "ev_vars.h" |
234 | #undef VAR |
241 | #undef VAR |
235 | }; |
242 | }; |
236 | #include "ev_wrap.h" |
243 | #include "ev_wrap.h" |
… | |
… | |
528 | heap [k] = w; |
535 | heap [k] = w; |
529 | ((W)heap [k])->active = k + 1; |
536 | ((W)heap [k])->active = k + 1; |
530 | } |
537 | } |
531 | |
538 | |
532 | inline void |
539 | inline void |
533 | adjustheap (WT *heap, int N, int k, ev_tstamp at) |
540 | adjustheap (WT *heap, int N, int k) |
534 | { |
541 | { |
535 | ev_tstamp old_at = heap [k]->at; |
542 | upheap (heap, k); |
536 | heap [k]->at = at; |
|
|
537 | |
|
|
538 | if (old_at < at) |
|
|
539 | downheap (heap, N, k); |
543 | downheap (heap, N, k); |
540 | else |
|
|
541 | upheap (heap, k); |
|
|
542 | } |
544 | } |
543 | |
545 | |
544 | /*****************************************************************************/ |
546 | /*****************************************************************************/ |
545 | |
547 | |
546 | typedef struct |
548 | typedef struct |
… | |
… | |
1346 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1348 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1347 | |
1349 | |
1348 | if (((W)w)->active < timercnt--) |
1350 | if (((W)w)->active < timercnt--) |
1349 | { |
1351 | { |
1350 | timers [((W)w)->active - 1] = timers [timercnt]; |
1352 | timers [((W)w)->active - 1] = timers [timercnt]; |
1351 | downheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1353 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1352 | } |
1354 | } |
1353 | |
1355 | |
1354 | ((WT)w)->at -= mn_now; |
1356 | ((WT)w)->at -= mn_now; |
1355 | |
1357 | |
1356 | ev_stop (EV_A_ (W)w); |
1358 | ev_stop (EV_A_ (W)w); |
… | |
… | |
1360 | ev_timer_again (EV_P_ struct ev_timer *w) |
1362 | ev_timer_again (EV_P_ struct ev_timer *w) |
1361 | { |
1363 | { |
1362 | if (ev_is_active (w)) |
1364 | if (ev_is_active (w)) |
1363 | { |
1365 | { |
1364 | if (w->repeat) |
1366 | if (w->repeat) |
|
|
1367 | { |
|
|
1368 | ((WT)w)->at = mn_now + w->repeat; |
1365 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1, mn_now + w->repeat); |
1369 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
|
|
1370 | } |
1366 | else |
1371 | else |
1367 | ev_timer_stop (EV_A_ w); |
1372 | ev_timer_stop (EV_A_ w); |
1368 | } |
1373 | } |
1369 | else if (w->repeat) |
1374 | else if (w->repeat) |
1370 | ev_timer_start (EV_A_ w); |
1375 | ev_timer_start (EV_A_ w); |
… | |
… | |
1404 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1409 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1405 | |
1410 | |
1406 | if (((W)w)->active < periodiccnt--) |
1411 | if (((W)w)->active < periodiccnt--) |
1407 | { |
1412 | { |
1408 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1413 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1409 | downheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1414 | adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1410 | } |
1415 | } |
1411 | |
1416 | |
1412 | ev_stop (EV_A_ (W)w); |
1417 | ev_stop (EV_A_ (W)w); |
1413 | } |
1418 | } |
1414 | |
1419 | |
… | |
… | |
1434 | |
1439 | |
1435 | void |
1440 | void |
1436 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1441 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1437 | { |
1442 | { |
1438 | ev_clear_pending (EV_A_ (W)w); |
1443 | ev_clear_pending (EV_A_ (W)w); |
1439 | if (ev_is_active (w)) |
1444 | if (!ev_is_active (w)) |
1440 | return; |
1445 | return; |
1441 | |
1446 | |
1442 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1447 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1443 | ev_stop (EV_A_ (W)w); |
1448 | ev_stop (EV_A_ (W)w); |
1444 | } |
1449 | } |
… | |
… | |
1456 | |
1461 | |
1457 | void |
1462 | void |
1458 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1463 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1459 | { |
1464 | { |
1460 | ev_clear_pending (EV_A_ (W)w); |
1465 | ev_clear_pending (EV_A_ (W)w); |
1461 | if (ev_is_active (w)) |
1466 | if (!ev_is_active (w)) |
1462 | return; |
1467 | return; |
1463 | |
1468 | |
1464 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1469 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1465 | ev_stop (EV_A_ (W)w); |
1470 | ev_stop (EV_A_ (W)w); |
1466 | } |
1471 | } |