@@ -54,9 +54,20 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags,
54
54
SwitchToThread ();
55
55
}
56
56
#endif
57
- #endif
58
-
59
- #if defined(__unix__ )
57
+ #elif defined(__FreeBSD__ )
58
+ #if !HAVE_UL_UNFAIR_LOCK
59
+ DISPATCH_ALWAYS_INLINE
60
+ static inline void
61
+ _dispatch_thread_switch (dispatch_lock value , dispatch_lock_options_t flags ,
62
+ uint32_t timeout )
63
+ {
64
+ (void )value ;
65
+ (void )flags ;
66
+ (void )timeout ;
67
+ sched_yield ();
68
+ }
69
+ #endif // HAVE_UL_UNFAIR_LOCK
70
+ #elif defined(__unix__ )
60
71
#if !HAVE_UL_UNFAIR_LOCK && !HAVE_FUTEX_PI
61
72
DISPATCH_ALWAYS_INLINE
62
73
static inline void
@@ -539,6 +550,16 @@ _dispatch_wait_on_address(uint32_t volatile *_address, uint32_t value,
539
550
? INFINITE : ((nsecs + 1000000 ) / 1000000 );
540
551
if (dwMilliseconds == 0 ) return ETIMEDOUT ;
541
552
return WaitOnAddress (address , & value , sizeof (value ), dwMilliseconds ) == TRUE;
553
+ #elif defined(__FreeBSD__ )
554
+ (void )flags ;
555
+ if (nsecs != DISPATCH_TIME_FOREVER ) {
556
+ struct timespec ts = {
557
+ .tv_sec = (__typeof__ (ts .tv_sec ))(nsecs / NSEC_PER_SEC ),
558
+ .tv_nsec = (__typeof__ (ts .tv_nsec ))(nsecs % NSEC_PER_SEC ),
559
+ };
560
+ return _umtx_op ((void * )address , UMTX_OP_WAIT_UINT , value , (void * )(uintptr_t )sizeof (struct timespec ), (void * )& ts );
561
+ }
562
+ return _umtx_op ((void * )address , UMTX_OP_WAIT_UINT , value , 0 , 0 );
542
563
#else
543
564
#error _dispatch_wait_on_address unimplemented for this platform
544
565
#endif
@@ -553,6 +574,8 @@ _dispatch_wake_by_address(uint32_t volatile *address)
553
574
_dispatch_futex_wake ((uint32_t * )address , INT_MAX , FUTEX_PRIVATE_FLAG );
554
575
#elif defined(_WIN32 )
555
576
WakeByAddressAll ((uint32_t * )address );
577
+ #elif defined(__FreeBSD__ )
578
+ _umtx_op ((void * )address , UMTX_OP_WAKE , INT_MAX , 0 , 0 );
556
579
#else
557
580
(void )address ;
558
581
#endif
@@ -712,7 +735,7 @@ _dispatch_once_wait(dispatch_once_gate_t dgo)
712
735
_dispatch_futex_wait (lock , (dispatch_lock )new_v , NULL ,
713
736
FUTEX_PRIVATE_FLAG );
714
737
#else
715
- _dispatch_thread_switch (new_v , 0 , timeout ++ );
738
+ _dispatch_thread_switch (( dispatch_lock ) new_v , 0 , timeout ++ );
716
739
#endif
717
740
(void )timeout ;
718
741
}
0 commit comments