Skip to content

Commit e5ea7d8

Browse files
committed
Foundation: correct Thread.sleep(until:) on Windows
We were computing the duration incorrectly, using the time since the Cocoa epoch rather than now resulting in what appeared to be an infinite sleep. Correct the duration which is relative to *now* in 100ns intervals. This allows the NSLock tests to succeed.
1 parent 263ce3c commit e5ea7d8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Foundation/Thread.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ open class Thread : NSObject {
106106
open class func sleep(until date: Date) {
107107
#if os(Windows)
108108
var hTimer: HANDLE = CreateWaitableTimerW(nil, true, nil)
109-
// FIXME(compnerd) how to check that hTimer is not NULL?
109+
if hTimer == HANDLE(bitPattern: 0) { fatalError("unable to create timer: \(GetLastError())") }
110110
defer { CloseHandle(hTimer) }
111111

112112
// the timeout is in 100ns units
113113
var liTimeout: LARGE_INTEGER =
114-
LARGE_INTEGER(QuadPart: LONGLONG(date.timeIntervalSinceReferenceDate) * -10000000)
114+
LARGE_INTEGER(QuadPart: LONGLONG(date.timeIntervalSinceNow) * -10000000)
115115
if !SetWaitableTimer(hTimer, &liTimeout, 0, nil, nil, false) {
116116
return
117117
}

0 commit comments

Comments
 (0)