[vlc-commits] Factor mtime_to to struct timespec conversion

Rémi Denis-Courmont git at videolan.org
Thu Jul 14 19:44:46 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jul 14 14:37:33 2011 +0300| [0c677da7db59c016537f7362fbe051c10b7c6832] | committer: Rémi Denis-Courmont

Factor mtime_to to struct timespec conversion

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

 src/posix/thread.c |   23 +++++++++++++----------
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/posix/thread.c b/src/posix/thread.c
index 05005b2..56b9d2d 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -137,6 +137,14 @@ int nanosleep (struct timespec *, struct timespec *);
 # define vlc_clock_setup() (void)0
 #endif /* _POSIX_TIMERS */
 
+static struct timespec mtime_to_ts (mtime_t date)
+{
+    lldiv_t d = lldiv (date, CLOCK_FREQ);
+    struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
+
+    return ts;
+}
+
 /**
  * Print a backtrace to the standard error for debugging purpose.
  */
@@ -466,13 +474,11 @@ int vlc_cond_timedwait (vlc_cond_t *p_condvar, vlc_mutex_t *p_mutex,
     deadline -= base;
     if (deadline < 0)
         deadline = 0;
-    lldiv_t d = lldiv( deadline, CLOCK_FREQ );
-    struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
 
+    struct timespec ts = mtime_to_ts (deadline);
     int val = pthread_cond_timedwait_relative_np(p_condvar, p_mutex, &ts);
 #else
-    lldiv_t d = lldiv( deadline, CLOCK_FREQ );
-    struct timespec ts = { d.quot, d.rem * (1000000000 / CLOCK_FREQ) };
+    struct timespec ts = mtime_to_ts (deadline);
     int val = pthread_cond_timedwait (p_condvar, p_mutex, &ts);
 #endif
     if (val != ETIMEDOUT)
@@ -976,8 +982,7 @@ void mwait (mtime_t deadline)
      * do not even bother the system timer. */
     deadline -= vlc_clock_prec;
 
-    lldiv_t d = lldiv (deadline, 1000000);
-    struct timespec ts = { d.quot, d.rem * 1000 };
+    struct timespec ts = mtime_to_ts (deadline);
 
     while (clock_nanosleep (vlc_clock_id, TIMER_ABSTIME, &ts, NULL) == EINTR);
 
@@ -996,11 +1001,9 @@ void mwait (mtime_t deadline)
  */
 void msleep (mtime_t delay)
 {
-    vlc_clock_setup ();
-
-    lldiv_t d = lldiv (delay, 1000000);
-    struct timespec ts = { d.quot, d.rem * 1000 };
+    struct timespec ts = mtime_to_ts (delay);
 
+    vlc_clock_setup ();
 #if (_POSIX_TIMERS > 0)
     while (clock_nanosleep (vlc_clock_id, 0, &ts, &ts) == EINTR);
 



More information about the vlc-commits mailing list