summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroot <root>2009-04-15 19:35:53 +0000
committerroot <root>2009-04-15 19:35:53 +0000
commit063940f2d384a70bbf0499865ca0e54e99b96f23 (patch)
treebccd47935a27a6d4e0e407bc27500a8a5aee2fce
parentfccdbf50f2094e18861bcb38d5b980212d04c242 (diff)
resume/suspend
-rw-r--r--Changes5
-rw-r--r--ev.c3
-rw-r--r--ev.h12
-rw-r--r--ev.pod26
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<ev_timer> 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<ev_suspend>
+in your C<SIGTSTP> handler, sending yourself a C<SIGSTOP> and calling
+C<ev_resume> directly afterwards to resume timer processing.
+
+Effectively, all C<ev_timer> watchers will be delayed by the time spend
+between C<ev_suspend> and C<ev_resume>, and all C<ev_periodic> watchers
+will be rescheduled (that is, they will lose any events that would have
+occured while suspended).
+
+After calling C<ev_suspend> you B<must not> call I<any> function on the
+given loop other than C<ev_resume>, and you B<must not> call C<ev_resume>
+without a previous call to C<ev_suspend>.
+
+Calling C<ev_suspend>/C<ev_resume> has the side effect of updating the
+event loop time (see C<ev_now_update>).
+
=item ev_loop (loop, int flags)
Finally, this is it, the event handler. This function usually is called