-#if USE_MACH_SEM
-static void
-_dispatch_semaphore_create_port(semaphore_t *s4)
-{
- kern_return_t kr;
- semaphore_t tmp;
-
- if (*s4) {
- return;
- }
- _dispatch_fork_becomes_unsafe();
-
- // lazily allocate the semaphore port
-
- // Someday:
- // 1) Switch to a doubly-linked FIFO in user-space.
- // 2) User-space timers for the timeout.
- // 3) Use the per-thread semaphore port.
-
- while ((kr = semaphore_create(mach_task_self(), &tmp,
- SYNC_POLICY_FIFO, 0))) {
- DISPATCH_VERIFY_MIG(kr);
- _dispatch_temporary_resource_shortage();
- }
-
- if (!os_atomic_cmpxchg(s4, 0, tmp, relaxed)) {
- kr = semaphore_destroy(mach_task_self(), tmp);
- DISPATCH_VERIFY_MIG(kr);
- DISPATCH_SEMAPHORE_VERIFY_KR(kr);
- }
-}
-#elif USE_WIN32_SEM
-static void
-_dispatch_semaphore_create_handle(HANDLE *s4)
-{
- HANDLE tmp;
-
- if (*s4) {
- return;
- }
-
- // lazily allocate the semaphore port
-
- while (!dispatch_assume(tmp = CreateSemaphore(NULL, 0, LONG_MAX, NULL))) {
- _dispatch_temporary_resource_shortage();
- }
-
- if (!os_atomic_cmpxchg(s4, 0, tmp)) {
- CloseHandle(tmp);
- }
-}
-#endif
-