@@ -900,106 +900,6 @@ extension Task where Success == Never, Failure == Never {
900900 }
901901}
902902
903- // ==== Manual Priority Escalation ---------------------------------------------
904-
905- extension Task {
906- /// Escalate the task `priority` of the passed in task to the `newPriority`.
907- ///
908- /// - Warning: This API should rarely be used, and instead you can rely on
909- /// structured concurrency and implicit priority escalation which happens
910- /// when a higher priority task awaits on a result of a lower priority task.
911- ///
912- /// I.e. using `await` on the target task usually is the correct way to
913- /// escalate the target task to the current priority of the calling task,
914- /// especially because in such setup if the waiting task gets escalated,
915- /// the waited on task would be escalated automatically as well.
916- ///
917- /// The concurrency runtime is free to interpret and handle escalation
918- /// depending on platform characteristics.
919- ///
920- /// Priority escalation is propagated to child tasks of the waited-on task,
921- /// and will trigger any priority escalation handlers, if any were registered.
922- ///
923- /// Escalation can only *increase* the priority of a task, and
924- /// de-escalating priority is not supported.
925- ///
926- /// This method can be called from any task or thread.
927- ///
928- /// - Parameters:
929- /// - task: the task which to escalate the priority of
930- /// - newPriority: the new priority the task should continue executing on
931- @available ( SwiftStdlib 9999 , * )
932- public static func escalatePriority( _ task: Task , to newPriority: TaskPriority ) {
933- _taskEscalate ( task. _task, newPriority: newPriority. rawValue)
934- }
935-
936- /// Escalate the task `priority` of the passed in task to the `newPriority`.
937- ///
938- /// - Warning: This API should rarely be used, and instead you can rely on
939- /// structured concurrency and implicit priority escalation which happens
940- /// when a higher priority task awaits on a result of a lower priority task.
941- ///
942- /// I.e. using `await` on the target task usually is the correct way to
943- /// escalate the target task to the current priority of the calling task,
944- /// especially because in such setup if the waiting task gets escalated,
945- /// the waited on task would be escalated automatically as well.
946- ///
947- /// The concurrency runtime is free to interpret and handle escalation
948- /// depending on platform characteristics.
949- ///
950- /// Priority escalation is propagated to child tasks of the waited-on task,
951- /// and will trigger any priority escalation handlers, if any were registered.
952- ///
953- /// Escalation can only *increase* the priority of a task, and
954- /// de-escalating priority is not supported.
955- ///
956- /// This method can be called from any task or thread.
957- ///
958- /// - Parameters:
959- /// - task: the task which to escalate the priority of
960- /// - newPriority: the new priority the task should continue executing on
961- @available ( SwiftStdlib 9999 , * )
962- public static func escalatePriority( _ task: UnsafeCurrentTask , to newPriority: TaskPriority ) {
963- _taskEscalate ( task. _task, newPriority: newPriority. rawValue)
964- }
965- }
966-
967- /// Runs the passed `operation` while registering a task priority escalation handler.
968- /// The handler will be triggered concurrently to the current task if the current
969- /// is subject to priority escalation.
970- ///
971- /// The handler may perform additional actions upon priority escalation,
972- /// but cannot influence how the escalation influences the task, i.e. the task's
973- /// priority will be escalated regardless of actions performed in the handler.
974- ///
975- /// If multiple task escalation handlers are nester they will all be triggered.
976- ///
977- /// Task escalation propagates through structured concurrency child-tasks.
978- ///
979- /// - Parameters:
980- /// - operation: the operation during which to listen for priority escalation
981- /// - handler: handler to invoke, concurrently to `operation`,
982- /// when priority escalation happens
983- /// - Returns: the value returned by `operation`
984- /// - Throws: when the `operation` throws an error
985- @available ( SwiftStdlib 9999 , * )
986- public func withTaskPriorityEscalationHandler< T, E> (
987- operation: ( ) async throws ( E) -> T ,
988- onEscalate handler: @Sendable ( TaskPriority ) -> Void ,
989- isolation: isolated ( any Actor ) ? = #isolation
990- ) async throws ( E) -> T {
991- // NOTE: We have to create the closure beforehand as otherwise it seems
992- // the task-local allocator may be used and we end up violating stack-discipline
993- // when releasing the handler closure vs. the record.
994- let handler0 : ( UInt8 ) -> Void = {
995- handler ( TaskPriority ( rawValue: $0) )
996- }
997- let record = _taskAddPriorityEscalationHandler ( handler: handler0)
998- defer { _taskRemovePriorityEscalationHandler ( record: record) }
999-
1000- return try await operation ( )
1001- }
1002-
1003903// ==== UnsafeCurrentTask ------------------------------------------------------
1004904
1005905/// Calls a closure with an unsafe reference to the current task.
@@ -1266,7 +1166,7 @@ func _taskIsCancelled(_ task: Builtin.NativeObject) -> Bool
12661166@_silgen_name ( " swift_task_currentPriority " )
12671167internal func _taskCurrentPriority( _ task: Builtin . NativeObject ) -> UInt8
12681168
1269- @available ( SwiftStdlib 9999 , * ) // TODO: determine how far back this can back-deploy because it already was in runtime
1169+ @available ( SwiftStdlib 6 . 2 , * )
12701170@_silgen_name ( " swift_task_escalate " )
12711171internal func _taskEscalate( _ task: Builtin . NativeObject , newPriority: UInt8 )
12721172
0 commit comments