Skip to content

Commit 9324136

Browse files
committed
Thread: optimise locking (unused though)
1 parent f601d2d commit 9324136

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/common/thread.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,19 @@
3636
#if FF_HAVE_PTHREAD_NP
3737
#include <pthread_np.h>
3838
#endif
39-
#define FF_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
40-
typedef pthread_mutex_t FFThreadMutex;
4139
typedef pthread_t FFThreadType;
42-
static inline void ffThreadMutexLock(FFThreadMutex* mutex) { pthread_mutex_lock(mutex); }
43-
static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { pthread_mutex_unlock(mutex); }
40+
#if __APPLE__
41+
#include <os/lock.h>
42+
#define FF_THREAD_MUTEX_INITIALIZER OS_UNFAIR_LOCK_INIT
43+
typedef os_unfair_lock FFThreadMutex;
44+
static inline void ffThreadMutexLock(os_unfair_lock* mutex) { os_unfair_lock_lock(mutex); }
45+
static inline void ffThreadMutexUnlock(os_unfair_lock* mutex) { os_unfair_lock_unlock(mutex); }
46+
#else
47+
#define FF_THREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
48+
typedef pthread_mutex_t FFThreadMutex;
49+
static inline void ffThreadMutexLock(FFThreadMutex* mutex) { pthread_mutex_lock(mutex); }
50+
static inline void ffThreadMutexUnlock(FFThreadMutex* mutex) { pthread_mutex_unlock(mutex); }
51+
#endif
4452
static inline FFThreadType ffThreadCreate(void* (* func)(void*), void* data) {
4553
FFThreadType newThread = 0;
4654
pthread_create(&newThread, NULL, func, data);

0 commit comments

Comments
 (0)