@@ -54,9 +54,20 @@ _dispatch_thread_switch(dispatch_lock value, dispatch_lock_options_t flags,
5454 SwitchToThread ();
5555}
5656#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__ )
6071#if !HAVE_UL_UNFAIR_LOCK && !HAVE_FUTEX_PI
6172DISPATCH_ALWAYS_INLINE
6273static inline void
@@ -539,6 +550,16 @@ _dispatch_wait_on_address(uint32_t volatile *_address, uint32_t value,
539550 ? INFINITE : ((nsecs + 1000000 ) / 1000000 );
540551 if (dwMilliseconds == 0 ) return ETIMEDOUT ;
541552 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 );
542563#else
543564#error _dispatch_wait_on_address unimplemented for this platform
544565#endif
@@ -553,6 +574,8 @@ _dispatch_wake_by_address(uint32_t volatile *address)
553574 _dispatch_futex_wake ((uint32_t * )address , INT_MAX , FUTEX_PRIVATE_FLAG );
554575#elif defined(_WIN32 )
555576 WakeByAddressAll ((uint32_t * )address );
577+ #elif defined(__FreeBSD__ )
578+ _umtx_op ((void * )address , UMTX_OP_WAKE , INT_MAX , 0 , 0 );
556579#else
557580 (void )address ;
558581#endif
@@ -712,7 +735,7 @@ _dispatch_once_wait(dispatch_once_gate_t dgo)
712735 _dispatch_futex_wait (lock , (dispatch_lock )new_v , NULL ,
713736 FUTEX_PRIVATE_FLAG );
714737#else
715- _dispatch_thread_switch (new_v , 0 , timeout ++ );
738+ _dispatch_thread_switch (( dispatch_lock ) new_v , 0 , timeout ++ );
716739#endif
717740 (void )timeout ;
718741 }
0 commit comments