@@ -56,6 +56,20 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags,
56
56
#endif
57
57
#endif
58
58
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
+
59
73
#pragma mark - semaphores
60
74
61
75
#if USE_MACH_SEM
@@ -395,8 +409,10 @@ _dispatch_unfair_lock_wake(uint32_t *uaddr, uint32_t flags)
395
409
#include <sys/time.h>
396
410
#ifdef __ANDROID__
397
411
#include <sys/syscall.h>
398
- #else
412
+ #elif __linux__
399
413
#include <syscall.h>
414
+ #else
415
+ #include <sys/futex.h>
400
416
#endif /* __ANDROID__ */
401
417
402
418
DISPATCH_ALWAYS_INLINE
@@ -405,7 +421,12 @@ _dispatch_futex(uint32_t *uaddr, int op, uint32_t val,
405
421
const struct timespec * timeout , uint32_t * uaddr2 , uint32_t val3 ,
406
422
int opflags )
407
423
{
424
+ #if __linux__
408
425
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
409
430
}
410
431
411
432
// returns 0, ETIMEDOUT, EFAULT, EINTR, EWOULDBLOCK
@@ -455,6 +476,7 @@ _dispatch_futex_wake(uint32_t *uaddr, int wake, int opflags)
455
476
DISPATCH_INTERNAL_CRASH (errno , "_dlock_wake() failed" );
456
477
}
457
478
479
+ #if HAVE_FUTEX_PI
458
480
static void
459
481
_dispatch_futex_lock_pi (uint32_t * uaddr , struct timespec * timeout , int detect ,
460
482
int opflags )
@@ -472,6 +494,7 @@ _dispatch_futex_unlock_pi(uint32_t *uaddr, int opflags)
472
494
if (rc == 0 ) return ;
473
495
DISPATCH_CLIENT_CRASH (errno , "futex_unlock_pi() failed" );
474
496
}
497
+ #endif
475
498
476
499
#endif
477
500
#pragma mark - wait for address
@@ -606,7 +629,7 @@ _dispatch_unfair_lock_lock_slow(dispatch_unfair_lock_t dul,
606
629
}
607
630
}
608
631
}
609
- #elif HAVE_FUTEX
632
+ #elif HAVE_FUTEX_PI
610
633
void
611
634
_dispatch_unfair_lock_lock_slow (dispatch_unfair_lock_t dul ,
612
635
dispatch_lock_options_t flags )
@@ -643,7 +666,7 @@ _dispatch_unfair_lock_unlock_slow(dispatch_unfair_lock_t dul, dispatch_lock cur)
643
666
if (_dispatch_lock_has_waiters (cur )) {
644
667
_dispatch_unfair_lock_wake (& dul -> dul_lock , 0 );
645
668
}
646
- #elif HAVE_FUTEX
669
+ #elif HAVE_FUTEX_PI
647
670
// futex_unlock_pi() handles both OWNER_DIED which we abuse & WAITERS
648
671
_dispatch_futex_unlock_pi (& dul -> dul_lock , FUTEX_PRIVATE_FLAG );
649
672
#else
0 commit comments