summaryrefslogtreecommitdiffstats
path: root/osdep/win32/include/pthread.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-05-24 18:45:40 +0200
committerwm4 <wm4@nowhere>2016-05-24 19:02:22 +0200
commitb9cc33de58c3e58a93c5e5316e5734922f5a44b9 (patch)
tree60862bc79e8bdb76bfba9cb1d5d7e7cb9191d403 /osdep/win32/include/pthread.h
parent8ff96f0216884f9bd3c60857e629a25aaa8704de (diff)
downloadmpv-b9cc33de58c3e58a93c5e5316e5734922f5a44b9.tar.bz2
mpv-b9cc33de58c3e58a93c5e5316e5734922f5a44b9.tar.xz
win32: pthread: use SRW locks by default
SRW locks are available since Windows Vista. They work essentially like Linux futexes. In particular, they can be statically initialized, and do not require deinitialization. This makes them ideal for implementing PTHREAD_MUTEX_INITIALIZER. We still need CRITICAL_SECTION for recursive mutexes.
Diffstat (limited to 'osdep/win32/include/pthread.h')
-rw-r--r--osdep/win32/include/pthread.h16
1 files changed, 9 insertions, 7 deletions
diff --git a/osdep/win32/include/pthread.h b/osdep/win32/include/pthread.h
index 7b82eb2651..e1324a0bb0 100644
--- a/osdep/win32/include/pthread.h
+++ b/osdep/win32/include/pthread.h
@@ -25,19 +25,21 @@
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
typedef struct {
- char static_mutex;
- INIT_ONCE static_init;
- CRITICAL_SECTION cs;
+ char use_cs;
+ union {
+ SRWLOCK srw;
+ CRITICAL_SECTION cs;
+ } lock;
} pthread_mutex_t;
-#define PTHREAD_MUTEX_INITIALIZER {1, INIT_ONCE_STATIC_INIT}
+// Assume SRWLOCK_INIT is {0} so we can easily remain C89-compatible.
+#define PTHREAD_MUTEX_INITIALIZER {0}
#define pthread_mutexattr_t int
#define pthread_mutexattr_destroy(attr) (void)0
#define pthread_mutexattr_init(attr) (*(attr) = 0)
-#define pthread_mutexattr_settype(attr, type) (void)0
-// CRITICAL_SECTION is always recursive
-#define PTHREAD_MUTEX_RECURSIVE 0
+#define pthread_mutexattr_settype(attr, type) (*(attr) = (type))
+#define PTHREAD_MUTEX_RECURSIVE 1
int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_init(pthread_mutex_t *restrict mutex,