diff --git a/CoreFoundation/Base.subproj/CFRuntime.c b/CoreFoundation/Base.subproj/CFRuntime.c index 4aaa65ed3c..afdbf5d21e 100644 --- a/CoreFoundation/Base.subproj/CFRuntime.c +++ b/CoreFoundation/Base.subproj/CFRuntime.c @@ -1179,7 +1179,7 @@ void __CFInitialize(void) { if (!__CFInitialized && !__CFInitializing) { __CFInitializing = 1; -#if __HAS_DISPATCH__ +#if __HAS_DISPATCH__ && !TARGET_OS_MAC // libdispatch has to be initialized before CoreFoundation, so to avoid // issues with static initializer ordering, we are doing it explicitly. libdispatch_init(); diff --git a/Sources/Foundation/Process.swift b/Sources/Foundation/Process.swift index e064711296..542cc94cf1 100644 --- a/Sources/Foundation/Process.swift +++ b/Sources/Foundation/Process.swift @@ -1134,14 +1134,17 @@ open class Process: NSObject { open func waitUntilExit() { let runInterval = 0.05 let currentRunLoop = RunLoop.current - let checkRunLoop : () -> Bool = (currentRunLoop == self.runLoop) - ? { currentRunLoop.run(mode: .default, before: Date(timeIntervalSinceNow: runInterval)) } - : { currentRunLoop.run(until: Date(timeIntervalSinceNow: runInterval)); return true } - // update .runLoop to allow early wakeup. + let runRunLoop : () -> Void = (currentRunLoop == self.runLoop) + ? { currentRunLoop.run(mode: .default, before: Date(timeIntervalSinceNow: runInterval)) } + : { currentRunLoop.run(until: Date(timeIntervalSinceNow: runInterval)) } + // update .runLoop to allow early wakeup triggered by terminateRunLoop. self.runLoop = currentRunLoop - while self.isRunning && checkRunLoop() {} - + + while self.isRunning { + runRunLoop() + } + self.runLoop = nil self.runLoopSource = nil }