Skip to content

Commit 34dfbf7

Browse files
committed
[Concurrency] Tweak some things after the availability change.
We need to fix some call sites to make this work.
1 parent d81da3a commit 34dfbf7

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

stdlib/public/Concurrency/Executor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public protocol SerialExecutor: Executor {
374374
/// The default implementation returns `nil` is used to indicate that it is "unknown" if the current context is
375375
/// isolated by this serial executor. The runtime then _may_ proceed to invoke `checkIsolated()` as a last-resort
376376
/// attempt to verify the isolation of the current context.
377-
@available(StdlibDeploymentTarget 6.3, *)
377+
@available(StdlibDeploymentTarget 6.2, *)
378378
func isIsolatingCurrentContext() -> Bool?
379379

380380
}

stdlib/public/Concurrency/ExecutorImpl.swift

Lines changed: 46 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@ import Swift
2424
@_silgen_name("swift_task_asyncMainDrainQueueImpl")
2525
internal func drainMainQueue() {
2626
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
27-
try! MainActor.executor.run()
28-
_exit(result: 0)
27+
if #available(StdlibDeploymentTarget 6.3, *) {
28+
try! MainActor.executor.run()
29+
_exit(result: 0)
30+
} else {
31+
fatalError("this should never happen")
32+
}
2933
#else
3034
fatalError("swift_task_asyncMainDrainQueue() not supported with task-to-thread")
3135
#endif
@@ -37,10 +41,14 @@ internal func donateToGlobalExecutor(
3741
condition: @convention(c) (_ ctx: UnsafeMutableRawPointer) -> CBool,
3842
context: UnsafeMutableRawPointer
3943
) {
40-
if let runnableExecutor = Task.defaultExecutor as? RunLoopExecutor {
41-
try! runnableExecutor.runUntil { unsafe Bool(condition(context)) }
44+
if #available(StdlibDeploymentTarget 6.3, *) {
45+
if let runnableExecutor = Task.defaultExecutor as? RunLoopExecutor {
46+
try! runnableExecutor.runUntil { unsafe Bool(condition(context)) }
47+
} else {
48+
fatalError("Global executor does not support thread donation")
49+
}
4250
} else {
43-
fatalError("Global executor does not support thread donation")
51+
fatalError("this should never happen")
4452
}
4553
}
4654

@@ -63,7 +71,11 @@ internal func enqueueOnMainExecutor(job unownedJob: UnownedJob) {
6371
@available(SwiftStdlib 6.2, *)
6472
@_silgen_name("swift_task_enqueueGlobalImpl")
6573
internal func enqueueOnGlobalExecutor(job unownedJob: UnownedJob) {
66-
Task.defaultExecutor.enqueue(unownedJob)
74+
if #available(StdlibDeploymentTarget 6.3, *) {
75+
Task.defaultExecutor.enqueue(unownedJob)
76+
} else {
77+
fatalError("this should never happen")
78+
}
6779
}
6880

6981
#if !$Embedded
@@ -72,9 +84,13 @@ internal func enqueueOnGlobalExecutor(job unownedJob: UnownedJob) {
7284
internal func enqueueOnGlobalExecutor(delay: CUnsignedLongLong,
7385
job unownedJob: UnownedJob) {
7486
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
75-
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
76-
after: .nanoseconds(delay),
77-
clock: .continuous)
87+
if #available(StdlibDeploymentTarget 6.3, *) {
88+
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
89+
after: .nanoseconds(delay),
90+
clock: .continuous)
91+
} else {
92+
fatalError("this should never happen")
93+
}
7894
#else
7995
fatalError("swift_task_enqueueGlobalWithDelay() not supported for task-to-thread")
8096
#endif
@@ -91,19 +107,27 @@ internal func enqueueOnGlobalExecutor(seconds: CLongLong,
91107
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
92108
let delay = Duration.seconds(seconds) + Duration.nanoseconds(nanoseconds)
93109
let leeway = Duration.seconds(leewaySeconds) + Duration.nanoseconds(leewayNanoseconds)
94-
switch clock {
95-
case _ClockID.suspending.rawValue:
96-
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
97-
after: delay,
98-
tolerance: leeway,
99-
clock: .suspending)
100-
case _ClockID.continuous.rawValue:
101-
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
102-
after: delay,
103-
tolerance: leeway,
104-
clock: .continuous)
105-
default:
106-
fatalError("Unknown clock ID \(clock)")
110+
if #available(StdlibDeploymentTarget 6.3, *) {
111+
switch clock {
112+
case _ClockID.suspending.rawValue:
113+
Task.defaultExecutor.asSchedulingExecutor!.enqueue(
114+
ExecutorJob(unownedJob),
115+
after: delay,
116+
tolerance: leeway,
117+
clock: .suspending
118+
)
119+
case _ClockID.continuous.rawValue:
120+
Task.defaultExecutor.asSchedulingExecutor!.enqueue(
121+
ExecutorJob(unownedJob),
122+
after: delay,
123+
tolerance: leeway,
124+
clock: .continuous
125+
)
126+
default:
127+
fatalError("Unknown clock ID \(clock)")
128+
}
129+
} else {
130+
fatalError("this should never happen")
107131
}
108132
#else
109133
fatalError("swift_task_enqueueGlobalWithDeadline() not supported for task-to-thread")

0 commit comments

Comments
 (0)