From 063940f2d384a70bbf0499865ca0e54e99b96f23 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 15 Apr 2009 19:35:53 +0000 Subject: resume/suspend --- Changes | 5 +++-- ev.c | 3 ++- ev.h | 12 ++++++++++-- ev.pod | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index 4cf91ec..c6ede60 100644 --- a/Changes +++ b/Changes @@ -1,8 +1,8 @@ Revision history for libev, a high-performance and full-featured event loop. -TODO: ev_time_freeze, ev_time_thaw TODO: ev_walk -TODO: ev_stop_all +TODO: ev_stop_all docs +TODO: priority/idle docs TODO: fix signal handling(?) under win32 3.54 - multiple timers becoming ready within an event loop iteration @@ -14,6 +14,7 @@ TODO: fix signal handling(?) under win32 - correctly zero the idx values for arrays, so destroying and reinitialising the default loop actually works (patch by Malek Hadj-Ali). + - implement ev_suspend and ev_resume. - new EV_CUSTOM revents flag for use by applications. 3.53 Sun Feb 15 02:38:20 CET 2009 diff --git a/ev.c b/ev.c index 410805e..684ca07 100644 --- a/ev.c +++ b/ev.c @@ -2135,9 +2135,10 @@ ev_resume (EV_P) ev_tstamp mn_prev = mn_now; ev_now_update (EV_A); - printf ("update %f\n", mn_now - mn_prev);//D timers_reschedule (EV_A_ mn_now - mn_prev); +#if EV_PERIODIC_ENABLE periodics_reschedule (EV_A); +#endif } /*****************************************************************************/ diff --git a/ev.h b/ev.h index 70746ab..c9e93cd 100644 --- a/ev.h +++ b/ev.h @@ -526,8 +526,16 @@ void ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval); /* sleep at lea void ev_ref (EV_P); void ev_unref (EV_P); -/* convenience function, wait for a single event, without registering an event watcher */ -/* if timeout is < 0, do wait indefinitely */ +/* + * stop/start the timer handling. + */ +void ev_suspend (EV_P); +void ev_resume (EV_P); + +/* + * convenience function, wait for a single event, without registering an event watcher + * if timeout is < 0, do wait indefinitely + */ void ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg); #endif diff --git a/ev.pod b/ev.pod index 7061527..467ac14 100644 --- a/ev.pod +++ b/ev.pod @@ -636,6 +636,32 @@ the current time is a good idea. See also "The special problem of time updates" in the C section. +=item ev_suspend (loop) + +=item ev_resume (loop) + +These two functions suspend and resume a loop, for use when the loop is +not used for a while and timeouts should not be processed. + +A typical use case would be an interactive program such as a game: When +the user presses C<^Z> to suspend the game and resumes it an hour later it +would be best to handle timeouts as if no time had actually passed while +the program was suspended. This can be achieved by calling C +in your C handler, sending yourself a C and calling +C directly afterwards to resume timer processing. + +Effectively, all C watchers will be delayed by the time spend +between C and C, and all C watchers +will be rescheduled (that is, they will lose any events that would have +occured while suspended). + +After calling C you B call I function on the +given loop other than C, and you B call C +without a previous call to C. + +Calling C/C has the side effect of updating the +event loop time (see C). + =item ev_loop (loop, int flags) Finally, this is it, the event handler. This function usually is called -- cgit v1.2.3