[vlc-devel] [PATCH 2/2] Android: remove polling timer in mwait() and msleep()

Rémi Denis-Courmont remi at remlab.net
Mon Oct 15 20:22:50 CEST 2012


---
 src/android/thread.c |   32 +++++++++-----------------------
 1 file changed, 9 insertions(+), 23 deletions(-)

diff --git a/src/android/thread.c b/src/android/thread.c
index d84ea79..ae522e8 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -490,37 +490,23 @@ mtime_t mdate (void)
     return (INT64_C(1000000) * ts.tv_sec) + (ts.tv_nsec / 1000);
 }
 
+static vlc_mutex_t sleep_lock = VLC_STATIC_MUTEX;
+static vlc_cond_t sleep_wait = { PTHREAD_COND_INITIALIZER, CLOCK_MONOTONIC };
+
 #undef mwait
 void mwait (mtime_t deadline)
 {
-    deadline -= mdate ();
-    if (deadline > 0)
-        msleep (deadline);
+    struct timespec ts = mtime_to_ts (delay);
+
+    vlc_mutex_lock (&sleep_lock);
+    while (vlc_cond_timewait (&sleep_wait, &sleep_lock, &ts));
+    vlc_mutex_unlock (&sleep_lock);
 }
 
 #undef msleep
 void msleep (mtime_t delay)
 {
-    struct timespec ts = mtime_to_ts (delay);
-
-    vlc_testcancel();
-    for (;;) {
-        /* FIXME: drift */
-        struct timespec t = { 0, 10 * 1000 * 1000 };
-        if (ts.tv_sec <= 0 && t.tv_nsec > ts.tv_nsec)
-            t.tv_nsec = ts.tv_nsec;
-        while (nanosleep (&t, &t) == -1) {
-            vlc_testcancel();
-            vlc_assert (errno == EINTR);
-        }
-
-        ts.tv_nsec -= 10 * 1000 * 1000;
-        if (ts.tv_nsec < 0) {
-            if (--ts.tv_sec < 0)
-                return;
-            ts.tv_nsec += 1000 * 1000 * 1000;
-        }
-    }
+    mwait (mdate () + delay);
 }
 
 /* cpu */
-- 
1.7.10.4




More information about the vlc-devel mailing list