@@ -15,7 +15,19 @@ import Swift
15
15
/// A service that can execute jobs.
16
16
@available(SwiftStdlib 5.1, *)
17
17
public protocol Executor: AnyObject, Sendable {
18
+
19
+ #if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
20
+ @available(macOS, introduced: 10.15, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
21
+ @available(iOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
22
+ @available(watchOS, introduced: 6.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
23
+ @available(tvOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
24
+ #endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
18
25
func enqueue(_ job: UnownedJob)
26
+
27
+ #if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
28
+ @available(SwiftStdlib 5.9, *)
29
+ func enqueue(_ job: __owned Job)
30
+ #endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
19
31
}
20
32
21
33
/// A service that executes jobs.
@@ -26,13 +38,51 @@ public protocol SerialExecutor: Executor {
26
38
// avoid drilling down to the base conformance just for the basic
27
39
// work-scheduling operation.
28
40
@_nonoverride
41
+ #if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
42
+ @available(macOS, introduced: 10.15, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
43
+ @available(iOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
44
+ @available(watchOS, introduced: 6.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
45
+ @available(tvOS, introduced: 13.0, deprecated: 9999, message: "Implement 'enqueue(_: __owned Job)' instead")
46
+ #endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
29
47
func enqueue(_ job: UnownedJob)
30
48
49
+ #if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
50
+ // This requirement is repeated here as a non-override so that we
51
+ // get a redundant witness-table entry for it. This allows us to
52
+ // avoid drilling down to the base conformance just for the basic
53
+ // work-scheduling operation.
54
+ @_nonoverride
55
+ @available(SwiftStdlib 5.9, *)
56
+ func enqueue(_ job: __owned Job)
57
+ #endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
58
+
31
59
/// Convert this executor value to the optimized form of borrowed
32
60
/// executor references.
61
+ @available(SwiftStdlib 5.9, *)
33
62
func asUnownedSerialExecutor() -> UnownedSerialExecutor
34
63
}
35
64
65
+ #if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
66
+ @available(SwiftStdlib 5.9, *)
67
+ extension Executor {
68
+ public func enqueue(_ job: UnownedJob) {
69
+ self.enqueue(Job(job))
70
+ }
71
+
72
+ public func enqueue(_ job: __owned Job) {
73
+ self.enqueue(UnownedJob(job))
74
+ }
75
+ }
76
+ #endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
77
+
78
+ @available(SwiftStdlib 5.9, *)
79
+ extension SerialExecutor {
80
+ @available(SwiftStdlib 5.9, *)
81
+ public func asUnownedSerialExecutor() -> UnownedSerialExecutor {
82
+ UnownedSerialExecutor(ordinary: self)
83
+ }
84
+ }
85
+
36
86
/// An unowned reference to a serial executor (a `SerialExecutor`
37
87
/// value).
38
88
///
@@ -88,14 +138,6 @@ public struct UnownedSerialExecutor: Sendable {
88
138
@_silgen_name("swift_task_isOnExecutor")
89
139
public func _taskIsOnExecutor<Executor: SerialExecutor>(_ executor: Executor) -> Bool
90
140
91
- // Used by the concurrency runtime
92
- @available(SwiftStdlib 5.1, *)
93
- @_silgen_name("_swift_task_enqueueOnExecutor")
94
- internal func _enqueueOnExecutor<E>(job: UnownedJob, executor: E)
95
- where E: SerialExecutor {
96
- executor.enqueue(job)
97
- }
98
-
99
141
@available(SwiftStdlib 5.1, *)
100
142
@_transparent
101
143
public // COMPILER_INTRINSIC
@@ -109,7 +151,33 @@ func _checkExpectedExecutor(_filenameStart: Builtin.RawPointer,
109
151
}
110
152
111
153
_reportUnexpectedExecutor(
112
- _filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
154
+ _filenameStart, _filenameLength, _filenameIsASCII, _line, _executor)
155
+ }
156
+
157
+ /// Primarily a debug utility.
158
+ ///
159
+ /// If the passed in Job is a Task, returns the complete 64bit TaskId,
160
+ /// otherwise returns only the job's 32bit Id.
161
+ ///
162
+ /// - Returns: the Id stored in this Job or Task, for purposes of debug printing
163
+ @available(SwiftStdlib 5.9, *)
164
+ @_silgen_name("swift_task_getJobTaskId")
165
+ internal func _getJobTaskId(_ job: UnownedJob) -> UInt64
166
+
167
+ // Used by the concurrency runtime
168
+ @available(SwiftStdlib 5.1, *)
169
+ @_silgen_name("_swift_task_enqueueOnExecutor")
170
+ internal func _enqueueOnExecutor<E>(job unownedJob: UnownedJob, executor: E)
171
+ where E: SerialExecutor {
172
+ #if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
173
+ if #available(SwiftStdlib 5.9, *) {
174
+ executor.enqueue(Job(context: unownedJob._context))
175
+ } else {
176
+ executor.enqueue(unownedJob)
177
+ }
178
+ #else // SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
179
+ executor.enqueue(unownedJob)
180
+ #endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
113
181
}
114
182
115
183
#if !SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
@@ -139,4 +207,4 @@ internal final class DispatchQueueShim: @unchecked Sendable, SerialExecutor {
139
207
return UnownedSerialExecutor(ordinary: self)
140
208
}
141
209
}
142
- #endif
210
+ #endif // SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY
0 commit comments