@@ -6472,7 +6472,7 @@ _dispatch_runloop_handle_is_valid(dispatch_runloop_handle_t handle)
6472
6472
{
6473
6473
#if TARGET_OS_MAC
6474
6474
return MACH_PORT_VALID (handle );
6475
- #elif defined(__linux__ )
6475
+ #elif defined(__linux__ ) || defined( __unix__ )
6476
6476
return handle >= 0 ;
6477
6477
#elif defined(_WIN32 )
6478
6478
return handle != NULL ;
@@ -6490,6 +6490,8 @@ _dispatch_runloop_queue_get_handle(dispatch_lane_t dq)
6490
6490
#elif defined(__linux__ )
6491
6491
// decode: 0 is a valid fd, so offset by 1 to distinguish from NULL
6492
6492
return ((dispatch_runloop_handle_t )(uintptr_t )dq -> do_ctxt ) - 1 ;
6493
+ #elif defined(__unix__ ) && !defined(__linux__ )
6494
+ return ((dispatch_runloop_handle_t )(uintptr_t )dq -> do_ctxt );
6493
6495
#elif defined(_WIN32 )
6494
6496
return ((dispatch_runloop_handle_t )(uintptr_t )dq -> do_ctxt );
6495
6497
#else
@@ -6507,13 +6509,21 @@ _dispatch_runloop_queue_set_handle(dispatch_lane_t dq,
6507
6509
#elif defined(__linux__ )
6508
6510
// encode: 0 is a valid fd, so offset by 1 to distinguish from NULL
6509
6511
dq -> do_ctxt = (void * )(uintptr_t )(handle + 1 );
6512
+ #elif defined(__unix__ ) && !defined(__linux__ )
6513
+ dq -> do_ctxt = (void * )(uintptr_t )handle ;
6510
6514
#elif defined(_WIN32 )
6511
6515
dq -> do_ctxt = (void * )(uintptr_t )handle ;
6512
6516
#else
6513
6517
#error "runloop support not implemented on this platform"
6514
6518
#endif
6515
6519
}
6516
6520
6521
+ #if defined(__unix__ )
6522
+ #define DISPATCH_RUNLOOP_HANDLE_PACK (rfd , wfd ) (((uint64_t)(rfd) << 32) | (wfd))
6523
+ #define DISPATCH_RUNLOOP_HANDLE_RFD (h ) ((int)((h) >> 32))
6524
+ #define DISPATCH_RUNLOOP_HANDLE_WFD (h ) ((int)((h) & 0xffffffff))
6525
+ #endif
6526
+
6517
6527
static void
6518
6528
_dispatch_runloop_queue_handle_init (void * ctxt )
6519
6529
{
@@ -6563,6 +6573,14 @@ _dispatch_runloop_queue_handle_init(void *ctxt)
6563
6573
}
6564
6574
}
6565
6575
handle = fd ;
6576
+ #elif defined(__unix__ ) && !defined(__linux__ )
6577
+ int fds [2 ];
6578
+ int r = pipe2 (fds , O_CLOEXEC | O_NONBLOCK );
6579
+ if (r == -1 ) {
6580
+ DISPATCH_CLIENT_CRASH (errno , "pipe2 failure" );
6581
+ }
6582
+ uint32_t rfd = (uint32_t )fds [0 ], wfd = (uint32_t )fds [1 ];
6583
+ handle = DISPATCH_RUNLOOP_HANDLE_PACK (rfd , wfd );
6566
6584
#elif defined(_WIN32 )
6567
6585
HANDLE hEvent ;
6568
6586
hEvent = CreateEventW (NULL , /*bManualReset=*/ FALSE,
@@ -6597,6 +6615,11 @@ _dispatch_runloop_queue_handle_dispose(dispatch_lane_t dq)
6597
6615
#elif defined(__linux__ )
6598
6616
int rc = close (handle );
6599
6617
(void )dispatch_assume_zero (rc );
6618
+ #elif defined(__unix__ ) && !defined(__linux__ )
6619
+ int rc = close (DISPATCH_RUNLOOP_HANDLE_WFD (handle ));
6620
+ (void )dispatch_assume_zero (rc );
6621
+ rc = close (DISPATCH_RUNLOOP_HANDLE_RFD (handle ));
6622
+ (void )dispatch_assume_zero (rc );
6600
6623
#elif defined(_WIN32 )
6601
6624
BOOL bSuccess ;
6602
6625
bSuccess = CloseHandle (handle );
@@ -6633,6 +6656,13 @@ _dispatch_runloop_queue_class_poke(dispatch_lane_t dq)
6633
6656
result = eventfd_write (handle , 1 );
6634
6657
} while (result == -1 && errno == EINTR );
6635
6658
(void )dispatch_assume_zero (result );
6659
+ #elif defined(__unix__ ) && !defined(__linux__ )
6660
+ int wfd = DISPATCH_RUNLOOP_HANDLE_WFD (handle );
6661
+ ssize_t result ;
6662
+ do {
6663
+ result = write (wfd , "x" , 1 );
6664
+ } while (result == -1 && errno == EINTR );
6665
+ (void )dispatch_assume_zero (result - 1 );
6636
6666
#elif defined(_WIN32 )
6637
6667
BOOL bSuccess ;
6638
6668
bSuccess = SetEvent (handle );
@@ -7311,6 +7341,13 @@ _gettid(void)
7311
7341
{
7312
7342
return (pid_t )pthread_getthreadid_np ();
7313
7343
}
7344
+ #elif defined(__OpenBSD__ )
7345
+ DISPATCH_ALWAYS_INLINE
7346
+ static inline pid_t
7347
+ _gettid (void )
7348
+ {
7349
+ return getthrid ();
7350
+ }
7314
7351
#elif defined(_WIN32 )
7315
7352
DISPATCH_ALWAYS_INLINE
7316
7353
static inline DWORD
0 commit comments