From 9324136f52072f84085ec0a32c795a11b8c9f23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 26 Jan 2025 09:49:31 +0800 Subject: [PATCH] Thread: optimise locking (unused though) --- src/common/thread.h | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/common/thread.h b/src/common/thread.h index 62c8cc056..4d25dd505 100644 --- a/src/common/thread.h +++ b/src/common/thread.h @@ -36,11 +36,19 @@ #if FF_HAVE_PTHREAD_NP #include #endif - #define FF_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER - typedef pthread_mutex_t FFThreadMutex; typedef pthread_t FFThreadType; - static inline void ffThreadMutexLock(FFThreadMutex* mutex) { pthread_mutex_lock(mutex); } - static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { pthread_mutex_unlock(mutex); } + #if __APPLE__ + #include + #define FF_THREAD_MUTEX_INITIALIZER OS_UNFAIR_LOCK_INIT + typedef os_unfair_lock FFThreadMutex; + static inline void ffThreadMutexLock(os_unfair_lock* mutex) { os_unfair_lock_lock(mutex); } + static inline void ffThreadMutexUnlock(os_unfair_lock* mutex) { os_unfair_lock_unlock(mutex); } + #else + #define FF_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER + typedef pthread_mutex_t FFThreadMutex; + static inline void ffThreadMutexLock(FFThreadMutex* mutex) { pthread_mutex_lock(mutex); } + static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { pthread_mutex_unlock(mutex); } + #endif static inline FFThreadType ffThreadCreate(void* (* func)(void*), void* data) { FFThreadType newThread = 0; pthread_create(&newThread, NULL, func, data);