mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #85312 from al45tair/concurrency-6.3-not-6.2
[Concurrency] Change all of the StdlibDeploymentTarget 6.2s to 6.3.
This commit is contained in:
@@ -190,7 +190,7 @@ internal func _getClockRes(
|
|||||||
nanoseconds: UnsafeMutablePointer<Int64>,
|
nanoseconds: UnsafeMutablePointer<Int64>,
|
||||||
clock: CInt)
|
clock: CInt)
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_sleep")
|
@_silgen_name("swift_sleep")
|
||||||
internal func _sleep(
|
internal func _sleep(
|
||||||
seconds: Int64,
|
seconds: Int64,
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ extension ContinuousClock: Clock {
|
|||||||
public func sleep(
|
public func sleep(
|
||||||
until deadline: Instant, tolerance: Swift.Duration? = nil
|
until deadline: Instant, tolerance: Swift.Duration? = nil
|
||||||
) async throws {
|
) async throws {
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
try await Task._sleep(until: deadline,
|
try await Task._sleep(until: deadline,
|
||||||
tolerance: tolerance,
|
tolerance: tolerance,
|
||||||
clock: self)
|
clock: self)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import Swift
|
|||||||
// Store the Timestamp in the executor private data, if it will fit; otherwise,
|
// Store the Timestamp in the executor private data, if it will fit; otherwise,
|
||||||
// use the allocator to allocate space for it and stash a pointer in the private
|
// use the allocator to allocate space for it and stash a pointer in the private
|
||||||
// data area.
|
// data area.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension ExecutorJob {
|
extension ExecutorJob {
|
||||||
fileprivate var cooperativeExecutorTimestampIsIndirect: Bool {
|
fileprivate var cooperativeExecutorTimestampIsIndirect: Bool {
|
||||||
return MemoryLayout<(Int, Int)>.size
|
return MemoryLayout<(Int, Int)>.size
|
||||||
@@ -99,7 +99,7 @@ extension ExecutorJob {
|
|||||||
|
|
||||||
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
/// A wait queue is a specialised priority queue used to run a timer.
|
/// A wait queue is a specialised priority queue used to run a timer.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
struct WaitQueue {
|
struct WaitQueue {
|
||||||
var queue: PriorityQueue<UnownedJob>
|
var queue: PriorityQueue<UnownedJob>
|
||||||
var clock: _ClockID
|
var clock: _ClockID
|
||||||
@@ -157,7 +157,7 @@ struct WaitQueue {
|
|||||||
|
|
||||||
/// A co-operative executor that can be used as the main executor or as a
|
/// A co-operative executor that can be used as the main executor or as a
|
||||||
/// task executor.
|
/// task executor.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
final class CooperativeExecutor: Executor, @unchecked Sendable {
|
final class CooperativeExecutor: Executor, @unchecked Sendable {
|
||||||
var runQueue: PriorityQueue<UnownedJob>
|
var runQueue: PriorityQueue<UnownedJob>
|
||||||
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
@@ -282,7 +282,7 @@ extension CooperativeExecutor: SchedulingExecutor {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension CooperativeExecutor: RunLoopExecutor {
|
extension CooperativeExecutor: RunLoopExecutor {
|
||||||
public func run() throws {
|
public func run() throws {
|
||||||
try runUntil { false }
|
try runUntil { false }
|
||||||
@@ -340,13 +340,13 @@ extension CooperativeExecutor: RunLoopExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension CooperativeExecutor: SerialExecutor {}
|
extension CooperativeExecutor: SerialExecutor {}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension CooperativeExecutor: TaskExecutor {}
|
extension CooperativeExecutor: TaskExecutor {}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension CooperativeExecutor: MainExecutor {}
|
extension CooperativeExecutor: MainExecutor {}
|
||||||
|
|
||||||
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#endif // !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public protocol Executor: AnyObject, Sendable {
|
|||||||
|
|
||||||
#if os(WASI) || !$Embedded
|
#if os(WASI) || !$Embedded
|
||||||
/// `true` if this is the main executor.
|
/// `true` if this is the main executor.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
var isMainExecutor: Bool { get }
|
var isMainExecutor: Bool { get }
|
||||||
#endif // os(WASI) || !$Embedded
|
#endif // os(WASI) || !$Embedded
|
||||||
|
|
||||||
@@ -49,12 +49,12 @@ public protocol Executor: AnyObject, Sendable {
|
|||||||
/// Executors that implement SchedulingExecutor should provide their
|
/// Executors that implement SchedulingExecutor should provide their
|
||||||
/// own copy of this method, which will allow the compiler to avoid a
|
/// own copy of this method, which will allow the compiler to avoid a
|
||||||
/// potentially expensive runtime cast.
|
/// potentially expensive runtime cast.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
var asSchedulingExecutor: (any SchedulingExecutor)? { get }
|
var asSchedulingExecutor: (any SchedulingExecutor)? { get }
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public protocol SchedulingExecutor: Executor {
|
public protocol SchedulingExecutor: Executor {
|
||||||
|
|
||||||
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
@@ -74,7 +74,7 @@ public protocol SchedulingExecutor: Executor {
|
|||||||
/// - tolerance: The maximum additional delay permissible before the
|
/// - tolerance: The maximum additional delay permissible before the
|
||||||
/// job is executed. `nil` means no limit.
|
/// job is executed. `nil` means no limit.
|
||||||
/// - clock: The clock used for the delay.
|
/// - clock: The clock used for the delay.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
||||||
after delay: C.Duration,
|
after delay: C.Duration,
|
||||||
tolerance: C.Duration?,
|
tolerance: C.Duration?,
|
||||||
@@ -94,7 +94,7 @@ public protocol SchedulingExecutor: Executor {
|
|||||||
/// - tolerance: The maximum additional delay permissible before the
|
/// - tolerance: The maximum additional delay permissible before the
|
||||||
/// job is executed. `nil` means no limit.
|
/// job is executed. `nil` means no limit.
|
||||||
/// - clock: The clock used for the delay.
|
/// - clock: The clock used for the delay.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
||||||
at instant: C.Instant,
|
at instant: C.Instant,
|
||||||
tolerance: C.Duration?,
|
tolerance: C.Duration?,
|
||||||
@@ -138,7 +138,7 @@ extension Executor {
|
|||||||
/// Executors that implement SchedulingExecutor should provide their
|
/// Executors that implement SchedulingExecutor should provide their
|
||||||
/// own copy of this method, which will allow the compiler to avoid a
|
/// own copy of this method, which will allow the compiler to avoid a
|
||||||
/// potentially expensive runtime cast.
|
/// potentially expensive runtime cast.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public var asSchedulingExecutor: (any SchedulingExecutor)? {
|
public var asSchedulingExecutor: (any SchedulingExecutor)? {
|
||||||
return self as? SchedulingExecutor
|
return self as? SchedulingExecutor
|
||||||
}
|
}
|
||||||
@@ -162,19 +162,19 @@ extension Executor {
|
|||||||
#if os(WASI) || !$Embedded
|
#if os(WASI) || !$Embedded
|
||||||
// This defaults to `false` so that existing third-party Executor
|
// This defaults to `false` so that existing third-party Executor
|
||||||
// implementations will work as expected.
|
// implementations will work as expected.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public var isMainExecutor: Bool { false }
|
public var isMainExecutor: Bool { false }
|
||||||
#endif // os(WASI) || !$Embedded
|
#endif // os(WASI) || !$Embedded
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delay support
|
// Delay support
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension SchedulingExecutor {
|
extension SchedulingExecutor {
|
||||||
|
|
||||||
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
public func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
||||||
after delay: C.Duration,
|
after delay: C.Duration,
|
||||||
tolerance: C.Duration? = nil,
|
tolerance: C.Duration? = nil,
|
||||||
@@ -185,7 +185,7 @@ extension SchedulingExecutor {
|
|||||||
tolerance: tolerance, clock: clock)
|
tolerance: tolerance, clock: clock)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
public func enqueue<C: Clock>(_ job: consuming ExecutorJob,
|
||||||
at instant: C.Instant,
|
at instant: C.Instant,
|
||||||
tolerance: C.Duration? = nil,
|
tolerance: C.Duration? = nil,
|
||||||
@@ -383,7 +383,7 @@ public protocol SerialExecutor: Executor {
|
|||||||
extension SerialExecutor {
|
extension SerialExecutor {
|
||||||
|
|
||||||
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
|
public var isMainExecutor: Bool { return MainActor.executor._isSameExecutor(self) }
|
||||||
#endif // os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
#endif // os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
||||||
|
|
||||||
@@ -397,13 +397,13 @@ extension SerialExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if SWIFT_CONCURRENCY_USES_DISPATCH
|
#if SWIFT_CONCURRENCY_USES_DISPATCH
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
private var _dispatchQueue: OpaquePointer? {
|
private var _dispatchQueue: OpaquePointer? {
|
||||||
return unsafe _getDispatchQueueForExecutor(self.asUnownedSerialExecutor())
|
return unsafe _getDispatchQueueForExecutor(self.asUnownedSerialExecutor())
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
internal func _isSameExecutor(_ rhs: some SerialExecutor) -> Bool {
|
internal func _isSameExecutor(_ rhs: some SerialExecutor) -> Bool {
|
||||||
if rhs === self {
|
if rhs === self {
|
||||||
return true
|
return true
|
||||||
@@ -526,10 +526,10 @@ extension SerialExecutor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension SerialExecutor where Self: Equatable {
|
extension SerialExecutor where Self: Equatable {
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func isSameExclusiveExecutionContext(other: Self) -> Bool {
|
public func isSameExclusiveExecutionContext(other: Self) -> Bool {
|
||||||
return self == other
|
return self == other
|
||||||
}
|
}
|
||||||
@@ -541,7 +541,7 @@ extension SerialExecutor where Self: Equatable {
|
|||||||
/// The idea here is that some executors may work by running a loop
|
/// The idea here is that some executors may work by running a loop
|
||||||
/// that processes events of some sort; we want a way to enter that loop,
|
/// that processes events of some sort; we want a way to enter that loop,
|
||||||
/// and we would also like a way to trigger the loop to exit.
|
/// and we would also like a way to trigger the loop to exit.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public protocol RunLoopExecutor: Executor {
|
public protocol RunLoopExecutor: Executor {
|
||||||
/// Run the executor's run loop.
|
/// Run the executor's run loop.
|
||||||
///
|
///
|
||||||
@@ -572,7 +572,7 @@ public protocol RunLoopExecutor: Executor {
|
|||||||
func stop()
|
func stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension RunLoopExecutor {
|
extension RunLoopExecutor {
|
||||||
|
|
||||||
public func runUntil(_ condition: () -> Bool) throws {
|
public func runUntil(_ condition: () -> Bool) throws {
|
||||||
@@ -584,14 +584,14 @@ extension RunLoopExecutor {
|
|||||||
|
|
||||||
/// The main executor must conform to these two protocols; we have to
|
/// The main executor must conform to these two protocols; we have to
|
||||||
/// make this a protocol for compatibility with Embedded Swift.
|
/// make this a protocol for compatibility with Embedded Swift.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public protocol MainExecutor: RunLoopExecutor, SerialExecutor {
|
public protocol MainExecutor: RunLoopExecutor, SerialExecutor {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// An ExecutorFactory is used to create the default main and task
|
/// An ExecutorFactory is used to create the default main and task
|
||||||
/// executors.
|
/// executors.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public protocol ExecutorFactory {
|
public protocol ExecutorFactory {
|
||||||
#if os(WASI) || !$Embedded
|
#if os(WASI) || !$Embedded
|
||||||
/// Constructs and returns the main executor, which is started implicitly
|
/// Constructs and returns the main executor, which is started implicitly
|
||||||
@@ -607,7 +607,7 @@ public protocol ExecutorFactory {
|
|||||||
@available(StdlibDeploymentTarget 6.3, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
typealias DefaultExecutorFactory = PlatformExecutorFactory
|
typealias DefaultExecutorFactory = PlatformExecutorFactory
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_createExecutors")
|
@_silgen_name("swift_createExecutors")
|
||||||
public func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
|
public func _createExecutors<F: ExecutorFactory>(factory: F.Type) {
|
||||||
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
||||||
@@ -626,7 +626,7 @@ func _createDefaultExecutors() {
|
|||||||
|
|
||||||
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
#if os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
||||||
extension MainActor {
|
extension MainActor {
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
static var _executor: (any MainExecutor)? = nil
|
static var _executor: (any MainExecutor)? = nil
|
||||||
|
|
||||||
/// The main executor, which is started implicitly by the `async main`
|
/// The main executor, which is started implicitly by the `async main`
|
||||||
@@ -634,7 +634,7 @@ extension MainActor {
|
|||||||
///
|
///
|
||||||
/// Attempting to set this after the first `enqueue` on the main
|
/// Attempting to set this after the first `enqueue` on the main
|
||||||
/// executor is a fatal error.
|
/// executor is a fatal error.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public static var executor: any MainExecutor {
|
public static var executor: any MainExecutor {
|
||||||
// It would be good if there was a Swift way to do this
|
// It would be good if there was a Swift way to do this
|
||||||
_createDefaultExecutorsOnce()
|
_createDefaultExecutorsOnce()
|
||||||
@@ -642,7 +642,7 @@ extension MainActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An unowned version of the above, for performance
|
/// An unowned version of the above, for performance
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
static var unownedExecutor: UnownedSerialExecutor {
|
static var unownedExecutor: UnownedSerialExecutor {
|
||||||
_createDefaultExecutorsOnce()
|
_createDefaultExecutorsOnce()
|
||||||
return unsafe UnownedSerialExecutor(ordinary: _executor!)
|
return unsafe UnownedSerialExecutor(ordinary: _executor!)
|
||||||
@@ -651,7 +651,7 @@ extension MainActor {
|
|||||||
#endif // os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
#endif // os(WASI) || (!$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY)
|
||||||
|
|
||||||
extension Task where Success == Never, Failure == Never {
|
extension Task where Success == Never, Failure == Never {
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
static var _defaultExecutor: (any TaskExecutor)? = nil
|
static var _defaultExecutor: (any TaskExecutor)? = nil
|
||||||
|
|
||||||
/// The default or global executor, which is the default place in which
|
/// The default or global executor, which is the default place in which
|
||||||
@@ -659,7 +659,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
///
|
///
|
||||||
/// Attempting to set this after the first `enqueue` on the global
|
/// Attempting to set this after the first `enqueue` on the global
|
||||||
/// executor is a fatal error.
|
/// executor is a fatal error.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public static var defaultExecutor: any TaskExecutor {
|
public static var defaultExecutor: any TaskExecutor {
|
||||||
// It would be good if there was a Swift way to do this
|
// It would be good if there was a Swift way to do this
|
||||||
_createDefaultExecutorsOnce()
|
_createDefaultExecutorsOnce()
|
||||||
@@ -667,7 +667,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An unowned version of the above, for performance
|
/// An unowned version of the above, for performance
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
static var unownedDefaultExecutor: UnownedTaskExecutor {
|
static var unownedDefaultExecutor: UnownedTaskExecutor {
|
||||||
_createDefaultExecutorsOnce()
|
_createDefaultExecutorsOnce()
|
||||||
return unsafe UnownedTaskExecutor(_defaultExecutor!)
|
return unsafe UnownedTaskExecutor(_defaultExecutor!)
|
||||||
@@ -686,7 +686,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
/// 3. The task executor for the current thread
|
/// 3. The task executor for the current thread
|
||||||
///
|
///
|
||||||
/// If none of these exist, returns the default executor.
|
/// If none of these exist, returns the default executor.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_unavailableInEmbedded
|
@_unavailableInEmbedded
|
||||||
public static var currentExecutor: any Executor {
|
public static var currentExecutor: any Executor {
|
||||||
if let activeExecutor = unsafe _getActiveExecutor().asSerialExecutor() {
|
if let activeExecutor = unsafe _getActiveExecutor().asSerialExecutor() {
|
||||||
@@ -700,7 +700,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the preferred executor for the current `Task`, if any.
|
/// Get the preferred executor for the current `Task`, if any.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public static var preferredExecutor: (any TaskExecutor)? {
|
public static var preferredExecutor: (any TaskExecutor)? {
|
||||||
if let taskExecutor = unsafe _getPreferredTaskExecutor().asTaskExecutor() {
|
if let taskExecutor = unsafe _getPreferredTaskExecutor().asTaskExecutor() {
|
||||||
return taskExecutor
|
return taskExecutor
|
||||||
@@ -713,7 +713,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
///
|
///
|
||||||
/// This follows the same logic as `currentExecutor`, except that it ignores
|
/// This follows the same logic as `currentExecutor`, except that it ignores
|
||||||
/// any executor that isn't a `SchedulingExecutor`.
|
/// any executor that isn't a `SchedulingExecutor`.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public static var currentSchedulingExecutor: (any SchedulingExecutor)? {
|
public static var currentSchedulingExecutor: (any SchedulingExecutor)? {
|
||||||
if let activeExecutor = unsafe _getActiveExecutor().asSerialExecutor(),
|
if let activeExecutor = unsafe _getActiveExecutor().asSerialExecutor(),
|
||||||
let scheduling = activeExecutor.asSchedulingExecutor {
|
let scheduling = activeExecutor.asSchedulingExecutor {
|
||||||
@@ -806,7 +806,7 @@ public struct UnownedSerialExecutor: Sendable {
|
|||||||
unsafe _executor_isComplexEquality(self)
|
unsafe _executor_isComplexEquality(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func asSerialExecutor() -> (any SerialExecutor)? {
|
public func asSerialExecutor() -> (any SerialExecutor)? {
|
||||||
// The low bits of the witness table are used to encode the executor kind.
|
// The low bits of the witness table are used to encode the executor kind.
|
||||||
// any SerialExecutor needs a raw witness table pointer, so mask off the low
|
// any SerialExecutor needs a raw witness table pointer, so mask off the low
|
||||||
@@ -843,13 +843,13 @@ public struct UnownedTaskExecutor: Sendable {
|
|||||||
unsafe self.executor = Builtin.buildOrdinaryTaskExecutorRef(executor)
|
unsafe self.executor = Builtin.buildOrdinaryTaskExecutorRef(executor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@inlinable
|
@inlinable
|
||||||
public init<E: TaskExecutor>(_ executor: __shared E) {
|
public init<E: TaskExecutor>(_ executor: __shared E) {
|
||||||
unsafe self.executor = Builtin.buildOrdinaryTaskExecutorRef(executor)
|
unsafe self.executor = Builtin.buildOrdinaryTaskExecutorRef(executor)
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func asTaskExecutor() -> (any TaskExecutor)? {
|
public func asTaskExecutor() -> (any TaskExecutor)? {
|
||||||
return unsafe unsafeBitCast(executor, to: (any TaskExecutor)?.self)
|
return unsafe unsafeBitCast(executor, to: (any TaskExecutor)?.self)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,19 +17,19 @@
|
|||||||
|
|
||||||
import Swift
|
import Swift
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_exit")
|
@_silgen_name("_swift_exit")
|
||||||
internal func _exit(result: CInt)
|
internal func _exit(result: CInt)
|
||||||
|
|
||||||
#if !$Embedded
|
#if !$Embedded
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_task_isMainExecutorSwift")
|
@_silgen_name("_swift_task_isMainExecutorSwift")
|
||||||
internal func _isMainExecutor<E>(_ executor: E) -> Bool where E: SerialExecutor {
|
internal func _isMainExecutor<E>(_ executor: E) -> Bool where E: SerialExecutor {
|
||||||
return executor.isMainExecutor
|
return executor.isMainExecutor
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_task_checkIsolatedSwift")
|
@_silgen_name("_swift_task_checkIsolatedSwift")
|
||||||
internal func checkIsolated<E>(executor: E) where E: SerialExecutor {
|
internal func checkIsolated<E>(executor: E) where E: SerialExecutor {
|
||||||
executor.checkIsolated()
|
executor.checkIsolated()
|
||||||
@@ -40,7 +40,7 @@ internal func checkIsolated<E>(executor: E) where E: SerialExecutor {
|
|||||||
/// -1: unknown
|
/// -1: unknown
|
||||||
/// 0: not isolated
|
/// 0: not isolated
|
||||||
/// 1: isolated
|
/// 1: isolated
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_task_isIsolatingCurrentContextSwift")
|
@_silgen_name("_swift_task_isIsolatingCurrentContextSwift")
|
||||||
internal func isIsolatingCurrentContext<E>(executor: E) -> Int8
|
internal func isIsolatingCurrentContext<E>(executor: E) -> Int8
|
||||||
where E: SerialExecutor {
|
where E: SerialExecutor {
|
||||||
@@ -51,41 +51,41 @@ internal func isIsolatingCurrentContext<E>(executor: E) -> Int8
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_getActiveExecutor")
|
@_silgen_name("_swift_getActiveExecutor")
|
||||||
internal func _getActiveExecutor() -> UnownedSerialExecutor
|
internal func _getActiveExecutor() -> UnownedSerialExecutor
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_getCurrentTaskExecutor")
|
@_silgen_name("_swift_getCurrentTaskExecutor")
|
||||||
internal func _getCurrentTaskExecutor() -> UnownedTaskExecutor
|
internal func _getCurrentTaskExecutor() -> UnownedTaskExecutor
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_getPreferredTaskExecutor")
|
@_silgen_name("_swift_getPreferredTaskExecutor")
|
||||||
internal func _getPreferredTaskExecutor() -> UnownedTaskExecutor
|
internal func _getPreferredTaskExecutor() -> UnownedTaskExecutor
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_job_allocate")
|
@_silgen_name("swift_job_allocate")
|
||||||
internal func _jobAllocate(_ job: Builtin.Job,
|
internal func _jobAllocate(_ job: Builtin.Job,
|
||||||
_ capacity: Int) -> UnsafeMutableRawPointer
|
_ capacity: Int) -> UnsafeMutableRawPointer
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_job_deallocate")
|
@_silgen_name("swift_job_deallocate")
|
||||||
internal func _jobDeallocate(_ job: Builtin.Job,
|
internal func _jobDeallocate(_ job: Builtin.Job,
|
||||||
_ address: UnsafeMutableRawPointer)
|
_ address: UnsafeMutableRawPointer)
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_job_getPriority")
|
@_silgen_name("swift_job_getPriority")
|
||||||
internal func _jobGetPriority(_ job: Builtin.Job) -> UInt8
|
internal func _jobGetPriority(_ job: Builtin.Job) -> UInt8
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_job_setPriority")
|
@_silgen_name("swift_job_setPriority")
|
||||||
internal func _jobSetPriority(_ job: Builtin.Job, _ priority: UInt8)
|
internal func _jobSetPriority(_ job: Builtin.Job, _ priority: UInt8)
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_job_getKind")
|
@_silgen_name("swift_job_getKind")
|
||||||
internal func _jobGetKind(_ job: Builtin.Job) -> UInt8
|
internal func _jobGetKind(_ job: Builtin.Job) -> UInt8
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_job_getExecutorPrivateData")
|
@_silgen_name("swift_job_getExecutorPrivateData")
|
||||||
internal func _jobGetExecutorPrivateData(
|
internal func _jobGetExecutorPrivateData(
|
||||||
_ job: Builtin.Job
|
_ job: Builtin.Job
|
||||||
@@ -93,38 +93,38 @@ internal func _jobGetExecutorPrivateData(
|
|||||||
|
|
||||||
#if os(WASI) || !$Embedded
|
#if os(WASI) || !$Embedded
|
||||||
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_getMainExecutor")
|
@_silgen_name("swift_getMainExecutor")
|
||||||
internal func _getMainExecutorAsSerialExecutor() -> UnownedSerialExecutor {
|
internal func _getMainExecutorAsSerialExecutor() -> UnownedSerialExecutor {
|
||||||
return unsafe MainActor.unownedExecutor
|
return unsafe MainActor.unownedExecutor
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
// For task-to-thread model, this is implemented in C++
|
// For task-to-thread model, this is implemented in C++
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_getMainExecutor")
|
@_silgen_name("swift_getMainExecutor")
|
||||||
internal func _getMainExecutorAsSerialExecutor() -> UnownedSerialExecutor
|
internal func _getMainExecutorAsSerialExecutor() -> UnownedSerialExecutor
|
||||||
#endif // SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#endif // SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
#endif // os(WASI) || !$Embedded
|
#endif // os(WASI) || !$Embedded
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_getDefaultExecutor")
|
@_silgen_name("swift_getDefaultExecutor")
|
||||||
internal func _getDefaultExecutorAsTaskExecutor() -> UnownedTaskExecutor {
|
internal func _getDefaultExecutorAsTaskExecutor() -> UnownedTaskExecutor {
|
||||||
return unsafe Task.unownedDefaultExecutor
|
return unsafe Task.unownedDefaultExecutor
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_dispatchMain")
|
@_silgen_name("swift_dispatchMain")
|
||||||
internal func _dispatchMain()
|
internal func _dispatchMain()
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_dispatchEnqueueMain")
|
@_silgen_name("swift_dispatchEnqueueMain")
|
||||||
internal func _dispatchEnqueueMain(_ job: UnownedJob)
|
internal func _dispatchEnqueueMain(_ job: UnownedJob)
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_dispatchEnqueueGlobal")
|
@_silgen_name("swift_dispatchEnqueueGlobal")
|
||||||
internal func _dispatchEnqueueGlobal(_ job: UnownedJob)
|
internal func _dispatchEnqueueGlobal(_ job: UnownedJob)
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_dispatchEnqueueWithDeadline")
|
@_silgen_name("swift_dispatchEnqueueWithDeadline")
|
||||||
internal func _dispatchEnqueueWithDeadline(_ global: CBool,
|
internal func _dispatchEnqueueWithDeadline(_ global: CBool,
|
||||||
_ sec: CLongLong,
|
_ sec: CLongLong,
|
||||||
@@ -134,7 +134,7 @@ internal func _dispatchEnqueueWithDeadline(_ global: CBool,
|
|||||||
_ clock: CInt,
|
_ clock: CInt,
|
||||||
_ job: UnownedJob)
|
_ job: UnownedJob)
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("swift_dispatchAssertMainQueue")
|
@_silgen_name("swift_dispatchAssertMainQueue")
|
||||||
internal func _dispatchAssertMainQueue()
|
internal func _dispatchAssertMainQueue()
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,12 @@ import Swift
|
|||||||
@_silgen_name("swift_task_asyncMainDrainQueueImpl")
|
@_silgen_name("swift_task_asyncMainDrainQueueImpl")
|
||||||
internal func drainMainQueue() {
|
internal func drainMainQueue() {
|
||||||
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
try! MainActor.executor.run()
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
_exit(result: 0)
|
try! MainActor.executor.run()
|
||||||
|
_exit(result: 0)
|
||||||
|
} else {
|
||||||
|
fatalError("this should never happen")
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
fatalError("swift_task_asyncMainDrainQueue() not supported with task-to-thread")
|
fatalError("swift_task_asyncMainDrainQueue() not supported with task-to-thread")
|
||||||
#endif
|
#endif
|
||||||
@@ -37,24 +41,36 @@ internal func donateToGlobalExecutor(
|
|||||||
condition: @convention(c) (_ ctx: UnsafeMutableRawPointer) -> CBool,
|
condition: @convention(c) (_ ctx: UnsafeMutableRawPointer) -> CBool,
|
||||||
context: UnsafeMutableRawPointer
|
context: UnsafeMutableRawPointer
|
||||||
) {
|
) {
|
||||||
if let runnableExecutor = Task.defaultExecutor as? RunLoopExecutor {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
try! runnableExecutor.runUntil { unsafe Bool(condition(context)) }
|
if let runnableExecutor = Task.defaultExecutor as? RunLoopExecutor {
|
||||||
|
try! runnableExecutor.runUntil { unsafe Bool(condition(context)) }
|
||||||
|
} else {
|
||||||
|
fatalError("Global executor does not support thread donation")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fatalError("Global executor does not support thread donation")
|
fatalError("this should never happen")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 6.2, *)
|
@available(SwiftStdlib 6.2, *)
|
||||||
@_silgen_name("swift_task_getMainExecutorImpl")
|
@_silgen_name("swift_task_getMainExecutorImpl")
|
||||||
internal func getMainExecutor() -> UnownedSerialExecutor {
|
internal func getMainExecutor() -> UnownedSerialExecutor {
|
||||||
return unsafe _getMainExecutorAsSerialExecutor()
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
|
return unsafe _getMainExecutorAsSerialExecutor()
|
||||||
|
} else {
|
||||||
|
fatalError("this should never happen")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 6.2, *)
|
@available(SwiftStdlib 6.2, *)
|
||||||
@_silgen_name("swift_task_enqueueMainExecutorImpl")
|
@_silgen_name("swift_task_enqueueMainExecutorImpl")
|
||||||
internal func enqueueOnMainExecutor(job unownedJob: UnownedJob) {
|
internal func enqueueOnMainExecutor(job unownedJob: UnownedJob) {
|
||||||
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
MainActor.executor.enqueue(unownedJob)
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
|
MainActor.executor.enqueue(unownedJob)
|
||||||
|
} else {
|
||||||
|
fatalError("this should never happen")
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
fatalError("swift_task_enqueueMainExecutor() not supported for task-to-thread")
|
fatalError("swift_task_enqueueMainExecutor() not supported for task-to-thread")
|
||||||
#endif
|
#endif
|
||||||
@@ -63,7 +79,11 @@ internal func enqueueOnMainExecutor(job unownedJob: UnownedJob) {
|
|||||||
@available(SwiftStdlib 6.2, *)
|
@available(SwiftStdlib 6.2, *)
|
||||||
@_silgen_name("swift_task_enqueueGlobalImpl")
|
@_silgen_name("swift_task_enqueueGlobalImpl")
|
||||||
internal func enqueueOnGlobalExecutor(job unownedJob: UnownedJob) {
|
internal func enqueueOnGlobalExecutor(job unownedJob: UnownedJob) {
|
||||||
Task.defaultExecutor.enqueue(unownedJob)
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
|
Task.defaultExecutor.enqueue(unownedJob)
|
||||||
|
} else {
|
||||||
|
fatalError("this should never happen")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !$Embedded
|
#if !$Embedded
|
||||||
@@ -72,9 +92,13 @@ internal func enqueueOnGlobalExecutor(job unownedJob: UnownedJob) {
|
|||||||
internal func enqueueOnGlobalExecutor(delay: CUnsignedLongLong,
|
internal func enqueueOnGlobalExecutor(delay: CUnsignedLongLong,
|
||||||
job unownedJob: UnownedJob) {
|
job unownedJob: UnownedJob) {
|
||||||
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
after: .nanoseconds(delay),
|
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
|
||||||
clock: .continuous)
|
after: .nanoseconds(delay),
|
||||||
|
clock: .continuous)
|
||||||
|
} else {
|
||||||
|
fatalError("this should never happen")
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
fatalError("swift_task_enqueueGlobalWithDelay() not supported for task-to-thread")
|
fatalError("swift_task_enqueueGlobalWithDelay() not supported for task-to-thread")
|
||||||
#endif
|
#endif
|
||||||
@@ -91,19 +115,27 @@ internal func enqueueOnGlobalExecutor(seconds: CLongLong,
|
|||||||
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
let delay = Duration.seconds(seconds) + Duration.nanoseconds(nanoseconds)
|
let delay = Duration.seconds(seconds) + Duration.nanoseconds(nanoseconds)
|
||||||
let leeway = Duration.seconds(leewaySeconds) + Duration.nanoseconds(leewayNanoseconds)
|
let leeway = Duration.seconds(leewaySeconds) + Duration.nanoseconds(leewayNanoseconds)
|
||||||
switch clock {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
case _ClockID.suspending.rawValue:
|
switch clock {
|
||||||
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
|
case _ClockID.suspending.rawValue:
|
||||||
after: delay,
|
Task.defaultExecutor.asSchedulingExecutor!.enqueue(
|
||||||
tolerance: leeway,
|
ExecutorJob(unownedJob),
|
||||||
clock: .suspending)
|
after: delay,
|
||||||
case _ClockID.continuous.rawValue:
|
tolerance: leeway,
|
||||||
Task.defaultExecutor.asSchedulingExecutor!.enqueue(ExecutorJob(unownedJob),
|
clock: .suspending
|
||||||
after: delay,
|
)
|
||||||
tolerance: leeway,
|
case _ClockID.continuous.rawValue:
|
||||||
clock: .continuous)
|
Task.defaultExecutor.asSchedulingExecutor!.enqueue(
|
||||||
default:
|
ExecutorJob(unownedJob),
|
||||||
fatalError("Unknown clock ID \(clock)")
|
after: delay,
|
||||||
|
tolerance: leeway,
|
||||||
|
clock: .continuous
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
fatalError("Unknown clock ID \(clock)")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fatalError("this should never happen")
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
fatalError("swift_task_enqueueGlobalWithDeadline() not supported for task-to-thread")
|
fatalError("swift_task_enqueueGlobalWithDeadline() not supported for task-to-thread")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import Swift
|
|||||||
@_unavailableInEmbedded
|
@_unavailableInEmbedded
|
||||||
public var globalConcurrentExecutor: any TaskExecutor {
|
public var globalConcurrentExecutor: any TaskExecutor {
|
||||||
get {
|
get {
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
return Task.defaultExecutor
|
return Task.defaultExecutor
|
||||||
} else {
|
} else {
|
||||||
fatalError("we shouldn't get here; if we have, availability is broken")
|
fatalError("we shouldn't get here; if we have, availability is broken")
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public struct UnownedJob: Sendable {
|
|||||||
@available(StdlibDeploymentTarget 5.9, *)
|
@available(StdlibDeploymentTarget 5.9, *)
|
||||||
public var priority: JobPriority {
|
public var priority: JobPriority {
|
||||||
let raw: UInt8
|
let raw: UInt8
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
raw = _jobGetPriority(context)
|
raw = _jobGetPriority(context)
|
||||||
} else {
|
} else {
|
||||||
fatalError("we shouldn't get here; if we have, availability is broken")
|
fatalError("we shouldn't get here; if we have, availability is broken")
|
||||||
@@ -227,7 +227,7 @@ public struct Job: Sendable, ~Copyable {
|
|||||||
|
|
||||||
public var priority: JobPriority {
|
public var priority: JobPriority {
|
||||||
let raw: UInt8
|
let raw: UInt8
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
raw = _jobGetPriority(self.context)
|
raw = _jobGetPriority(self.context)
|
||||||
} else {
|
} else {
|
||||||
fatalError("we shouldn't get here; if we have, availability is broken")
|
fatalError("we shouldn't get here; if we have, availability is broken")
|
||||||
@@ -301,7 +301,7 @@ public struct ExecutorJob: Sendable, ~Copyable {
|
|||||||
internal(set) public var priority: JobPriority {
|
internal(set) public var priority: JobPriority {
|
||||||
get {
|
get {
|
||||||
let raw: UInt8
|
let raw: UInt8
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
raw = _jobGetPriority(self.context)
|
raw = _jobGetPriority(self.context)
|
||||||
} else {
|
} else {
|
||||||
fatalError("we shouldn't get here; if we have, availability is broken")
|
fatalError("we shouldn't get here; if we have, availability is broken")
|
||||||
@@ -309,7 +309,7 @@ public struct ExecutorJob: Sendable, ~Copyable {
|
|||||||
return JobPriority(rawValue: raw)
|
return JobPriority(rawValue: raw)
|
||||||
}
|
}
|
||||||
set {
|
set {
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
_jobSetPriority(self.context, newValue.rawValue)
|
_jobSetPriority(self.context, newValue.rawValue)
|
||||||
} else {
|
} else {
|
||||||
fatalError("we shouldn't get here; if we have, availability is broken")
|
fatalError("we shouldn't get here; if we have, availability is broken")
|
||||||
@@ -327,7 +327,7 @@ public struct ExecutorJob: Sendable, ~Copyable {
|
|||||||
/// - body: The closure to execute.
|
/// - body: The closure to execute.
|
||||||
///
|
///
|
||||||
/// Returns the result of executing the closure.
|
/// Returns the result of executing the closure.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func withUnsafeExecutorPrivateData<R, E>(body: (UnsafeMutableRawBufferPointer) throws(E) -> R) throws(E) -> R {
|
public func withUnsafeExecutorPrivateData<R, E>(body: (UnsafeMutableRawBufferPointer) throws(E) -> R) throws(E) -> R {
|
||||||
let base = unsafe _jobGetExecutorPrivateData(self.context)
|
let base = unsafe _jobGetExecutorPrivateData(self.context)
|
||||||
let size = unsafe 2 * MemoryLayout<OpaquePointer>.stride
|
let size = unsafe 2 * MemoryLayout<OpaquePointer>.stride
|
||||||
@@ -336,7 +336,7 @@ public struct ExecutorJob: Sendable, ~Copyable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Kinds of schedulable jobs
|
/// Kinds of schedulable jobs
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@frozen
|
@frozen
|
||||||
public struct Kind: Sendable, RawRepresentable {
|
public struct Kind: Sendable, RawRepresentable {
|
||||||
public typealias RawValue = UInt8
|
public typealias RawValue = UInt8
|
||||||
@@ -357,7 +357,7 @@ public struct ExecutorJob: Sendable, ~Copyable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// What kind of job this is.
|
/// What kind of job this is.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public var kind: Kind {
|
public var kind: Kind {
|
||||||
return Kind(rawValue: _jobGetKind(self.context))!
|
return Kind(rawValue: _jobGetKind(self.context))!
|
||||||
}
|
}
|
||||||
@@ -454,7 +454,7 @@ extension ExecutorJob {
|
|||||||
|
|
||||||
// Helper to create a trampoline job to execute a job on a specified
|
// Helper to create a trampoline job to execute a job on a specified
|
||||||
// executor.
|
// executor.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension ExecutorJob {
|
extension ExecutorJob {
|
||||||
|
|
||||||
/// Create a trampoline to enqueue the specified job on the specified
|
/// Create a trampoline to enqueue the specified job on the specified
|
||||||
@@ -471,7 +471,7 @@ extension ExecutorJob {
|
|||||||
///
|
///
|
||||||
/// A new ExecutorJob that will enqueue the specified job on the specified
|
/// A new ExecutorJob that will enqueue the specified job on the specified
|
||||||
/// executor.
|
/// executor.
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public func createTrampoline(to executor: some Executor) -> ExecutorJob {
|
public func createTrampoline(to executor: some Executor) -> ExecutorJob {
|
||||||
let flags = taskCreateFlags(
|
let flags = taskCreateFlags(
|
||||||
priority: TaskPriority(priority),
|
priority: TaskPriority(priority),
|
||||||
@@ -496,7 +496,7 @@ extension ExecutorJob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stack-disciplined job-local allocator support
|
// Stack-disciplined job-local allocator support
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
extension ExecutorJob {
|
extension ExecutorJob {
|
||||||
|
|
||||||
/// Obtain a stack-disciplined job-local allocator.
|
/// Obtain a stack-disciplined job-local allocator.
|
||||||
@@ -971,7 +971,7 @@ public func _abiEnableAwaitContinuation() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
@_silgen_name("_swift_createJobForTestingOnly")
|
@_silgen_name("_swift_createJobForTestingOnly")
|
||||||
public func _swift_createJobForTestingOnly(
|
public func _swift_createJobForTestingOnly(
|
||||||
priority: TaskPriority = TaskPriority.medium,
|
priority: TaskPriority = TaskPriority.medium,
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
import Swift
|
import Swift
|
||||||
|
|
||||||
// This platform uses a single, global, CooperativeExecutor
|
// This platform uses a single, global, CooperativeExecutor
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public struct PlatformExecutorFactory: ExecutorFactory {
|
public struct PlatformExecutorFactory: ExecutorFactory {
|
||||||
static let executor = CooperativeExecutor()
|
static let executor = CooperativeExecutor()
|
||||||
public static var mainExecutor: any MainExecutor { executor }
|
public static var mainExecutor: any MainExecutor { executor }
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
import Swift
|
import Swift
|
||||||
|
|
||||||
// The default executors for now are Dispatch-based
|
// The default executors for now are Dispatch-based
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public struct PlatformExecutorFactory: ExecutorFactory {
|
public struct PlatformExecutorFactory: ExecutorFactory {
|
||||||
public static let mainExecutor: any MainExecutor = DispatchMainExecutor()
|
public static let mainExecutor: any MainExecutor = DispatchMainExecutor()
|
||||||
public static let defaultExecutor: any TaskExecutor
|
public static let defaultExecutor: any TaskExecutor
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
import Swift
|
import Swift
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public struct PlatformExecutorFactory: ExecutorFactory {
|
public struct PlatformExecutorFactory: ExecutorFactory {
|
||||||
public static let mainExecutor: any MainExecutor = UnimplementedMainExecutor()
|
public static let mainExecutor: any MainExecutor = UnimplementedMainExecutor()
|
||||||
public static let defaultExecutor: any TaskExecutor = UnimplementedTaskExecutor()
|
public static let defaultExecutor: any TaskExecutor = UnimplementedTaskExecutor()
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
import Swift
|
import Swift
|
||||||
|
|
||||||
// The default executors for now are Dispatch-based
|
// The default executors for now are Dispatch-based
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public struct PlatformExecutorFactory: ExecutorFactory {
|
public struct PlatformExecutorFactory: ExecutorFactory {
|
||||||
public static let mainExecutor: any MainExecutor = DispatchMainExecutor()
|
public static let mainExecutor: any MainExecutor = DispatchMainExecutor()
|
||||||
public static let defaultExecutor: any TaskExecutor =
|
public static let defaultExecutor: any TaskExecutor =
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ extension SuspendingClock: Clock {
|
|||||||
public func sleep(
|
public func sleep(
|
||||||
until deadline: Instant, tolerance: Swift.Duration? = nil
|
until deadline: Instant, tolerance: Swift.Duration? = nil
|
||||||
) async throws {
|
) async throws {
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
try await Task._sleep(until: deadline,
|
try await Task._sleep(until: deadline,
|
||||||
tolerance: tolerance,
|
tolerance: tolerance,
|
||||||
clock: self)
|
clock: self)
|
||||||
|
|||||||
@@ -637,7 +637,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
continuation: continuation)
|
continuation: continuation)
|
||||||
|
|
||||||
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
#if !$Embedded && !SWIFT_STDLIB_TASK_TO_THREAD_MODEL_CONCURRENCY
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
let executor = Task.currentExecutor
|
let executor = Task.currentExecutor
|
||||||
|
|
||||||
executor.enqueue(ExecutorJob(context: job))
|
executor.enqueue(ExecutorJob(context: job))
|
||||||
@@ -884,7 +884,7 @@ internal func _runAsyncMain(_ asyncFun: @Sendable @escaping () async throws -> (
|
|||||||
}
|
}
|
||||||
|
|
||||||
let job = Builtin.convertTaskToJob(theTask)
|
let job = Builtin.convertTaskToJob(theTask)
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
MainActor.executor.enqueue(ExecutorJob(context: job))
|
MainActor.executor.enqueue(ExecutorJob(context: job))
|
||||||
} else {
|
} else {
|
||||||
fatalError("we shouldn't get here; if we have, availability is broken")
|
fatalError("we shouldn't get here; if we have, availability is broken")
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
priority: Int(Task.currentPriority.rawValue),
|
priority: Int(Task.currentPriority.rawValue),
|
||||||
continuation: continuation)
|
continuation: continuation)
|
||||||
|
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
#if !$Embedded
|
#if !$Embedded
|
||||||
if let executor = Task.currentSchedulingExecutor {
|
if let executor = Task.currentSchedulingExecutor {
|
||||||
executor.enqueue(ExecutorJob(context: job),
|
executor.enqueue(ExecutorJob(context: job),
|
||||||
@@ -272,7 +272,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
|
|
||||||
let job = Builtin.convertTaskToJob(sleepTask)
|
let job = Builtin.convertTaskToJob(sleepTask)
|
||||||
|
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
#if !$Embedded
|
#if !$Embedded
|
||||||
if let executor = Task.currentSchedulingExecutor {
|
if let executor = Task.currentSchedulingExecutor {
|
||||||
executor.enqueue(ExecutorJob(context: job),
|
executor.enqueue(ExecutorJob(context: job),
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
|
|
||||||
let job = Builtin.convertTaskToJob(sleepTask)
|
let job = Builtin.convertTaskToJob(sleepTask)
|
||||||
|
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
#if !$Embedded
|
#if !$Embedded
|
||||||
if let executor = Task.currentSchedulingExecutor {
|
if let executor = Task.currentSchedulingExecutor {
|
||||||
executor.enqueue(ExecutorJob(context: job),
|
executor.enqueue(ExecutorJob(context: job),
|
||||||
@@ -136,7 +136,7 @@ extension Task where Success == Never, Failure == Never {
|
|||||||
clock: clock)
|
clock: clock)
|
||||||
let toleranceSeconds: Int64
|
let toleranceSeconds: Int64
|
||||||
let toleranceNanoseconds: Int64
|
let toleranceNanoseconds: Int64
|
||||||
if #available(StdlibDeploymentTarget 6.2, *) {
|
if #available(StdlibDeploymentTarget 6.3, *) {
|
||||||
if let tolerance = tolerance {
|
if let tolerance = tolerance {
|
||||||
(toleranceSeconds, toleranceNanoseconds)
|
(toleranceSeconds, toleranceNanoseconds)
|
||||||
= durationComponents(for: tolerance, clock: clock)
|
= durationComponents(for: tolerance, clock: clock)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import Swift
|
|||||||
|
|
||||||
// .. Main Executor ............................................................
|
// .. Main Executor ............................................................
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public final class UnimplementedMainExecutor: MainExecutor, @unchecked Sendable {
|
public final class UnimplementedMainExecutor: MainExecutor, @unchecked Sendable {
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public final class UnimplementedMainExecutor: MainExecutor, @unchecked Sendable
|
|||||||
|
|
||||||
// .. Task Executor ............................................................
|
// .. Task Executor ............................................................
|
||||||
|
|
||||||
@available(StdlibDeploymentTarget 6.2, *)
|
@available(StdlibDeploymentTarget 6.3, *)
|
||||||
public final class UnimplementedTaskExecutor: TaskExecutor, @unchecked Sendable {
|
public final class UnimplementedTaskExecutor: TaskExecutor, @unchecked Sendable {
|
||||||
public init() {}
|
public init() {}
|
||||||
|
|
||||||
|
|||||||
@@ -203,7 +203,7 @@ await Task.detached { @SomeGlobalActor in
|
|||||||
// CHECK: Testing a separate task off the main actor
|
// CHECK: Testing a separate task off the main actor
|
||||||
print("Testing a separate task off the main actor")
|
print("Testing a separate task off the main actor")
|
||||||
await Task.detached {
|
await Task.detached {
|
||||||
if #available(SwiftStdlib 6.2, *) {
|
if #available(SwiftStdlib 6.3, *) {
|
||||||
// Skip tests on platforms that use the same executor for the main
|
// Skip tests on platforms that use the same executor for the main
|
||||||
// actor and the global concurrent executor.
|
// actor and the global concurrent executor.
|
||||||
guard Task.defaultExecutor !== MainActor.executor else { return }
|
guard Task.defaultExecutor !== MainActor.executor else { return }
|
||||||
|
|||||||
@@ -15,14 +15,14 @@
|
|||||||
import Dispatch
|
import Dispatch
|
||||||
import StdlibUnittest
|
import StdlibUnittest
|
||||||
|
|
||||||
@available(SwiftStdlib 6.2, *)
|
@available(SwiftStdlib 6.3, *)
|
||||||
actor MyActor {
|
actor MyActor {
|
||||||
public func doSleep() async {
|
public func doSleep() async {
|
||||||
try! await Task.sleep(for: .seconds(0.1))
|
try! await Task.sleep(for: .seconds(0.1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 6.2, *)
|
@available(SwiftStdlib 6.3, *)
|
||||||
final class TestExecutor: TaskExecutor, SchedulingExecutor, @unchecked Sendable {
|
final class TestExecutor: TaskExecutor, SchedulingExecutor, @unchecked Sendable {
|
||||||
var asScheduling: SchedulingExecutor? {
|
var asScheduling: SchedulingExecutor? {
|
||||||
return self
|
return self
|
||||||
@@ -58,7 +58,7 @@ final class TestExecutor: TaskExecutor, SchedulingExecutor, @unchecked Sendable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@available(SwiftStdlib 6.2, *)
|
@available(SwiftStdlib 6.3, *)
|
||||||
@main struct Main {
|
@main struct Main {
|
||||||
static func main() async {
|
static func main() async {
|
||||||
let tests = TestSuite("sleep_executor")
|
let tests = TestSuite("sleep_executor")
|
||||||
|
|||||||
Reference in New Issue
Block a user