@@ -56,6 +56,20 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags,
5656#endif
5757#endif
5858
59+ #if defined(__unix__ )
60+ #if !HAVE_UL_UNFAIR_LOCK && !HAVE_FUTEX_PI
61+ DISPATCH_ALWAYS_INLINE
62+ static inline void
63+ _dispatch_thread_switch (dispatch_lock value , dispatch_lock_options_t flags ,
64+ uint32_t timeout )
65+ {
66+ (void )value ;
67+ (void )flags ;
68+ (void )timeout ;
69+ }
70+ #endif
71+ #endif
72+
5973#pragma mark - semaphores
6074
6175#if USE_MACH_SEM
@@ -394,8 +408,10 @@ _dispatch_unfair_lock_wake(uint32_t *uaddr, uint32_t flags)
394408#include <sys/time.h>
395409#ifdef __ANDROID__
396410#include <sys/syscall.h>
397- #else
411+ #elif __linux__
398412#include <syscall.h>
413+ #else
414+ #include <sys/futex.h>
399415#endif /* __ANDROID__ */
400416
401417DISPATCH_ALWAYS_INLINE
@@ -404,7 +420,12 @@ _dispatch_futex(uint32_t *uaddr, int op, uint32_t val,
404420 const struct timespec * timeout , uint32_t * uaddr2 , uint32_t val3 ,
405421 int opflags )
406422{
423+ #if __linux__
407424 return (int )syscall (SYS_futex , uaddr , op | opflags , val , timeout , uaddr2 , val3 );
425+ #else
426+ (void )val3 ;
427+ return futex (uaddr , op | opflags , (int )val , timeout , uaddr2 );
428+ #endif
408429}
409430
410431// returns 0, ETIMEDOUT, EFAULT, EINTR, EWOULDBLOCK
@@ -454,6 +475,7 @@ _dispatch_futex_wake(uint32_t *uaddr, int wake, int opflags)
454475 DISPATCH_INTERNAL_CRASH (errno , "_dlock_wake() failed" );
455476}
456477
478+ #if HAVE_FUTEX_PI
457479static void
458480_dispatch_futex_lock_pi (uint32_t * uaddr , struct timespec * timeout , int detect ,
459481 int opflags )
@@ -471,6 +493,7 @@ _dispatch_futex_unlock_pi(uint32_t *uaddr, int opflags)
471493 if (rc == 0 ) return ;
472494 DISPATCH_CLIENT_CRASH (errno , "futex_unlock_pi() failed" );
473495}
496+ #endif
474497
475498#endif
476499#pragma mark - wait for address
@@ -605,7 +628,7 @@ _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t dul,
605628 }
606629 }
607630}
608- #elif HAVE_FUTEX
631+ #elif HAVE_FUTEX_PI
609632void
610633_dispatch_unfair_lock_lock_slow (dispatch_unfair_lock_t dul ,
611634 dispatch_lock_options_t flags )
@@ -642,7 +665,7 @@ _dispatch_unfair_lock_unlock_slow(dispatch_unfair_lock_t dul, dispatch_lock cur)
642665 if (_dispatch_lock_has_waiters (cur )) {
643666 _dispatch_unfair_lock_wake (& dul -> dul_lock , 0 );
644667 }
645- #elif HAVE_FUTEX
668+ #elif HAVE_FUTEX_PI
646669 // futex_unlock_pi() handles both OWNER_DIED which we abuse & WAITERS
647670 _dispatch_futex_unlock_pi (& dul -> dul_lock , FUTEX_PRIVATE_FLAG );
648671#else
0 commit comments