Skip to content

Commit cfd7974

Browse files
authored
Merge pull request #2544 from Molanda/fix_android_run_loop_hang
[Android][Linux] Fixed hang when using RunLoop.main.run with Date()
2 parents 315f251 + dedaacb commit cfd7974

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CoreFoundation/RunLoop.subproj/CFRunLoop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2846,7 +2846,7 @@ static int32_t __CFRunLoopRun(CFRunLoopRef rl, CFRunLoopModeRef rlm, CFTimeInter
28462846
// Here, use the app-supplied message queue mask. They will set this if they are interested in having this run loop receive windows messages.
28472847
__CFRunLoopWaitForMultipleObjects(waitSet, NULL, poll ? 0 : TIMEOUT_INFINITY, rlm->_msgQMask, &livePort, &windowsMessageReceived);
28482848
#elif TARGET_OS_LINUX
2849-
__CFRunLoopServiceFileDescriptors(waitSet, CFPORT_NULL, TIMEOUT_INFINITY, &livePort);
2849+
__CFRunLoopServiceFileDescriptors(waitSet, CFPORT_NULL, poll ? 0 : TIMEOUT_INFINITY, &livePort);
28502850
#endif
28512851

28522852
__CFRunLoopLock(rl);

TestFoundation/TestRunLoop.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ class TestRunLoop : XCTestCase {
6969

7070
XCTAssertLessThan(abs(timerTickInterval - expectedTimeInterval), 0.01)
7171
}
72+
73+
func test_runLoopPoll() {
74+
let runLoop = RunLoop.current
75+
76+
let startDate = Date()
77+
runLoop.run(until: Date())
78+
let endDate = Date()
79+
80+
XCTAssertLessThan(endDate.timeIntervalSince(startDate), 0.5)
81+
}
7282

7383
func test_commonModes() {
7484
let runLoop = RunLoop.current
@@ -123,6 +133,7 @@ class TestRunLoop : XCTestCase {
123133
// these tests do not work the same as Darwin https://bugs.swift.org/browse/SR-399
124134
// ("test_runLoopRunMode", test_runLoopRunMode),
125135
// ("test_runLoopLimitDate", test_runLoopLimitDate),
136+
("test_runLoopPoll", test_runLoopPoll),
126137
("test_addingRemovingPorts", test_addingRemovingPorts),
127138
]
128139
}

0 commit comments

Comments
 (0)