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.
This commit is contained in:
1 parent
9964104a6e
commit
38439dd531
3 files changed
+11
-59
No files matched your search
+3
-12
@@ -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;
|
||||
|
||||
+8
-36
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user