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