Skip to content

Commit 9683a43

Browse files
committed
[5.5] Workaround the actor runtimes unwillingness to deal with priorities properly
rdar://79378627
1 parent d79b69b commit 9683a43

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

stdlib/public/Concurrency/Task.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ extension Task where Success == Never, Failure == Never {
285285
}
286286

287287
// Otherwise, query the system.
288-
return TaskPriority(rawValue: UInt8(_getCurrentThreadPriority()))
288+
return TaskPriority(rawValue: UInt8(0))
289289
}
290290
}
291291
}
@@ -294,10 +294,6 @@ extension Task where Success == Never, Failure == Never {
294294
extension TaskPriority {
295295
/// Downgrade user-interactive to user-initiated.
296296
var _downgradeUserInteractive: TaskPriority {
297-
if self == .userInteractive {
298-
return .userInitiated
299-
}
300-
301297
return self
302298
}
303299
}
@@ -547,7 +543,7 @@ extension Task where Failure == Never {
547543
// Set up the job flags for a new task.
548544
var flags = JobFlags()
549545
flags.kind = .task
550-
flags.priority = priority ?? .default
546+
flags.priority = priority ?? .unspecified
551547
flags.isFuture = true
552548

553549
// Create the asynchronous task future.
@@ -602,7 +598,7 @@ extension Task where Failure == Error {
602598
// Set up the job flags for a new task.
603599
var flags = JobFlags()
604600
flags.kind = .task
605-
flags.priority = priority ?? .default
601+
flags.priority = priority ?? .unspecified
606602
flags.isFuture = true
607603

608604
// Create the asynchronous task future.
@@ -758,7 +754,7 @@ public struct UnsafeCurrentTask {
758754
/// - SeeAlso: `TaskPriority`
759755
/// - SeeAlso: `Task.currentPriority`
760756
public var priority: TaskPriority {
761-
getJobFlags(_task).priority ?? .default
757+
getJobFlags(_task).priority ?? .unspecified
762758
}
763759
}
764760

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-concurrency) | %FileCheck %s
2+
3+
// REQUIRES: executable_test
4+
// REQUIRES: concurrency
5+
6+
import Foundation
7+
8+
@available(SwiftStdlib 5.5, *)
9+
actor Manager {
10+
static var shared = Manager()
11+
12+
func manage() async -> Int {
13+
print("manage")
14+
return 0
15+
}
16+
17+
func other() async -> Int{
18+
print("other")
19+
return 0
20+
}
21+
}
22+
23+
24+
@available(SwiftStdlib 5.5, *)
25+
func test() {
26+
detach {
27+
let x = await Manager.shared.manage()
28+
print(x)
29+
}
30+
detach {
31+
let x = await Manager.shared.other()
32+
print(x)
33+
}
34+
}
35+
36+
if #available(SwiftStdlib 5.5, *) {
37+
test()
38+
sleep(30)
39+
} else {
40+
print("manage")
41+
print("0")
42+
print("other")
43+
print("0")
44+
}
45+
// CHECK-DAG: manage
46+
// CHECK-DAG: 0
47+
// CHECK-DAG: other
48+
// CHECK-DAG: 0

test/Concurrency/Runtime/async_task_priority_current.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Dispatch
1313
@available(SwiftStdlib 5.5, *)
1414
func test_detach() async {
1515
let a1 = Task.currentPriority
16-
print("a1: \(a1)") // CHECK: TaskPriority(rawValue: 21)
16+
print("a1: \(a1)") // CHECK: TaskPriority(rawValue: 0)
1717

1818
// Note: remember to detach using a higher priority, otherwise a lower one
1919
// might be escalated by the get() and we could see `default` in the detached
@@ -24,7 +24,7 @@ func test_detach() async {
2424
}.get()
2525

2626
let a3 = Task.currentPriority
27-
print("a3: \(a3)") // CHECK: a3: TaskPriority(rawValue: 21)
27+
print("a3: \(a3)") // CHECK: a3: TaskPriority(rawValue: 0)
2828
}
2929

3030
@available(SwiftStdlib 5.5, *)

0 commit comments

Comments
 (0)