@@ -298,14 +298,23 @@ public struct ExecutorJob: Sendable, ~Copyable {
298
298
self . context = job. context
299
299
}
300
300
301
- public var priority : JobPriority {
302
- let raw : UInt8
303
- if #available( StdlibDeploymentTarget 6 . 2 , * ) {
304
- raw = _jobGetPriority ( self . context)
305
- } else {
306
- fatalError ( " we shouldn't get here; if we have, availability is broken " )
301
+ internal( set) public var priority : JobPriority {
302
+ get {
303
+ let raw : UInt8
304
+ if #available( StdlibDeploymentTarget 6 . 2 , * ) {
305
+ raw = _jobGetPriority ( self . context)
306
+ } else {
307
+ fatalError ( " we shouldn't get here; if we have, availability is broken " )
308
+ }
309
+ return JobPriority ( rawValue: raw)
310
+ }
311
+ set {
312
+ if #available( StdlibDeploymentTarget 6 . 2 , * ) {
313
+ _jobSetPriority ( self . context, newValue. rawValue)
314
+ } else {
315
+ fatalError ( " we shouldn't get here; if we have, availability is broken " )
316
+ }
307
317
}
308
- return JobPriority ( rawValue: raw)
309
318
}
310
319
311
320
/// Execute a closure, passing it the bounds of the executor private data
@@ -540,6 +549,16 @@ public struct JobPriority: Sendable {
540
549
541
550
/// The raw priority value.
542
551
public var rawValue : RawValue
552
+
553
+ /// Construct from a raw value
554
+ public init ( rawValue: RawValue ) {
555
+ self . rawValue = rawValue
556
+ }
557
+
558
+ /// Construct from a TaskPriority
559
+ public init ( _ p: TaskPriority ) {
560
+ self . rawValue = p. rawValue
561
+ }
543
562
}
544
563
545
564
@available ( SwiftStdlib 5 . 9 , * )
@@ -909,3 +928,17 @@ public func _unsafeInheritExecutor_withUnsafeThrowingContinuation<T>(
909
928
public func _abiEnableAwaitContinuation( ) {
910
929
fatalError ( " never use this function " )
911
930
}
931
+
932
+ @available ( StdlibDeploymentTarget 6 . 2 , * )
933
+ @_silgen_name ( " _swift_createJobForTestingOnly " )
934
+ public func _swift_createJobForTestingOnly(
935
+ priority: TaskPriority = TaskPriority . medium,
936
+ _ body: @escaping ( ) -> ( )
937
+ ) -> ExecutorJob {
938
+ let flags : Int = Int ( priority. rawValue)
939
+ let ( task, _) = Builtin . createAsyncTask ( flags, body)
940
+ var job = ExecutorJob ( unsafe unsafeBitCast( Builtin . convertTaskToJob ( task) ,
941
+ to: UnownedJob . self) )
942
+ job. priority = JobPriority ( priority)
943
+ return job
944
+ }
0 commit comments