summaryrefslogtreecommitdiffstats
path: root/osdep/win32
diff options
context:
space:
mode:
authorThomas Weißschuh <thomas@t-8ch.de>2023-10-15 19:48:07 +0200
committersfan5 <sfan5@live.de>2023-10-20 21:33:46 +0200
commitdd13412986e52671b1e19c6c7ddb81593b5d211f (patch)
tree66dae32777cf5f03904f77a1f8560d4609bd5870 /osdep/win32
parent218115915839cde153e7c4e2110e6324e7d633c6 (diff)
downloadmpv-dd13412986e52671b1e19c6c7ddb81593b5d211f.tar.bz2
mpv-dd13412986e52671b1e19c6c7ddb81593b5d211f.tar.xz
win32/pthread: add support for pthread_mutex_trylock
Diffstat (limited to 'osdep/win32')
-rw-r--r--osdep/win32/include/pthread.h2
-rw-r--r--osdep/win32/pthread.c9
2 files changed, 11 insertions, 0 deletions
diff --git a/osdep/win32/include/pthread.h b/osdep/win32/include/pthread.h
index b955e722ae..71dc8084a4 100644
--- a/osdep/win32/include/pthread.h
+++ b/osdep/win32/include/pthread.h
@@ -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
diff --git a/osdep/win32/pthread.c b/osdep/win32/pthread.c
index 9bc7f0057d..11a0c50476 100644
--- a/osdep/win32/pthread.c
+++ b/osdep/win32/pthread.c
@@ -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) {