1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-16 12:17:12 +00:00

win32/pthread: add support for pthread_mutex_trylock

This commit is contained in:
Thomas Weißschuh 2023-10-15 19:48:07 +02:00 committed by sfan5
parent 2181159158
commit dd13412986
2 changed files with 11 additions and 0 deletions

View File

@ -33,6 +33,7 @@
#define pthread_mutex_destroy m_pthread_mutex_destroy
#define pthread_mutex_init m_pthread_mutex_init
#define pthread_mutex_lock m_pthread_mutex_lock
#define pthread_mutex_trylock m_pthread_mutex_trylock
#define pthread_mutex_unlock m_pthread_mutex_unlock
#define pthread_cond_timedwait m_pthread_cond_timedwait
#define pthread_cond_wait m_pthread_cond_wait
@ -71,6 +72,7 @@ int pthread_mutex_init(pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr);
int pthread_mutex_lock(pthread_mutex_t *mutex);
int pthread_mutex_trylock(pthread_mutex_t *mutex);
int pthread_mutex_unlock(pthread_mutex_t *mutex);
#define pthread_cond_t CONDITION_VARIABLE

View File

@ -66,6 +66,15 @@ int pthread_mutex_lock(pthread_mutex_t *mutex)
return 0;
}
int pthread_mutex_trylock(pthread_mutex_t *mutex)
{
if (mutex->use_cs) {
return !TryEnterCriticalSection(&mutex->lock.cs);
} else {
return !TryAcquireSRWLockExclusive(&mutex->lock.srw);
}
}
int pthread_mutex_unlock(pthread_mutex_t *mutex)
{
if (mutex->use_cs) {