Skip to content

Commit

Permalink
Revert "Final removal of actors (#57)"
Browse files Browse the repository at this point in the history
This reverts commit 2f8d44c.
  • Loading branch information
rvsrvs committed Aug 21, 2022
1 parent 26325a5 commit 2ac8519
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 182 deletions.
12 changes: 6 additions & 6 deletions Sources/FreeCombine/State/StateTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
/*:
#actor problems

1. no oneway funcs (i.e. they can’t be called from synchronous code)
2. cant selectively block callers in order (i.e. passing a continuation to an actor requires spawning a task which gives up ordering guarantees)
3. cant block calling tasks on internal state (can only block with async call to another task)
4. have no concept of cancellation (cannot perform orderly shutdown with outstanding requests in flight)
5. they execute on global actor queues (generally not needed or desirable to go off-Task for these things)
6. No way to allow possible failure to enqueue on an overburdened actor, all requests enter an unbounded queue
1. no oneway funcs (can't call from synchronous code)
2. can't selectively block callers (to pass a continuation to an actor requires spawning a task which gives up ordering guarantees)
3. can't block calling tasks on internal state (can only block with async call to another task)
4. no concept of cancellation (cannot perform orderly shutdown with outstanding requests in flight)
5. execute on global actor queues (generally not needed or desirable)
6. No way of possible failure to enqueue on an overburdened actor, all requests enter an unbounded queue

#actor solutions: StateTask - a swift implementation of the Haskell ST monad

Expand Down
135 changes: 0 additions & 135 deletions Sources/FreeCombine/Synchronization/LockFreeQueue.swift

This file was deleted.

39 changes: 14 additions & 25 deletions Sources/FreeCombine/Synchronization/SingleConsumerStack.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,17 @@
//===----------------------------------------------------------------------===//
//
// Semaphore.swift
// This source file is part of the Swift Atomics open source project
//
// Copyright (c) 2020-2021 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// Created by Van Simmons on 4/24/22.
// Derived from: https://github.com/apple/swift-atomics/blob/main/Tests/AtomicsTests/LockFreeSingleConsumerStack.swift
// As per, the Apache license this is a derivative work.
//
// Copyright 2022, ComputeCycles, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Atomics

class SingleConsumerStack<Element> {
class LockFreeSingleConsumerStack<Element> {
struct Node {
let value: Element
var next: UnsafeMutablePointer<Node>?
Expand All @@ -35,7 +24,7 @@ class SingleConsumerStack<Element> {

deinit {
// Discard remaining nodes
while let _ = pop() { }
while let _ = pop() {}
_last.destroy()
_consumerCount.destroy()
}
Expand All @@ -53,17 +42,17 @@ class SingleConsumerStack<Element> {
(done, current) = _last.compareExchange(
expected: current,
desired: new,
ordering: .releasing
)
ordering: .releasing)
}
}

// Pop and return the topmost element from the stack.
// This method does not support multiple overlapping concurrent calls.
func pop() -> Element? {
guard _consumerCount.loadThenWrappingIncrement(ordering: .acquiring) == 0 else {
return .none
}
precondition(
_consumerCount.loadThenWrappingIncrement(ordering: .acquiring) == 0,
"Multiple consumers detected"
)
defer { _consumerCount.wrappingDecrement(ordering: .releasing) }
var done = false
var current = _last.load(ordering: .acquiring)
Expand Down
2 changes: 1 addition & 1 deletion Sources/FreeCombine/Utils/Counter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public struct Counter {
}

@discardableResult
public func decrement(by: Int = 1) -> Int {
public func decrement(by: Int = -1) -> Int {
var c = atomicValue.load(ordering: .sequentiallyConsistent)
while !atomicValue.compareExchange(
expected: c,
Expand Down
17 changes: 2 additions & 15 deletions Sources/Time/TimeNever.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@
//
// Created by Van Simmons on 7/4/22.
//
// Copyright 2022, ComputeCycles, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

enum TimeNever {
// Provide a type for this package which is only used for testing

}

0 comments on commit 2ac8519

Please sign in to comment.