From 38439dd531e5d7041f7a44a5a7c11247656a2166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Mon, 3 Mar 2025 12:42:07 +0100 Subject: [PATCH] threads: remove unused recursive mutex support After removal of `MP_MUTEX_RECURSIVE` from vdpau.c there are no more clients of recursive mutex. Remove all the code related to it. This commit can be reverted if in the future it is needed again. For now let's not keep dead code. --- osdep/threads-posix.h | 15 +++------------ osdep/threads-win32.h | 44 ++++++++----------------------------------- osdep/threads.h | 11 ----------- 3 files changed, 11 insertions(+), 59 deletions(-) diff --git a/osdep/threads-posix.h b/osdep/threads-posix.h index 469bbc02e6..cce64b1f82 100644 --- a/osdep/threads-posix.h +++ b/osdep/threads-posix.h @@ -106,22 +106,13 @@ typedef pthread_t mp_thread; #define MP_STATIC_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER #define MP_STATIC_ONCE_INITIALIZER PTHREAD_ONCE_INIT -static inline int mp_mutex_init_type_internal(mp_mutex *mutex, enum mp_mutex_type mtype) +static inline int mp_mutex_init(mp_mutex *mutex) { - int mutex_type; - switch (mtype) { - case MP_MUTEX_RECURSIVE: - mutex_type = PTHREAD_MUTEX_RECURSIVE; - break; - case MP_MUTEX_NORMAL: - default: #ifndef NDEBUG - mutex_type = PTHREAD_MUTEX_ERRORCHECK; + int mutex_type = PTHREAD_MUTEX_ERRORCHECK; #else - mutex_type = PTHREAD_MUTEX_DEFAULT; + int mutex_type = PTHREAD_MUTEX_DEFAULT; #endif - break; - } int ret = 0; pthread_mutexattr_t attr; diff --git a/osdep/threads-win32.h b/osdep/threads-win32.h index c55406badc..7410ad8ce4 100644 --- a/osdep/threads-win32.h +++ b/osdep/threads-win32.h @@ -24,64 +24,42 @@ #include "common/common.h" #include "timer.h" -typedef struct { - char use_cs; - union { - CRITICAL_SECTION cs; - SRWLOCK srw; - }; -} mp_mutex; - typedef CONDITION_VARIABLE mp_cond; typedef INIT_ONCE mp_once; +typedef SRWLOCK mp_mutex; typedef mp_mutex mp_static_mutex; typedef HANDLE mp_thread; typedef DWORD mp_thread_id; #define MP_STATIC_COND_INITIALIZER CONDITION_VARIABLE_INIT -#define MP_STATIC_MUTEX_INITIALIZER { .srw = SRWLOCK_INIT } +#define MP_STATIC_MUTEX_INITIALIZER SRWLOCK_INIT #define MP_STATIC_ONCE_INITIALIZER INIT_ONCE_STATIC_INIT -static inline int mp_mutex_init_type_internal(mp_mutex *mutex, enum mp_mutex_type mtype) +static inline int mp_mutex_init(mp_mutex *mutex) { - mutex->use_cs = mtype == MP_MUTEX_RECURSIVE; - if (mutex->use_cs) - return !InitializeCriticalSectionEx(&mutex->cs, 0, 0); - InitializeSRWLock(&mutex->srw); + InitializeSRWLock(mutex); return 0; } static inline int mp_mutex_destroy(mp_mutex *mutex) { - if (mutex->use_cs) - DeleteCriticalSection(&mutex->cs); return 0; } static inline int mp_mutex_lock(mp_mutex *mutex) { - if (mutex->use_cs) { - EnterCriticalSection(&mutex->cs); - } else { - AcquireSRWLockExclusive(&mutex->srw); - } + AcquireSRWLockExclusive(mutex); return 0; } static inline int mp_mutex_trylock(mp_mutex *mutex) { - if (mutex->use_cs) - return !TryEnterCriticalSection(&mutex->cs); - return !TryAcquireSRWLockExclusive(&mutex->srw); + return !TryAcquireSRWLockExclusive(mutex); } static inline int mp_mutex_unlock(mp_mutex *mutex) { - if (mutex->use_cs) { - LeaveCriticalSection(&mutex->cs); - } else { - ReleaseSRWLockExclusive(&mutex->srw); - } + ReleaseSRWLockExclusive(mutex); return 0; } @@ -116,14 +94,8 @@ static inline int mp_cond_timedwait(mp_cond *cond, mp_mutex *mutex, int64_t time int ret = 0; int64_t hrt = mp_start_hires_timers(MP_TIME_MS_TO_NS(timeout)); - BOOL bRet; - if (mutex->use_cs) { - bRet = SleepConditionVariableCS(cond, &mutex->cs, timeout); - } else { - bRet = SleepConditionVariableSRW(cond, &mutex->srw, timeout, 0); - } - if (bRet == FALSE) + if (!SleepConditionVariableSRW(cond, mutex, timeout, 0)) ret = GetLastError() == ERROR_TIMEOUT ? ETIMEDOUT : EINVAL; mp_end_hires_timers(hrt); diff --git a/osdep/threads.h b/osdep/threads.h index b6d950e5de..4e9cf97baf 100644 --- a/osdep/threads.h +++ b/osdep/threads.h @@ -3,17 +3,6 @@ #include "config.h" -enum mp_mutex_type { - MP_MUTEX_NORMAL = 0, - MP_MUTEX_RECURSIVE, -}; - -#define mp_mutex_init(mutex) \ - mp_mutex_init_type(mutex, MP_MUTEX_NORMAL) - -#define mp_mutex_init_type(mutex, mtype) \ - mp_mutex_init_type_internal(mutex, mtype) - #if HAVE_WIN32_THREADS #include "threads-win32.h" #else