Skip to content

Commit e0a411a

Browse files
committed
[stdlib] Standard clocks: Fix .now and .minimumResolution implementations
These used to set the clock id incorrectly, leading to zero results. Fix that and also make the underlying entry point abort if it gets an invalid ID, preventing this from reoccurring.
1 parent aa9d147 commit e0a411a

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

stdlib/public/Concurrency/Clock.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ void swift_get_time(
8989
#endif
9090
break;
9191
}
92+
default:
93+
abort();
9294
}
9395
}
9496

@@ -136,5 +138,7 @@ switch (clock_id) {
136138
#endif
137139
break;
138140
}
141+
default:
142+
abort();
139143
}
140144
}

stdlib/public/Concurrency/Clock.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,21 @@ extension Clock {
7474
}
7575
}
7676

77-
@available(SwiftStdlib 5.7, *)
78-
@usableFromInline
7977
enum _ClockID: Int32 {
8078
case continuous = 1
8179
case suspending = 2
8280
}
8381

8482
@available(SwiftStdlib 5.7, *)
8583
@_silgen_name("swift_get_time")
86-
@usableFromInline
8784
internal func _getTime(
8885
seconds: UnsafeMutablePointer<Int64>,
8986
nanoseconds: UnsafeMutablePointer<Int64>,
90-
clock: _ClockID)
87+
clock: CInt)
9188

9289
@available(SwiftStdlib 5.7, *)
9390
@_silgen_name("swift_get_clock_res")
94-
@usableFromInline
9591
internal func _getClockRes(
9692
seconds: UnsafeMutablePointer<Int64>,
9793
nanoseconds: UnsafeMutablePointer<Int64>,
98-
clock: _ClockID)
94+
clock: CInt)

stdlib/public/Concurrency/ContinuousClock.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension ContinuousClock: Clock {
5959
_getClockRes(
6060
seconds: &seconds,
6161
nanoseconds: &nanoseconds,
62-
clock: .continuous)
62+
clock: _ClockID.continuous.rawValue)
6363
return .seconds(seconds) + .nanoseconds(nanoseconds)
6464
}
6565

@@ -70,7 +70,7 @@ extension ContinuousClock: Clock {
7070
_getTime(
7171
seconds: &seconds,
7272
nanoseconds: &nanoseconds,
73-
clock: .continuous)
73+
clock: _ClockID.continuous.rawValue)
7474
return ContinuousClock.Instant(_value:
7575
.seconds(seconds) + .nanoseconds(nanoseconds))
7676
}

stdlib/public/Concurrency/SuspendingClock.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ extension SuspendingClock: Clock {
6060
_getTime(
6161
seconds: &seconds,
6262
nanoseconds: &nanoseconds,
63-
clock: .suspending)
63+
clock: _ClockID.suspending.rawValue)
6464
return SuspendingClock.Instant(_value:
6565
.seconds(seconds) + .nanoseconds(nanoseconds))
6666
}
@@ -73,7 +73,7 @@ extension SuspendingClock: Clock {
7373
_getClockRes(
7474
seconds: &seconds,
7575
nanoseconds: &nanoseconds,
76-
clock: .suspending)
76+
clock: _ClockID.suspending.rawValue)
7777
return .seconds(seconds) + .nanoseconds(nanoseconds)
7878
}
7979

0 commit comments

Comments
 (0)