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