@@ -56,6 +56,18 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags,
5656#endif
5757#endif
5858
59+ #if defined(__unix__ )
60+ DISPATCH_ALWAYS_INLINE
61+ static inline void
62+ _dispatch_thread_switch (dispatch_lock value , dispatch_lock_options_t flags ,
63+ uint32_t timeout )
64+ {
65+ (void )value ;
66+ (void )flags ;
67+ (void )timeout ;
68+ }
69+ #endif
70+
5971#pragma mark - semaphores
6072
6173#if USE_MACH_SEM
@@ -394,8 +406,10 @@ _dispatch_unfair_lock_wake(uint32_t *uaddr, uint32_t flags)
394406#include <sys/time.h>
395407#ifdef __ANDROID__
396408#include <sys/syscall.h>
397- #else
409+ #elif __linux__
398410#include <syscall.h>
411+ #else
412+ #include <sys/futex.h>
399413#endif /* __ANDROID__ */
400414
401415DISPATCH_ALWAYS_INLINE
@@ -404,7 +418,12 @@ _dispatch_futex(uint32_t *uaddr, int op, uint32_t val,
404418 const struct timespec * timeout , uint32_t * uaddr2 , uint32_t val3 ,
405419 int opflags )
406420{
421+ #if __linux__
407422 return (int )syscall (SYS_futex , uaddr , op | opflags , val , timeout , uaddr2 , val3 );
423+ #else
424+ (void )val3 ;
425+ return futex (uaddr , op | opflags , (int )val , timeout , uaddr2 );
426+ #endif
408427}
409428
410429// returns 0, ETIMEDOUT, EFAULT, EINTR, EWOULDBLOCK
@@ -454,6 +473,7 @@ _dispatch_futex_wake(uint32_t *uaddr, int wake, int opflags)
454473 DISPATCH_INTERNAL_CRASH (errno , "_dlock_wake() failed" );
455474}
456475
476+ #if HAVE_FUTEX_PI
457477static void
458478_dispatch_futex_lock_pi (uint32_t * uaddr , struct timespec * timeout , int detect ,
459479 int opflags )
@@ -471,6 +491,7 @@ _dispatch_futex_unlock_pi(uint32_t *uaddr, int opflags)
471491 if (rc == 0 ) return ;
472492 DISPATCH_CLIENT_CRASH (errno , "futex_unlock_pi() failed" );
473493}
494+ #endif
474495
475496#endif
476497#pragma mark - wait for address
@@ -605,7 +626,7 @@ _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t dul,
605626 }
606627 }
607628}
608- #elif HAVE_FUTEX
629+ #elif HAVE_FUTEX_PI
609630void
610631_dispatch_unfair_lock_lock_slow (dispatch_unfair_lock_t dul ,
611632 dispatch_lock_options_t flags )
@@ -642,7 +663,7 @@ _dispatch_unfair_lock_unlock_slow(dispatch_unfair_lock_t dul, dispatch_lock cur)
642663 if (_dispatch_lock_has_waiters (cur )) {
643664 _dispatch_unfair_lock_wake (& dul -> dul_lock , 0 );
644665 }
645- #elif HAVE_FUTEX
666+ #elif HAVE_FUTEX_PI
646667 // futex_unlock_pi() handles both OWNER_DIED which we abuse & WAITERS
647668 _dispatch_futex_unlock_pi (& dul -> dul_lock , FUTEX_PRIVATE_FLAG );
648669#else
0 commit comments