Skip to content

Commit 0ea50ce

Browse files
committed
[Concurrency] Base priority should be present on UnsafeTask too
1 parent be8838a commit 0ea50ce

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

stdlib/public/Concurrency/PartialAsyncTask.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ internal func _swiftJobRun(_ job: UnownedJob,
2626
@available(SwiftStdlib 5.1, *)
2727
@frozen
2828
public struct UnownedJob: Sendable {
29-
private var context: Builtin.Job
29+
fileprivate var context: Builtin.Job
30+
31+
// Only the Swift is constructing jobs.
32+
@usableFromInline
33+
internal init(context: Builtin.Job) {
34+
self.context = context
35+
}
36+
37+
// Only the Swift is constructing jobs.
38+
@available(SwiftStdlib 5.9, *)
39+
@usableFromInline
40+
internal init(_ job: __owned Job) {
41+
self.context = job.context
42+
}
3043

3144
@available(SwiftStdlib 5.9, *)
3245
public var priority: Priority {

stdlib/public/Concurrency/Task.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ extension Task where Success == Never, Failure == Never {
306306
/// If the system can't provide a priority,
307307
/// this property's value is `Priority.default`.
308308
public static var currentPriority: TaskPriority {
309-
withUnsafeCurrentTask { task in
309+
withUnsafeCurrentTask { unsafeTask in
310310
// If we are running on behalf of a task, use that task's priority.
311-
if let unsafeTask = task {
312-
return TaskPriority(rawValue: _taskCurrentPriority(unsafeTask._task))
311+
if let unsafeTask {
312+
return unsafeTask.priority
313313
}
314314

315315
// Otherwise, query the system.
@@ -330,6 +330,7 @@ extension Task where Success == Never, Failure == Never {
330330
return nil
331331
}
332332
}
333+
333334
}
334335

335336
@available(SwiftStdlib 5.1, *)
@@ -839,6 +840,15 @@ public struct UnsafeCurrentTask {
839840
TaskPriority(rawValue: _taskCurrentPriority(_task))
840841
}
841842

843+
/// The current task's base priority.
844+
///
845+
/// - SeeAlso: `TaskPriority`
846+
/// - SeeAlso: `Task.currentBasePriority`
847+
@available(SwiftStdlib 5.9, *)
848+
public var basePriority: TaskPriority {
849+
TaskPriority(rawValue: _taskBasePriority(_task))
850+
}
851+
842852
/// Cancel the current task.
843853
public func cancel() {
844854
_taskCancel(_task)

0 commit comments

Comments
 (0)