]> rtime.felk.cvut.cz Git - sojka/libev.git/commitdiff
*** empty log message ***
authorMarc Alexander Lehmann <libev@schmorp.de>
Wed, 15 Jul 2009 16:58:53 +0000 (16:58 +0000)
committerMarc Alexander Lehmann <libev@schmorp.de>
Wed, 15 Jul 2009 16:58:53 +0000 (16:58 +0000)
Changes
ev.c
ev.h
ev.pod

diff --git a/Changes b/Changes
index a7df7ff9318ce201a6c341b0a52b75cd4db056e9..d294d7184ea9cbcdf3ef01c6717f43d8e263c7d7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -4,16 +4,18 @@ TODO: ev_walk
 TODO: remain
 TODO: EV_MINIMAL
 
-        - new functionality: ev_set_userdata, ev_userdata,
+       - ev_unloop and ev_loop wrongly used a global variable to exit loops,
+          instead of using a per-loop variable (bug caught by accident...).
+       - the ev_set_io_collect_interval interpretation has changed.
+        - add new functionality: ev_set_userdata, ev_userdata,
           ev_set_invoke_pending_cb, ev_set_loop_release_cb,
           ev_invoke_pending, together with a long example about thread
           locking.
-       - ev_unloop and ev_loop wrongly used a global variable to exit loops,
-          instead of using a per-loop variable (bug caught by accident...).
+        - add ev_timer_remaining (as requested by Denis F. Latypoff).
+        - add ev_loop_depth.
         - calling ev_unloop in fork/prepare watchers will no longer poll
           for new events.
        - Denis F. Latypoff corrected many typos in example code snippets.
-       - the ev_set_io_collect_interval interpretation has changed.
         - honor autoconf detection of EV_USE_CLOCK_SYSCALL, also double-
           check that the syscall number is available before trying to
           use it (reported by ry@tinyclouds).
@@ -21,7 +23,6 @@ TODO: EV_MINIMAL
           slightly higher accuracy.
         - properly declare ev_loop_verify and ev_now_update even when
           !EV_MULTIPLICITY.
-        - implement ev_loop_depth.
         - do not compile in any priority code when EV_MAXPRI == EV_MINPRI.
         - support EV_MINIMAL==2 for a reduced API.
         - actually 0-initialise struct sigaction when installing signals.
diff --git a/ev.c b/ev.c
index a6f414f9dd53b34624c4e9ce837b0602c6bae31a..eba23b6e81be1ee4513cad84f783ef3c454e8fb2 100644 (file)
--- a/ev.c
+++ b/ev.c
@@ -2489,6 +2489,12 @@ ev_timer_again (EV_P_ ev_timer *w)
   EV_FREQUENT_CHECK;
 }
 
+ev_tstamp
+ev_timer_remaining (EV_P_ ev_timer *w)
+{
+  return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
+}
+
 #if EV_PERIODIC_ENABLE
 void noinline
 ev_periodic_start (EV_P_ ev_periodic *w)
diff --git a/ev.h b/ev.h
index 0d00f0be3c2685f08ca532131e7cc05a71a9a341..25c3f1d80668c4dbc4cf3600bfa1bf06cf679fa1 100644 (file)
--- a/ev.h
+++ b/ev.h
@@ -638,6 +638,8 @@ void ev_timer_start    (EV_P_ ev_timer *w);
 void ev_timer_stop     (EV_P_ ev_timer *w);
 /* stops if active and no repeat, restarts if active and repeating, starts if inactive and repeating */
 void ev_timer_again    (EV_P_ ev_timer *w);
+/* return remaining time */
+ev_tstamp ev_timer_remaining (EV_P_ ev_timer *w);
 
 #if EV_PERIODIC_ENABLE
 void ev_periodic_start (EV_P_ ev_periodic *w);
diff --git a/ev.pod b/ev.pod
index feabbcc3b99c364bdda7e191512c064699c64383..289362b7c0793cd6f880cb1ea5c117713eb4b8d4 100644 (file)
--- a/ev.pod
+++ b/ev.pod
@@ -1822,6 +1822,18 @@ C<repeat> value), or reset the running timer to the C<repeat> value.
 This sounds a bit complicated, see L<Be smart about timeouts>, above, for a
 usage example.
 
+=item ev_timer_remaining (loop, ev_timer *)
+
+Returns the remaining time until a timer fires. If the timer is active,
+then this time is relative to the current event loop time, otherwise it's
+the timeout value currently configured.
+
+That is, after an C<ev_timer_set (w, 5, 7)>, C<ev_timer_remaining> returns
+C<5>. When the timer is started and one second passes, C<ev_timer_remain>
+will return C<4>. When the timer expires and is restarted, it will return
+roughly C<7> (likely slightly less as callback invocation takes some time,
+too), and so on.
+
 =item ev_tstamp repeat [read-write]
 
 The current C<repeat> value. Will be used each time the watcher times out