[vlc-devel] [PATCH 2/4] threads: use an atomic_uint for VLC_CANCEL_ADDR_SET/CLEAR
Steve Lhomme
robux4 at ycbcr.xyz
Mon Feb 10 10:02:20 CET 2020
That's what the caller expects as the default storage format for these variables.
---
include/vlc_threads.h | 4 ++--
src/android/thread.c | 8 ++++----
src/misc/threads.c | 25 +++++++++++++++----------
src/win32/thread.c | 6 +++---
4 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index 341ee97271e..f30f0699e37 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -1028,8 +1028,8 @@ enum
{
VLC_CLEANUP_PUSH,
VLC_CLEANUP_POP,
- VLC_CANCEL_ADDR_SET,
- VLC_CANCEL_ADDR_CLEAR,
+ VLC_CANCEL_ADDR_SET, /* atomic_uint* or equivalent size */
+ VLC_CANCEL_ADDR_CLEAR, /* atomic_uint* or equivalent size */
};
#if defined (LIBVLC_USE_PTHREAD_CLEANUP)
diff --git a/src/android/thread.c b/src/android/thread.c
index ca715418d41..5e26d5566ac 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -139,7 +139,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;
@@ -284,7 +284,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);
@@ -341,7 +341,7 @@ void vlc_control_cancel(int cmd, ...)
{
case VLC_CANCEL_ADDR_SET:
{
- void *addr = va_arg(ap, void *);
+ atomic_uint *addr = va_arg(ap, atomic_uint *);
vlc_mutex_lock(&th->wait.lock);
assert(th->wait.addr == NULL);
@@ -352,7 +352,7 @@ void vlc_control_cancel(int cmd, ...)
case VLC_CANCEL_ADDR_CLEAR:
{
- void *addr = va_arg(ap, void *);
+ atomic_uint *addr = va_arg(ap, atomic_uint *);
vlc_mutex_lock(&th->wait.lock);
assert(th->wait.addr == addr);
diff --git a/src/misc/threads.c b/src/misc/threads.c
index e6b993c4408..18855e85bd4 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -149,27 +149,32 @@ bool vlc_mutex_marked(const vlc_mutex_t *mutex)
#if defined(LIBVLC_NEED_SLEEP) || defined(LIBVLC_NEED_CONDVAR)
#include <stdatomic.h>
-static inline void vlc_cancel_addr_set(void *addr)
+static inline void vlc_cancel_addr_set(atomic_uint *addr)
{
vlc_control_cancel(VLC_CANCEL_ADDR_SET, addr);
}
-static inline void vlc_cancel_addr_clear(void *addr)
+static inline void vlc_cancel_addr_clear(atomic_uint *addr)
{
vlc_control_cancel(VLC_CANCEL_ADDR_CLEAR, addr);
}
-static void vlc_cancel_addr_prepare(void *addr)
+static inline 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 */
@@ -181,7 +186,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);
@@ -268,13 +273,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,
@@ -291,7 +296,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)
@@ -300,7 +305,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 6af2eb83852..069c83dbd3a 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;
};
@@ -669,7 +669,7 @@ void vlc_control_cancel (int cmd, ...)
case VLC_CANCEL_ADDR_SET:
{
- void *addr = va_arg(ap, void *);
+ atomic_uint *addr = va_arg(ap, atomic_uint *);
EnterCriticalSection(&th->wait.lock);
assert(th->wait.addr == NULL);
@@ -680,7 +680,7 @@ void vlc_control_cancel (int cmd, ...)
case VLC_CANCEL_ADDR_CLEAR:
{
- void *addr = va_arg(ap, void *);
+ atomic_uint *addr = va_arg(ap, atomic_uint *);
EnterCriticalSection(&th->wait.lock);
assert(th->wait.addr == addr);
--
2.17.1
More information about the vlc-devel
mailing list