From dd402ba04bd324c193a8cc607e03a21c964e9980 Mon Sep 17 00:00:00 2001 From: Brian Gontowski Date: Thu, 17 Oct 2019 09:36:54 +0900 Subject: [PATCH 1/2] Fixed hang when using RunLoop.main.run with Date() on Android/Linux --- CoreFoundation/RunLoop.subproj/CFRunLoop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CoreFoundation/RunLoop.subproj/CFRunLoop.c b/CoreFoundation/RunLoop.subproj/CFRunLoop.c index 7526696f14..d50b72b5f1 100644 --- a/CoreFoundation/RunLoop.subproj/CFRunLoop.c +++ b/CoreFoundation/RunLoop.subproj/CFRunLoop.c @@ -2846,7 +2846,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter // Here, use the app-supplied message queue mask. They will set this if they are interested in having this run loop receive windows messages. __CFRunLoopWaitForMultipleObjects(waitSet, NULL, poll ? 0 : TIMEOUT_INFINITY, rlm->_msgQMask, &livePort, &windowsMessageReceived); #elif TARGET_OS_LINUX - __CFRunLoopServiceFileDescriptors(waitSet, CFPORT_NULL, TIMEOUT_INFINITY, &livePort); + __CFRunLoopServiceFileDescriptors(waitSet, CFPORT_NULL, poll ? 0 : TIMEOUT_INFINITY, &livePort); #endif __CFRunLoopLock(rl); From dedaacbbff3e74eef6e65a1bd7d273245a35e5e5 Mon Sep 17 00:00:00 2001 From: Brian Gontowski Date: Sun, 27 Oct 2019 09:29:22 +0900 Subject: [PATCH 2/2] Added test to verify RunLoop.run in poll mode returns in a reasonable time --- TestFoundation/TestRunLoop.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/TestFoundation/TestRunLoop.swift b/TestFoundation/TestRunLoop.swift index 5a3b9f1036..58da7f7db0 100644 --- a/TestFoundation/TestRunLoop.swift +++ b/TestFoundation/TestRunLoop.swift @@ -69,6 +69,16 @@ class TestRunLoop : XCTestCase { XCTAssertLessThan(abs(timerTickInterval - expectedTimeInterval), 0.01) } + + func test_runLoopPoll() { + let runLoop = RunLoop.current + + let startDate = Date() + runLoop.run(until: Date()) + let endDate = Date() + + XCTAssertLessThan(endDate.timeIntervalSince(startDate), 0.5) + } func test_commonModes() { let runLoop = RunLoop.current @@ -123,6 +133,7 @@ class TestRunLoop : XCTestCase { // these tests do not work the same as Darwin https://bugs.swift.org/browse/SR-399 // ("test_runLoopRunMode", test_runLoopRunMode), // ("test_runLoopLimitDate", test_runLoopLimitDate), + ("test_runLoopPoll", test_runLoopPoll), ("test_addingRemovingPorts", test_addingRemovingPorts), ] }