[vlc-commits] timer: add a macro to disarm a timer and a define for the disarm value

Steve Lhomme git at videolan.org
Fri Jul 6 08:07:01 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Thu Jul  5 14:34:25 2018 +0200| [83df889ad58afbcfddd0d31dfb476a83f7febee3] | committer: Steve Lhomme

timer: add a macro to disarm a timer and a define for the disarm value

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=83df889ad58afbcfddd0d31dfb476a83f7febee3
---

 include/vlc_threads.h | 7 +++++++
 src/os2/thread.c      | 2 +-
 src/posix/timer.c     | 2 +-
 src/test/timer.c      | 2 +-
 src/win32/timer.c     | 2 +-
 5 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index f1343868a4..d1a4674335 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -948,6 +948,8 @@ VLC_USED;
  */
 VLC_API void vlc_timer_destroy(vlc_timer_t timer);
 
+#define VLC_TIMER_DISARM    (0)
+
 /**
  * Arms or disarms an initialized timer.
  *
@@ -969,6 +971,11 @@ VLC_API void vlc_timer_destroy(vlc_timer_t timer);
 VLC_API void vlc_timer_schedule(vlc_timer_t timer, bool absolute,
                                 vlc_tick_t value, vlc_tick_t interval);
 
+static inline void vlc_timer_disarm(vlc_timer_t timer)
+{
+    vlc_timer_schedule( timer, false, VLC_TIMER_DISARM, 0 );
+}
+
 /**
  * Fetches and resets the overrun counter for a timer.
  *
diff --git a/src/os2/thread.c b/src/os2/thread.c
index b963b8893f..17d2e60aa2 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -1010,7 +1010,7 @@ void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
         timer->interval = 0;
     }
 
-    if (value == 0)
+    if (value == VLC_TIMER_DISARM)
         return; /* Disarm */
 
     if (absolute)
diff --git a/src/posix/timer.c b/src/posix/timer.c
index e806e85fec..9acd51db8f 100644
--- a/src/posix/timer.c
+++ b/src/posix/timer.c
@@ -146,7 +146,7 @@ void vlc_timer_destroy (vlc_timer_t timer)
 void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
                          vlc_tick_t value, vlc_tick_t interval)
 {
-    if (value == 0)
+    if (value == VLC_TIMER_DISARM)
         interval = 0;
     else
     if (!absolute)
diff --git a/src/test/timer.c b/src/test/timer.c
index e287c1548e..539f8cd5c3 100644
--- a/src/test/timer.c
+++ b/src/test/timer.c
@@ -87,7 +87,7 @@ int main (void)
     vlc_mutex_unlock (&data.lock);
     assert(ts >= VLC_TICK_FROM_MS(100));
 
-    vlc_timer_schedule (data.timer, false, 0, 0);
+    vlc_timer_disarm (data.timer);
 
     /* Absolute timer */
     ts = vlc_tick_now ();
diff --git a/src/win32/timer.c b/src/win32/timer.c
index 8a8d106183..4c118252bc 100644
--- a/src/win32/timer.c
+++ b/src/win32/timer.c
@@ -70,7 +70,7 @@ void vlc_timer_schedule (vlc_timer_t timer, bool absolute,
         DeleteTimerQueueTimer (NULL, timer->handle, INVALID_HANDLE_VALUE);
         timer->handle = INVALID_HANDLE_VALUE;
     }
-    if (value == 0)
+    if (value == VLC_TIMER_DISARM)
         return; /* Disarm */
 
     if (absolute)



More information about the vlc-commits mailing list