[vlc-devel] [[PATCH v3] 2/6] threads: use an atomic_uint for vlc_cancel_addr_set/clear

Rémi Denis-Courmont remi at remlab.net
Mon Feb 10 14:43:48 CET 2020


LGTM

Le 10 février 2020 15:39:11 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>That's what the caller expects as the default storage format for these
>variables.
>---
> include/vlc_threads.h | 10 +++++++---
> src/android/thread.c  |  8 ++++----
> src/misc/threads.c    | 21 +++++++++++++--------
> src/win32/thread.c    |  6 +++---
> 4 files changed, 27 insertions(+), 18 deletions(-)
>
>diff --git a/include/vlc_threads.h b/include/vlc_threads.h
>index 0025ca7ea7d..1598c9c804d 100644
>--- a/include/vlc_threads.h
>+++ b/include/vlc_threads.h
>@@ -351,6 +351,10 @@ typedef struct vlc_timer *vlc_timer_t;
> #endif
> 
> #ifdef LIBVLC_NEED_CONDVAR
>+#ifndef __cplusplus
>+#include <stdatomic.h>
>+#endif
>+
> typedef struct
> {
>     unsigned value;
>@@ -1098,9 +1102,9 @@ static inline void vlc_cleanup_lock (void *lock)
> }
>#define mutex_cleanup_push( lock ) vlc_cleanup_push (vlc_cleanup_lock,
>lock)
> 
>-#if defined(LIBVLC_NEED_CONDVAR)
>-void vlc_cancel_addr_set(void *addr);
>-void vlc_cancel_addr_clear(void *addr);
>+#if defined(LIBVLC_NEED_CONDVAR) && !defined(__cplusplus)
>+void vlc_cancel_addr_set(atomic_uint *addr);
>+void vlc_cancel_addr_clear(atomic_uint *addr);
> #endif
> 
> #ifdef __cplusplus
>diff --git a/src/android/thread.c b/src/android/thread.c
>index c213e237ea4..26723d56726 100644
>--- a/src/android/thread.c
>+++ b/src/android/thread.c
>@@ -140,7 +140,7 @@ struct vlc_thread
> 
>     struct
>     {
>-        void *addr; /// Non-null if waiting on futex
>+        atomic_uint *addr; /// Non-null if waiting on futex
>         vlc_mutex_t lock ; /// Protects futex address
>     } wait;
> 
>@@ -285,7 +285,7 @@ int vlc_set_priority (vlc_thread_t th, int
>priority)
> 
> void vlc_cancel (vlc_thread_t thread_id)
> {
>-    atomic_int *addr;
>+    atomic_uint *addr;
> 
>     atomic_store(&thread_id->killed, true);
> 
>@@ -335,7 +335,7 @@ noreturn void vlc_control_cancel (int cmd, ...)
>     vlc_assert_unreachable ();
> }
> 
>-void vlc_cancel_addr_set(void *addr)
>+void vlc_cancel_addr_set(atomic_uint *addr)
> {
>     vlc_thread_t th = vlc_thread_self();
>     if (th == NULL)
>@@ -347,7 +347,7 @@ void vlc_cancel_addr_set(void *addr)
>     vlc_mutex_unlock(&th->wait.lock);
> }
> 
>-void vlc_cancel_addr_clear(void *addr)
>+void vlc_cancel_addr_clear(atomic_uint *addr)
> {
>     vlc_thread_t th = vlc_thread_self();
>     if (th == NULL)
>diff --git a/src/misc/threads.c b/src/misc/threads.c
>index 501a17ac9b3..b40348ca903 100644
>--- a/src/misc/threads.c
>+++ b/src/misc/threads.c
>@@ -149,17 +149,22 @@ bool vlc_mutex_marked(const vlc_mutex_t *mutex)
> #if defined(LIBVLC_NEED_SLEEP) || defined(LIBVLC_NEED_CONDVAR)
> #include <stdatomic.h>
> 
>-static void vlc_cancel_addr_prepare(void *addr)
>+static void do_vlc_cancel_addr_clear(void *addr)
>+{
>+    vlc_cancel_addr_clear(addr);
>+}
>+
>+static void vlc_cancel_addr_prepare(atomic_uint *addr)
> {
>    /* Let thread subsystem on address to broadcast for cancellation */
>     vlc_cancel_addr_set(addr);
>-    vlc_cleanup_push(vlc_cancel_addr_clear, addr);
>+    vlc_cleanup_push(do_vlc_cancel_addr_clear, addr);
>   /* Check if cancellation was pending before vlc_cancel_addr_set() */
>     vlc_testcancel();
>     vlc_cleanup_pop();
> }
> 
>-static void vlc_cancel_addr_finish(void *addr)
>+static void vlc_cancel_addr_finish(atomic_uint *addr)
> {
>     vlc_cancel_addr_clear(addr);
>     /* Act on cancellation as potential wake-up source */
>@@ -171,7 +176,7 @@ static void vlc_cancel_addr_finish(void *addr)
> void (vlc_tick_wait)(vlc_tick_t deadline)
> {
>     vlc_tick_t delay;
>-    atomic_int value = ATOMIC_VAR_INIT(0);
>+    atomic_uint value = ATOMIC_VAR_INIT(0);
> 
>     vlc_cancel_addr_prepare(&value);
> 
>@@ -258,13 +263,13 @@ void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t
>*mutex)
>             value++;
>     }
> 
>-    vlc_cancel_addr_prepare(&cond->value);
>+    vlc_cancel_addr_prepare(vlc_cond_value(cond));
>     vlc_mutex_unlock(mutex);
> 
>     vlc_atomic_wait(&cond->value, value);
> 
>     vlc_mutex_lock(mutex);
>-    vlc_cancel_addr_finish(&cond->value);
>+    vlc_cancel_addr_finish(vlc_cond_value(cond));
> }
> 
> static int vlc_cond_wait_delay(vlc_cond_t *cond, vlc_mutex_t *mutex,
>@@ -281,7 +286,7 @@ static int vlc_cond_wait_delay(vlc_cond_t *cond,
>vlc_mutex_t *mutex,
>             value++;
>     }
> 
>-    vlc_cancel_addr_prepare(&cond->value);
>+    vlc_cancel_addr_prepare(vlc_cond_value(cond));
>     vlc_mutex_unlock(mutex);
> 
>     if (delay > 0)
>@@ -290,7 +295,7 @@ static int vlc_cond_wait_delay(vlc_cond_t *cond,
>vlc_mutex_t *mutex,
>         value = 0;
> 
>     vlc_mutex_lock(mutex);
>-    vlc_cancel_addr_finish(&cond->value);
>+    vlc_cancel_addr_finish(vlc_cond_value(cond));
> 
>     return value ? 0 : ETIMEDOUT;
> }
>diff --git a/src/win32/thread.c b/src/win32/thread.c
>index 23f9c0afe50..994bd1631b4 100644
>--- a/src/win32/thread.c
>+++ b/src/win32/thread.c
>@@ -65,7 +65,7 @@ struct vlc_thread
> 
>     struct
>     {
>-        atomic_int      *addr;
>+        atomic_uint     *addr;
>         CRITICAL_SECTION lock;
>     } wait;
> };
>@@ -670,7 +670,7 @@ void vlc_control_cancel (int cmd, ...)
>     va_end (ap);
> }
> 
>-void vlc_cancel_addr_set(void *addr)
>+void vlc_cancel_addr_set(atomic_uint *addr)
> {
>     struct vlc_thread *th = vlc_thread_self();
>     if (th == NULL)
>@@ -682,7 +682,7 @@ void vlc_cancel_addr_set(void *addr)
>     LeaveCriticalSection(&th->wait.lock);
> }
> 
>-void vlc_cancel_addr_clear(void *addr)
>+void vlc_cancel_addr_clear(atomic_uint *addr)
> {
>     struct vlc_thread *th = vlc_thread_self();
>     if (th == NULL)
>-- 
>2.17.1
>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200210/c953895c/attachment.html>


More information about the vlc-devel mailing list