]> rtime.felk.cvut.cz Git - sojka/libev.git/commitdiff
resume/suspend
authorMarc Alexander Lehmann <libev@schmorp.de>
Wed, 15 Apr 2009 19:35:53 +0000 (19:35 +0000)
committerMarc Alexander Lehmann <libev@schmorp.de>
Wed, 15 Apr 2009 19:35:53 +0000 (19:35 +0000)
Changes
ev.c
ev.h
ev.pod

diff --git a/Changes b/Changes
index 4cf91ecdf2c65a70a4c606ca76fa21f6fc8efb06..c6ede600b689b7fa72fa570b87735521bdafb376 100644 (file)
--- 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 410805e3d8426b93ed5a96ff0d94423e43375f97..684ca073eb0044c29717ae3e8c96e4f7970a5d04 100644 (file)
--- 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 70746ab1d92332ac9dd0f78cb7f5dfbd576ae1c8..c9e93cdad9e776e9927b5b41f4d88fdd7444be5d 100644 (file)
--- 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 706152751c0c9ec12f011c8da7e2b0243b143f6d..467ac14d4d38c76231ad7b9985908f079b74f1f5 100644 (file)
--- 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