summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes11
-rw-r--r--ev.c6
-rw-r--r--ev.h2
-rw-r--r--ev.pod12
4 files changed, 26 insertions, 5 deletions
diff --git a/Changes b/Changes
index a7df7ff..d294d71 100644
--- 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 a6f414f..eba23b6 100644
--- 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 0d00f0b..25c3f1d 100644
--- 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 feabbcc..289362b 100644
--- 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