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