@@ -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
@@ -395,8 +409,10 @@ _dispatch_unfair_lock_wake(uint32_t *uaddr, uint32_t flags)
395409#include <sys/time.h>
396410#ifdef __ANDROID__
397411#include <sys/syscall.h>
398- #else
412+ #elif __linux__
399413#include <syscall.h>
414+ #else
415+ #include <sys/futex.h>
400416#endif /* __ANDROID__ */
401417
402418DISPATCH_ALWAYS_INLINE
@@ -405,7 +421,12 @@ _dispatch_futex(uint32_t *uaddr, int op, uint32_t val,
405421 const struct timespec * timeout , uint32_t * uaddr2 , uint32_t val3 ,
406422 int opflags )
407423{
424+ #if __linux__
408425 return (int )syscall (SYS_futex , uaddr , op | opflags , val , timeout , uaddr2 , val3 );
426+ #else
427+ (void )val3 ;
428+ return futex (uaddr , op | opflags , (int )val , timeout , uaddr2 );
429+ #endif
409430}
410431
411432// returns 0, ETIMEDOUT, EFAULT, EINTR, EWOULDBLOCK
@@ -455,6 +476,7 @@ _dispatch_futex_wake(uint32_t *uaddr, int wake, int opflags)
455476 DISPATCH_INTERNAL_CRASH (errno , "_dlock_wake() failed" );
456477}
457478
479+ #if HAVE_FUTEX_PI
458480static void
459481_dispatch_futex_lock_pi (uint32_t * uaddr , struct timespec * timeout , int detect ,
460482 int opflags )
@@ -472,6 +494,7 @@ _dispatch_futex_unlock_pi(uint32_t *uaddr, int opflags)
472494 if (rc == 0 ) return ;
473495 DISPATCH_CLIENT_CRASH (errno , "futex_unlock_pi() failed" );
474496}
497+ #endif
475498
476499#endif
477500#pragma mark - wait for address
@@ -606,7 +629,7 @@ _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t dul,
606629 }
607630 }
608631}
609- #elif HAVE_FUTEX
632+ #elif HAVE_FUTEX_PI
610633void
611634_dispatch_unfair_lock_lock_slow (dispatch_unfair_lock_t dul ,
612635 dispatch_lock_options_t flags )
@@ -643,7 +666,7 @@ _dispatch_unfair_lock_unlock_slow(dispatch_unfair_lock_t dul, dispatch_lock cur)
643666 if (_dispatch_lock_has_waiters (cur )) {
644667 _dispatch_unfair_lock_wake (& dul -> dul_lock , 0 );
645668 }
646- #elif HAVE_FUTEX
669+ #elif HAVE_FUTEX_PI
647670 // futex_unlock_pi() handles both OWNER_DIED which we abuse & WAITERS
648671 _dispatch_futex_unlock_pi (& dul -> dul_lock , FUTEX_PRIVATE_FLAG );
649672#else
0 commit comments