@@ -22,6 +22,8 @@ import SKLogging
22
22
import SwiftExtensions
23
23
#endif
24
24
25
+ import Synchronization
26
+
25
27
/// See comment on ``TaskDescriptionProtocol/dependencies(to:taskPriority:)``
26
28
package enum TaskDependencyAction < TaskDescription: TaskDescriptionProtocol > {
27
29
case waitAndElevatePriorityOfDependency( TaskDescription )
@@ -133,18 +135,18 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
133
135
/// Every time `execute` gets called, a new task is placed in this continuation. See comment on `executionTask`.
134
136
private let executionTaskCreatedContinuation : AsyncStream < Task < ExecutionTaskFinishStatus , Never > > . Continuation
135
137
136
- private let _priority : AtomicUInt8
138
+ private let _priority : Atomic < UInt8 >
137
139
138
140
/// The latest known priority of the task.
139
141
///
140
142
/// This starts off as the priority with which the task is being created. If higher priority tasks start depending on
141
143
/// it, the priority may get elevated.
142
144
nonisolated var priority : TaskPriority {
143
145
get {
144
- TaskPriority ( rawValue: _priority. value )
146
+ TaskPriority ( rawValue: _priority. load ( ordering : . sequentiallyConsistent ) )
145
147
}
146
148
set {
147
- _priority. value = newValue. rawValue
149
+ _priority. store ( newValue. rawValue, ordering : . sequentiallyConsistent )
148
150
}
149
151
}
150
152
@@ -154,13 +156,13 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
154
156
private var cancelledToBeRescheduled : Bool = false
155
157
156
158
/// Whether `resultTask` has been cancelled.
157
- private let resultTaskCancelled : AtomicBool = . init ( initialValue : false )
159
+ private let resultTaskCancelled : Atomic < Bool > = Atomic ( false )
158
160
159
- private let _isExecuting : AtomicBool = . init ( initialValue : false )
161
+ private let _isExecuting : Atomic < Bool > = Atomic ( false )
160
162
161
163
/// Whether the task is currently executing or still queued to be executed later.
162
164
package nonisolated var isExecuting : Bool {
163
- return _isExecuting. value
165
+ return _isExecuting. load ( ordering : . sequentiallyConsistent )
164
166
}
165
167
166
168
package nonisolated func cancel( ) {
@@ -193,7 +195,7 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
193
195
description: TaskDescription ,
194
196
executionStateChangedCallback: ( @Sendable ( QueuedTask, TaskExecutionState) async -> Void ) ?
195
197
) async {
196
- self . _priority = AtomicUInt8 ( initialValue : priority. rawValue)
198
+ self . _priority = Atomic < UInt8 > ( priority. rawValue)
197
199
self . description = description
198
200
self . executionStateChangedCallback = executionStateChangedCallback
199
201
@@ -225,7 +227,7 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
225
227
self . priority = Task . currentPriority
226
228
}
227
229
} onCancel: {
228
- self . resultTaskCancelled. value = true
230
+ self . resultTaskCancelled. store ( true , ordering : . sequentiallyConsistent )
229
231
}
230
232
}
231
233
}
@@ -246,12 +248,12 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
246
248
}
247
249
precondition ( executionTask == nil , " Task started twice " )
248
250
let task = Task . detached ( priority: self . priority) {
249
- if !Task. isCancelled && !self . resultTaskCancelled. value {
251
+ if !Task. isCancelled && !self . resultTaskCancelled. load ( ordering : . sequentiallyConsistent ) {
250
252
await self . description. execute ( )
251
253
}
252
254
return await self . finalizeExecution ( )
253
255
}
254
- _isExecuting. value = true
256
+ _isExecuting. store ( true , ordering : . sequentiallyConsistent )
255
257
executionTask = task
256
258
executionTaskCreatedContinuation. yield ( task)
257
259
await executionStateChangedCallback ? ( self , . executing)
@@ -261,7 +263,7 @@ package actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
261
263
/// Implementation detail of `execute` that is called after `self.description.execute()` finishes.
262
264
private func finalizeExecution( ) async -> ExecutionTaskFinishStatus {
263
265
self . executionTask = nil
264
- _isExecuting. value = false
266
+ _isExecuting. store ( false , ordering : . sequentiallyConsistent )
265
267
if Task . isCancelled && self . cancelledToBeRescheduled {
266
268
await executionStateChangedCallback ? ( self , . cancelledToBeRescheduled)
267
269
self . cancelledToBeRescheduled = false
0 commit comments