Skip to content

Commit 5431c6d

Browse files
authored
[Concurrency] Base priority should be present on UnsafeTask too (swiftlang#63563)
1 parent 69a1311 commit 5431c6d

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ extension Task where Success == Never, Failure == Never {
287287
/// If the system can't provide a priority,
288288
/// this property's value is `Priority.default`.
289289
public static var currentPriority: TaskPriority {
290-
withUnsafeCurrentTask { task in
290+
withUnsafeCurrentTask { unsafeTask in
291291
// If we are running on behalf of a task, use that task's priority.
292-
if let unsafeTask = task {
293-
return TaskPriority(rawValue: _taskCurrentPriority(unsafeTask._task))
292+
if let unsafeTask {
293+
return unsafeTask.priority
294294
}
295295

296296
// Otherwise, query the system.
@@ -311,6 +311,7 @@ extension Task where Success == Never, Failure == Never {
311311
return nil
312312
}
313313
}
314+
314315
}
315316

316317
@available(SwiftStdlib 5.1, *)
@@ -820,6 +821,15 @@ public struct UnsafeCurrentTask {
820821
TaskPriority(rawValue: _taskCurrentPriority(_task))
821822
}
822823

824+
/// The current task's base priority.
825+
///
826+
/// - SeeAlso: `TaskPriority`
827+
/// - SeeAlso: `Task.basePriority`
828+
@available(SwiftStdlib 5.9, *)
829+
public var basePriority: TaskPriority {
830+
TaskPriority(rawValue: _taskBasePriority(_task))
831+
}
832+
823833
/// Cancel the current task.
824834
public func cancel() {
825835
_taskCancel(_task)

test/Concurrency/async_task_priority.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ func expectedBasePri(priority: TaskPriority) -> TaskPriority {
3939
let basePri = Task.basePriority!
4040
print("Testing basePri matching expected pri - \(basePri) == \(priority)")
4141
expectEqual(basePri, priority)
42+
Task.withUnsafeCurrentTask { unsafeTask in
43+
guard let unsafeTask else {
44+
fatalError("Expected to be able to get current task, but could not!")
45+
}
46+
// The UnsafeCurrentTask must return the same value
47+
expectEqual(basePri, unsafeTask.basePriority)
48+
}
4249

4350
return basePri
4451
}

0 commit comments

Comments
 (0)