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);