[vlc-commits] [Git][videolan/vlc][master] 2 commits: android: appropriate the LIBVLC_NEED_SLEEP code
Rémi Denis-Courmont (@Courmisch)
gitlab at videolan.org
Fri Oct 1 14:09:15 UTC 2021
Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC
Commits:
9c3904c2 by Rémi Denis-Courmont at 2021-10-01T13:54:04+00:00
android: appropriate the LIBVLC_NEED_SLEEP code
No functional changes.
- - - - -
f7414320 by Rémi Denis-Courmont at 2021-10-01T13:54:04+00:00
android: remove vlc_cancel_addr_*()
- - - - -
3 changed files:
- include/vlc_threads.h
- src/android/thread.c
- src/misc/threads.c
Changes:
=====================================
include/vlc_threads.h
=====================================
@@ -124,7 +124,6 @@ static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
# include <pthread.h>
# include <poll.h>
# define LIBVLC_USE_PTHREAD_CLEANUP 1
-# define LIBVLC_NEED_SLEEP
typedef struct vlc_thread *vlc_thread_t;
#define VLC_THREAD_CANCELED NULL
@@ -1050,10 +1049,7 @@ static inline void vlc_cleanup_lock (void *lock)
}
#define mutex_cleanup_push( lock ) vlc_cleanup_push (vlc_cleanup_lock, lock)
-#ifndef __cplusplus
-void vlc_cancel_addr_set(atomic_uint *addr);
-void vlc_cancel_addr_clear(atomic_uint *addr);
-#else
+#ifdef __cplusplus
/**
* Helper C++ class to lock a mutex.
*
=====================================
src/android/thread.c
=====================================
@@ -74,13 +74,7 @@ struct vlc_thread
void *(*entry)(void*);
void *data;
- struct
- {
- atomic_uint *addr; /// Non-null if waiting on futex
- vlc_mutex_t lock ; /// Protects futex address
- } wait;
-
- atomic_bool killed;
+ atomic_uint killed;
bool killable;
};
@@ -126,8 +120,6 @@ static int vlc_clone_attr (vlc_thread_t *th, void *(*entry) (void *),
thread->killable = true;
thread->entry = entry;
thread->data = data;
- thread->wait.addr = NULL;
- vlc_mutex_init(&thread->wait.lock);
pthread_attr_t attr;
pthread_attr_init (&attr);
@@ -166,18 +158,8 @@ int vlc_set_priority (vlc_thread_t th, int priority)
void vlc_cancel (vlc_thread_t thread_id)
{
- atomic_uint *addr;
-
atomic_store(&thread_id->killed, true);
-
- vlc_mutex_lock(&thread_id->wait.lock);
- addr = thread_id->wait.addr;
- if (addr != NULL)
- {
- atomic_fetch_or_explicit(addr, 1, memory_order_relaxed);
- vlc_atomic_notify_all(addr);
- }
- vlc_mutex_unlock(&thread_id->wait.lock);
+ vlc_atomic_notify_one(&thread_id->killed);
}
int vlc_savecancel (void)
@@ -210,31 +192,6 @@ void vlc_testcancel (void)
pthread_exit(NULL);
}
-void vlc_cancel_addr_set(atomic_uint *addr)
-{
- vlc_thread_t th = thread;
- 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(atomic_uint *addr)
-{
- vlc_thread_t th = thread;
- if (th == NULL)
- return;
-
- vlc_mutex_lock(&th->wait.lock);
- assert(th->wait.addr == addr);
- th->wait.addr = NULL;
- (void) addr;
- vlc_mutex_unlock(&th->wait.lock);
-}
-
/* threadvar */
int vlc_threadvar_create (vlc_threadvar_t *key, void (*destr) (void *))
@@ -258,6 +215,18 @@ void *vlc_threadvar_get (vlc_threadvar_t key)
}
/* time */
+void (vlc_tick_wait)(vlc_tick_t deadline)
+{
+ do
+ vlc_testcancel();
+ while (vlc_atomic_timedwait(&thread->killed, false, deadline) == 0);
+}
+
+void (vlc_tick_sleep)(vlc_tick_t delay)
+{
+ vlc_tick_wait(vlc_tick_now() + delay);
+}
+
vlc_tick_t vlc_tick_now (void)
{
struct timespec ts;
=====================================
src/misc/threads.c
=====================================
@@ -62,47 +62,6 @@ void vlc_global_mutex (unsigned n, bool acquire)
vlc_mutex_unlock (lock);
}
-#ifdef LIBVLC_NEED_SLEEP
-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(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(atomic_uint *addr)
-{
- vlc_cancel_addr_clear(addr);
- /* Act on cancellation as potential wake-up source */
- vlc_testcancel();
-}
-
-void (vlc_tick_wait)(vlc_tick_t deadline)
-{
- atomic_uint value = ATOMIC_VAR_INIT(0);
-
- vlc_cancel_addr_prepare(&value);
-
- while (vlc_atomic_timedwait(&value, 0, deadline) == 0)
- vlc_testcancel();
-
- vlc_cancel_addr_finish(&value);
-}
-
-void (vlc_tick_sleep)(vlc_tick_t delay)
-{
- vlc_tick_wait(vlc_tick_now() + delay);
-}
-#endif
-
static void vlc_mutex_init_common(vlc_mutex_t *mtx, bool recursive)
{
atomic_init(&mtx->value, 0);
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7ff2c1aa9f7582671292c237ec9a864ebada9ae1...f7414320b1fe77ed6dd7bfc6392c597563af5667
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/7ff2c1aa9f7582671292c237ec9a864ebada9ae1...f7414320b1fe77ed6dd7bfc6392c597563af5667
You're receiving this email because of your account on code.videolan.org.
More information about the vlc-commits
mailing list