@@ -6467,7 +6467,7 @@ _dispatch_runloop_handle_is_valid(dispatch_runloop_handle_t handle)
6467
6467
{
6468
6468
#if TARGET_OS_MAC
6469
6469
return MACH_PORT_VALID (handle );
6470
- #elif defined(__linux__ )
6470
+ #elif defined(__linux__ ) || defined( __unix__ )
6471
6471
return handle >= 0 ;
6472
6472
#elif defined(_WIN32 )
6473
6473
return handle != NULL ;
@@ -6485,6 +6485,8 @@ _dispatch_runloop_queue_get_handle(dispatch_lane_t dq)
6485
6485
#elif defined(__linux__ )
6486
6486
// decode: 0 is a valid fd, so offset by 1 to distinguish from NULL
6487
6487
return ((dispatch_runloop_handle_t )(uintptr_t )dq -> do_ctxt ) - 1 ;
6488
+ #elif defined(__unix__ ) && !defined(__linux__ )
6489
+ return ((dispatch_runloop_handle_t )(uintptr_t )dq -> do_ctxt );
6488
6490
#elif defined(_WIN32 )
6489
6491
return ((dispatch_runloop_handle_t )(uintptr_t )dq -> do_ctxt );
6490
6492
#else
@@ -6502,13 +6504,21 @@ _dispatch_runloop_queue_set_handle(dispatch_lane_t dq,
6502
6504
#elif defined(__linux__ )
6503
6505
// encode: 0 is a valid fd, so offset by 1 to distinguish from NULL
6504
6506
dq -> do_ctxt = (void * )(uintptr_t )(handle + 1 );
6507
+ #elif defined(__unix__ ) && !defined(__linux__ )
6508
+ dq -> do_ctxt = (void * )(uintptr_t )handle ;
6505
6509
#elif defined(_WIN32 )
6506
6510
dq -> do_ctxt = (void * )(uintptr_t )handle ;
6507
6511
#else
6508
6512
#error "runloop support not implemented on this platform"
6509
6513
#endif
6510
6514
}
6511
6515
6516
+ #if defined(__unix__ )
6517
+ #define DISPATCH_RUNLOOP_HANDLE_PACK (rfd , wfd ) (((uint64_t)(rfd) << 32) | (wfd))
6518
+ #define DISPATCH_RUNLOOP_HANDLE_RFD (h ) ((int)((h) >> 32))
6519
+ #define DISPATCH_RUNLOOP_HANDLE_WFD (h ) ((int)((h) & 0xffffffff))
6520
+ #endif
6521
+
6512
6522
static void
6513
6523
_dispatch_runloop_queue_handle_init (void * ctxt )
6514
6524
{
@@ -6558,6 +6568,14 @@ _dispatch_runloop_queue_handle_init(void *ctxt)
6558
6568
}
6559
6569
}
6560
6570
handle = fd ;
6571
+ #elif defined(__unix__ ) && !defined(__linux__ )
6572
+ int fds [2 ];
6573
+ int r = pipe2 (fds , O_CLOEXEC | O_NONBLOCK );
6574
+ if (r == -1 ) {
6575
+ DISPATCH_CLIENT_CRASH (errno , "pipe2 failure" );
6576
+ }
6577
+ uint32_t rfd = (uint32_t )fds [0 ], wfd = (uint32_t )fds [1 ];
6578
+ handle = DISPATCH_RUNLOOP_HANDLE_PACK (rfd , wfd );
6561
6579
#elif defined(_WIN32 )
6562
6580
HANDLE hEvent ;
6563
6581
hEvent = CreateEventW (NULL , /*bManualReset=*/ FALSE,
@@ -6592,6 +6610,11 @@ _dispatch_runloop_queue_handle_dispose(dispatch_lane_t dq)
6592
6610
#elif defined(__linux__ )
6593
6611
int rc = close (handle );
6594
6612
(void )dispatch_assume_zero (rc );
6613
+ #elif defined(__unix__ ) && !defined(__linux__ )
6614
+ int rc = close (DISPATCH_RUNLOOP_HANDLE_WFD (handle ));
6615
+ (void )dispatch_assume_zero (rc );
6616
+ rc = close (DISPATCH_RUNLOOP_HANDLE_RFD (handle ));
6617
+ (void )dispatch_assume_zero (rc );
6595
6618
#elif defined(_WIN32 )
6596
6619
BOOL bSuccess ;
6597
6620
bSuccess = CloseHandle (handle );
@@ -6628,6 +6651,13 @@ _dispatch_runloop_queue_class_poke(dispatch_lane_t dq)
6628
6651
result = eventfd_write (handle , 1 );
6629
6652
} while (result == -1 && errno == EINTR );
6630
6653
(void )dispatch_assume_zero (result );
6654
+ #elif defined(__unix__ ) && !defined(__linux__ )
6655
+ int wfd = DISPATCH_RUNLOOP_HANDLE_WFD (handle );
6656
+ ssize_t result ;
6657
+ do {
6658
+ result = write (wfd , "x" , 1 );
6659
+ } while (result == -1 && errno == EINTR );
6660
+ (void )dispatch_assume_zero (result - 1 );
6631
6661
#elif defined(_WIN32 )
6632
6662
BOOL bSuccess ;
6633
6663
bSuccess = SetEvent (handle );
@@ -7306,6 +7336,13 @@ _gettid(void)
7306
7336
{
7307
7337
return (pid_t )pthread_getthreadid_np ();
7308
7338
}
7339
+ #elif defined(__OpenBSD__ )
7340
+ DISPATCH_ALWAYS_INLINE
7341
+ static inline pid_t
7342
+ _gettid (void )
7343
+ {
7344
+ return getthrid ();
7345
+ }
7309
7346
#elif defined(_WIN32 )
7310
7347
DISPATCH_ALWAYS_INLINE
7311
7348
static inline DWORD
0 commit comments