shithub: dav1d

Download patch

ref: ac7367d8f1accb013a65ffaa52bcd1fc8ba15126
parent: 755fcdf884aae9ee85ef611d24398a39da53f407
author: James Almer <jamrial@gmail.com>
date: Sat Sep 29 14:09:07 EDT 2018

threads: Inline some Windows pthreads compat wrappers in the header

They are all single line functions.

--- a/src/thread.h
+++ b/src/thread.h
@@ -42,22 +42,51 @@
 typedef void *pthread_condattr_t;
 typedef void *pthread_attr_t;
 
-void pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t* attr);
-void pthread_mutex_destroy(pthread_mutex_t* mutex);
-void pthread_mutex_lock(pthread_mutex_t* mutex);
-void pthread_mutex_unlock(pthread_mutex_t* mutex);
-
-void pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr);
-void pthread_cond_destroy(pthread_cond_t* cond);
-void pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex);
-void pthread_cond_signal(pthread_cond_t* cond);
-void pthread_cond_broadcast(pthread_cond_t* cond);
-
 int pthread_create(pthread_t* thread, const pthread_attr_t* attr,
                    void*(*proc)(void*), void* param);
 void pthread_join(pthread_t thread, void** res);
 
 int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));
+
+static inline void pthread_mutex_init(pthread_mutex_t* mutex,
+                                      const pthread_mutexattr_t* attr)
+{
+    (void)attr;
+    InitializeCriticalSection(mutex);
+}
+
+static inline void pthread_mutex_destroy(pthread_mutex_t* mutex) {
+    DeleteCriticalSection(mutex);
+}
+
+static inline void pthread_mutex_lock(pthread_mutex_t* mutex) {
+    EnterCriticalSection(mutex);
+}
+
+static inline void pthread_mutex_unlock(pthread_mutex_t* mutex) {
+    LeaveCriticalSection(mutex);
+}
+
+static inline void pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr) {
+    (void)attr;
+    InitializeConditionVariable(cond);
+}
+
+static inline void pthread_cond_destroy(pthread_cond_t* cond) {
+    (void)cond;
+}
+
+static inline void pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) {
+    SleepConditionVariableCS(cond, mutex, INFINITE);
+}
+
+static inline void pthread_cond_signal(pthread_cond_t* cond) {
+    WakeConditionVariable(cond);
+}
+
+static inline void pthread_cond_broadcast(pthread_cond_t* cond) {
+    WakeAllConditionVariable(cond);
+}
 
 #else
 
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -36,46 +36,6 @@
 #include "config.h"
 #include "src/thread.h"
 
-void pthread_mutex_init(pthread_mutex_t* mutex,
-                        const pthread_mutexattr_t* attr)
-{
-    (void)attr;
-    InitializeCriticalSection(mutex);
-}
-
-void pthread_mutex_destroy(pthread_mutex_t* mutex) {
-    DeleteCriticalSection(mutex);
-}
-
-void pthread_mutex_lock(pthread_mutex_t* mutex) {
-    EnterCriticalSection(mutex);
-}
-
-void pthread_mutex_unlock(pthread_mutex_t* mutex) {
-    LeaveCriticalSection(mutex);
-}
-
-void pthread_cond_init(pthread_cond_t* cond, const pthread_condattr_t* attr) {
-    (void)attr;
-    InitializeConditionVariable(cond);
-}
-
-void pthread_cond_destroy(pthread_cond_t* cond) {
-    (void)cond;
-}
-
-void pthread_cond_wait(pthread_cond_t* cond, pthread_mutex_t* mutex) {
-    SleepConditionVariableCS(cond, mutex, INFINITE);
-}
-
-void pthread_cond_signal(pthread_cond_t* cond) {
-    WakeConditionVariable(cond);
-}
-
-void pthread_cond_broadcast(pthread_cond_t* cond) {
-    WakeAllConditionVariable(cond);
-}
-
 typedef struct dav1d_win32_thread_t {
     HANDLE h;
     void* param;