@@ -298,14 +298,23 @@ public struct ExecutorJob: Sendable, ~Copyable {
298298 self . context = job. context
299299 }
300300
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+ }
307317 }
308- return JobPriority ( rawValue: raw)
309318 }
310319
311320 /// Execute a closure, passing it the bounds of the executor private data
@@ -540,6 +549,16 @@ public struct JobPriority: Sendable {
540549
541550 /// The raw priority value.
542551 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+ }
543562}
544563
545564@available ( SwiftStdlib 5 . 9 , * )
@@ -909,3 +928,17 @@ public func _unsafeInheritExecutor_withUnsafeThrowingContinuation<T>(
909928public func _abiEnableAwaitContinuation( ) {
910929 fatalError ( " never use this function " )
911930}
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