[vlc-commits] threads: turn vlc_cancel_addr_set/clear into internal functions

Steve Lhomme git at videolan.org
Mon Feb 10 14:54:07 CET 2020


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Mon Feb 10 13:21:18 2020 +0100| [66c7bb38b66b7b8ab517e88a61a17aabdb0e254a] | committer: Steve Lhomme

threads: turn vlc_cancel_addr_set/clear into internal functions

Should only be called on Win32 and Android, the only platforms where
LIBVLC_NEED_CONDVAR is defined.

LIBVLC_NEED_SLEEP is always found when LIBVLC_NEED_CONDVAR is set, so no need
to test it.

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

 include/vlc_threads.h | 15 ++++----------
 src/android/thread.c  | 56 ++++++++++++++++++++++-----------------------------
 src/win32/thread.c    | 42 ++++++++++++++++++++------------------
 3 files changed, 50 insertions(+), 63 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 2e85d63d6b..0025ca7ea7 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -1028,8 +1028,6 @@ enum
 {
     VLC_CLEANUP_PUSH,
     VLC_CLEANUP_POP,
-    VLC_CANCEL_ADDR_SET,
-    VLC_CANCEL_ADDR_CLEAR,
 };
 
 #if defined (LIBVLC_USE_PTHREAD_CLEANUP)
@@ -1100,15 +1098,10 @@ static inline void vlc_cleanup_lock (void *lock)
 }
 #define mutex_cleanup_push( lock ) vlc_cleanup_push (vlc_cleanup_lock, lock)
 
-static inline void vlc_cancel_addr_set(void *addr)
-{
-    vlc_control_cancel(VLC_CANCEL_ADDR_SET, addr);
-}
-
-static inline void vlc_cancel_addr_clear(void *addr)
-{
-    vlc_control_cancel(VLC_CANCEL_ADDR_CLEAR, addr);
-}
+#if defined(LIBVLC_NEED_CONDVAR)
+void vlc_cancel_addr_set(void *addr);
+void vlc_cancel_addr_clear(void *addr);
+#endif
 
 #ifdef __cplusplus
 /**
diff --git a/src/android/thread.c b/src/android/thread.c
index ca715418d4..c213e237ea 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -34,6 +34,7 @@
 #include <signal.h>
 #include <errno.h>
 #include <stdatomic.h>
+#include <stdnoreturn.h>
 #include <time.h>
 #include <assert.h>
 
@@ -328,44 +329,35 @@ void vlc_testcancel (void)
     pthread_exit(NULL);
 }
 
-void vlc_control_cancel(int cmd, ...)
+noreturn void vlc_control_cancel (int cmd, ...)
+{
+    (void) cmd;
+    vlc_assert_unreachable ();
+}
+
+void vlc_cancel_addr_set(void *addr)
 {
     vlc_thread_t th = vlc_thread_self();
-    va_list ap;
+    if (th == NULL)
+        return;
 
+    vlc_mutex_lock(&th->wait.lock);
+    assert(th->wait.addr == NULL);
+    th->wait.addr = addr;
+    vlc_mutex_unlock(&th->wait.lock);
+}
+
+void vlc_cancel_addr_clear(void *addr)
+{
+    vlc_thread_t th = vlc_thread_self();
     if (th == NULL)
         return;
 
-    va_start(ap, cmd);
-    switch (cmd)
-    {
-        case VLC_CANCEL_ADDR_SET:
-        {
-            void *addr = va_arg(ap, void *);
-
-            vlc_mutex_lock(&th->wait.lock);
-            assert(th->wait.addr == NULL);
-            th->wait.addr = addr;
-            vlc_mutex_unlock(&th->wait.lock);
-            break;
-        }
-
-        case VLC_CANCEL_ADDR_CLEAR:
-        {
-            void *addr = va_arg(ap, void *);
-
-            vlc_mutex_lock(&th->wait.lock);
-            assert(th->wait.addr == addr);
-            th->wait.addr = NULL;
-            (void) addr;
-            vlc_mutex_unlock(&th->wait.lock);
-            break;
-        }
-
-        default:
-            vlc_assert_unreachable ();
-    }
-    va_end(ap);
+    vlc_mutex_lock(&th->wait.lock);
+    assert(th->wait.addr == addr);
+    th->wait.addr = NULL;
+    (void) addr;
+    vlc_mutex_unlock(&th->wait.lock);
 }
 
 /* threadvar */
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 6af2eb8385..23f9c0afe5 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -666,30 +666,32 @@ void vlc_control_cancel (int cmd, ...)
             th->cleaners = th->cleaners->next;
             break;
         }
+    }
+    va_end (ap);
+}
 
-        case VLC_CANCEL_ADDR_SET:
-        {
-            void *addr = va_arg(ap, void *);
+void vlc_cancel_addr_set(void *addr)
+{
+    struct vlc_thread *th = vlc_thread_self();
+    if (th == NULL)
+        return; /* Main thread - cannot be cancelled anyway */
 
-            EnterCriticalSection(&th->wait.lock);
-            assert(th->wait.addr == NULL);
-            th->wait.addr = addr;
-            LeaveCriticalSection(&th->wait.lock);
-            break;
-        }
+    EnterCriticalSection(&th->wait.lock);
+    assert(th->wait.addr == NULL);
+    th->wait.addr = addr;
+    LeaveCriticalSection(&th->wait.lock);
+}
 
-        case VLC_CANCEL_ADDR_CLEAR:
-        {
-            void *addr = va_arg(ap, void *);
+void vlc_cancel_addr_clear(void *addr)
+{
+    struct vlc_thread *th = vlc_thread_self();
+    if (th == NULL)
+        return; /* Main thread - cannot be cancelled anyway */
 
-            EnterCriticalSection(&th->wait.lock);
-            assert(th->wait.addr == addr);
-            th->wait.addr = NULL;
-            LeaveCriticalSection(&th->wait.lock);
-            break;
-        }
-    }
-    va_end (ap);
+    EnterCriticalSection(&th->wait.lock);
+    assert(th->wait.addr == addr);
+    th->wait.addr = NULL;
+    LeaveCriticalSection(&th->wait.lock);
 }
 
 /*** Clock ***/



More information about the vlc-commits mailing list