X-Git-Url: https://git.llucax.com/software/libev.git/blobdiff_plain/04c8cb9913a370451296919b6dd2567793de9a75..49a82c163f76e2916974ec3eac8d395662e7187b:/ev.c diff --git a/ev.c b/ev.c index 1e54f21..aefc9df 100644 --- a/ev.c +++ b/ev.c @@ -36,18 +36,6 @@ #include "ev.h" -struct ev_watcher { - EV_WATCHER (ev_watcher); -}; - -struct ev_watcher_list { - EV_WATCHER_LIST (ev_watcher_list); -}; - -struct ev_watcher_time { - EV_WATCHER_TIME (ev_watcher_time); -}; - typedef struct ev_watcher *W; typedef struct ev_watcher_list *WL; typedef struct ev_watcher_time *WT; @@ -97,7 +85,6 @@ get_clock (void) if ((cnt) > cur) \ { \ int newcnt = cur ? cur << 1 : 16; \ - fprintf (stderr, "resize(" # base ") from %d to %d\n", cur, newcnt);\ base = realloc (base, sizeof (*base) * (newcnt)); \ init (base + cur, newcnt - cur); \ cur = newcnt; \ @@ -457,11 +444,11 @@ periodics_reify () } static void -time_jump (ev_tstamp diff) +periodics_reschedule (ev_tstamp diff) { int i; - /* adjust periodics */ + /* adjust periodics after time jump */ for (i = 0; i < periodiccnt; ++i) { struct ev_periodic *w = periodics [i]; @@ -479,10 +466,6 @@ time_jump (ev_tstamp diff) } } } - - /* adjust timers. this is easy, as the offset is the same for all */ - for (i = 0; i < timercnt; ++i) - timers [i]->at += diff; } static void @@ -507,12 +490,19 @@ time_update () ev_now = ev_time (); } - time_jump (diff - odiff); + periodics_reschedule (diff - odiff); + /* no timer adjustment, as the monotonic clock doesn't jump */ } else { if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP) - time_jump (ev_now - now); + { + periodics_reschedule (ev_now - now); + + /* adjust timers. this is easy, as the offset is the same for all */ + for (i = 0; i < timercnt; ++i) + timers [i]->at += diff; + } now = ev_now; } @@ -523,7 +513,7 @@ int ev_loop_done; void ev_loop (int flags) { double block; - ev_loop_done = flags & EVLOOP_ONESHOT; + ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; if (checkcnt) { @@ -549,7 +539,7 @@ void ev_loop (int flags) if (timercnt) { - ev_tstamp to = timers [0]->at - get_clock () + method_fudge; + ev_tstamp to = timers [0]->at - (have_monotonic ? get_clock () : ev_now) + method_fudge; if (block > to) block = to; } @@ -581,6 +571,9 @@ void ev_loop (int flags) call_pending (); } while (!ev_loop_done); + + if (ev_loop_done != 2) + ev_loop_done = 0; } /*****************************************************************************/ @@ -665,6 +658,8 @@ evtimer_start (struct ev_timer *w) w->at += now; + assert (("timer repeat value less than zero not allowed", w->repeat >= 0.)); + ev_start ((W)w, ++timercnt); array_needsize (timers, timermax, timercnt, ); timers [timercnt - 1] = w; @@ -683,15 +678,36 @@ evtimer_stop (struct ev_timer *w) downheap ((WT *)timers, timercnt, w->active - 1); } + w->at = w->repeat; + ev_stop ((W)w); } +void +evtimer_again (struct ev_timer *w) +{ + if (ev_is_active (w)) + { + if (w->repeat) + { + w->at = now + w->repeat; + downheap ((WT *)timers, timercnt, w->active - 1); + } + else + evtimer_stop (w); + } + else if (w->repeat) + evtimer_start (w); +} + void evperiodic_start (struct ev_periodic *w) { if (ev_is_active (w)) return; + assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); + /* this formula differs from the one in periodic_reify because we do not always round up */ if (w->interval) w->at += ceil ((ev_now - w->at) / w->interval) * w->interval; @@ -784,7 +800,7 @@ void evcheck_stop (struct ev_check *w) /*****************************************************************************/ -#if 1 +#if 0 struct ev_io wio;