Skip to content

Commit

Permalink
Swift6 (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored Sep 24, 2024
1 parent 340cf14 commit 613d07e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 36 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on: [push, pull_request]

jobs:
test:
runs-on: macos-13
runs-on: macos-14

steps:
- uses: maxim-lobanov/setup-xcode@v1.1
- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "14.3"
xcode-version: "16.0"
- uses: actions/checkout@v2
- name: Run Test
run: xcodebuild -scheme swift-concurrency-task-manager test -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.4' | xcpretty
run: xcodebuild -scheme swift-concurrency-task-manager test -destination 'platform=iOS Simulator,name=iPhone 15 Pro,OS=18.0' | xcpretty
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.7
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down Expand Up @@ -34,5 +34,6 @@ let package = Package(
name: "ConcurrencyTaskManagerTests",
dependencies: ["ConcurrencyTaskManager"]
),
]
],
swiftLanguageModes: [.v5, .v6]
)
4 changes: 2 additions & 2 deletions Sources/ConcurrencyTaskManager/TaskManagerActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ public actor TaskManagerActor {
task(label: label, key: key, mode: mode, priority: priority, action)
}

public func batch(_ closure: (isolated TaskManagerActor) -> Void) {
public func batch(_ closure: sending @Sendable (isolated TaskManagerActor) -> Void) {
closure(self)
}

public func batch(_ closure: (isolated TaskManagerActor) async -> Void) async {
public func batch(_ closure: sending @Sendable (isolated TaskManagerActor) async -> Void) async {
await closure(self)
}

Expand Down
45 changes: 20 additions & 25 deletions Sources/ConcurrencyTaskManager/TaskQueueActor.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import Foundation
@preconcurrency import Combine

/**
structure of linked-list
it has a node for the next task after this node.
*/
final class TaskNode: CustomStringConvertible {
final class TaskNode: CustomStringConvertible, @unchecked Sendable {

struct WeakBox<T: AnyObject> {
weak var value: T?
}

private struct State {
private struct State: Sendable {

var isActivated: Bool = false
var isFinished: Bool = false
Expand All @@ -20,7 +21,7 @@ final class TaskNode: CustomStringConvertible {

private var anyTask: _Verge_TaskType?

let taskFactory: (WeakBox<TaskNode>) async -> Void
let taskFactory: (sending WeakBox<TaskNode>) async -> Void

private(set) var next: TaskNode?
let label: String
Expand All @@ -29,7 +30,7 @@ final class TaskNode: CustomStringConvertible {

init(
label: String = "",
@_inheritActorContext taskFactory: @escaping @Sendable (WeakBox<TaskNode>) async -> Void
@_inheritActorContext taskFactory: @escaping @Sendable (sending WeakBox<TaskNode>) async -> Void
) {
self.label = label
self.taskFactory = taskFactory
Expand Down Expand Up @@ -179,18 +180,8 @@ public actor TaskQueueActor {
}

// connecting to the next if presents

await self?.batch {
guard let node = box.value else { return }
if let next = node.next {
$0.head = next
next.activate()
} else {
if $0.head === node {
$0.head = nil
}
}
}

await self?.advance(box: box)

}

Expand Down Expand Up @@ -240,13 +231,17 @@ public actor TaskQueueActor {
}

}

/**
Performs given closure in a critical session
*/
@discardableResult
public func batch<Return>(_ perform: (isolated TaskQueueActor) -> Return) -> Return {
return perform(self)

func advance(box: sending TaskNode.WeakBox<TaskNode>) {
guard let node = box.value else { return }
if let next = node.next {
self.head = next
next.activate()
} else {
if self.head === node {
self.head = nil
}
}
}

}
Expand Down Expand Up @@ -275,7 +270,7 @@ final class AutoReleaseContinuationBox<T>: @unchecked Sendable {
self.continuation = continuation
}

func resume(throwing error: Error) {
func resume(throwing error: sending Error) {
lock.lock()
defer {
lock.unlock()
Expand All @@ -287,7 +282,7 @@ final class AutoReleaseContinuationBox<T>: @unchecked Sendable {
continuation?.resume(throwing: error)
}

func resume(returning value: T) {
func resume(returning value: sending T) {
lock.lock()
defer {
lock.unlock()
Expand Down
7 changes: 5 additions & 2 deletions Sources/ConcurrencyTaskManager/TaskStackActor.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DequeModule
import Foundation
@preconcurrency import Combine

public actor TaskStackActor {

Expand Down Expand Up @@ -105,7 +106,7 @@ public actor TaskStackActor {
continuation.yield(state)
}

continuation.onTermination = { _ in
continuation.onTermination = { _ in
cancellable.cancel()
}

Expand All @@ -129,7 +130,9 @@ public actor TaskStackActor {
state.update(waitingCount: stack.count, executingCount: currentExecutingTaskCount)
}

private func processForCompletion(taskNode: TaskNode) {
private func processForCompletion(
taskNode: sending TaskNode
) {
executings.removeAll { $0 === taskNode }
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/ConcurrencyTaskManagerTests/UnfairLockAtomic.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os.atomic

public final class UnfairLock: Sendable {
public final class UnfairLock: @unchecked Sendable {
private let _lock: os_unfair_lock_t

public init() {
Expand Down

0 comments on commit 613d07e

Please sign in to comment.