Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use swift-atomics instead of NIOAtomics
`NIOAtomics` was deprecated in apple/swift-nio#2204 in favor of `swift-atomics` https://github.com/apple/swift-atomics
In addition, the `@preconcrrency` imports of `NIOCore` are not required and do not produce warnings/errors even with the currently latest released version of swift-nio (2.40.0), changes from `main` are not required.
  • Loading branch information
dnadoba committed Jul 8, 2022
commit e897c0ff55d989aa95c2b373d1e7aa483d205698
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
],
targets: [
.target(
Expand All @@ -38,6 +39,7 @@ let package = Package(
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOFoundationCompat", package: "swift-nio"),
.product(name: "Crypto", package: "swift-crypto"),
.product(name: "Atomics", package: "swift-atomics"),
]
),
.executableTarget(
Expand Down
5 changes: 1 addition & 4 deletions Sources/NIOSSH/Child Channels/SSHChannelType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
#if swift(>=5.6)
@preconcurrency import NIOCore
#else

import NIOCore
#endif // swift(>=5.6)

/// `SSHChannelType` represents the type of a single SSH channel.
///
Expand Down
33 changes: 15 additions & 18 deletions Sources/NIOSSH/Child Channels/SSHChildChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
//
//===----------------------------------------------------------------------===//

#if swift(>=5.6)
@preconcurrency import NIOCore
#else
import NIOCore
#endif
import Atomics
import NIOConcurrencyHelpers
import NIOCore

/// A NIO `Channel` that encapsulates a single SSH `Channel`.
///
Expand Down Expand Up @@ -90,9 +87,9 @@ final class SSHChildChannel {

public let eventLoop: EventLoop

private let _isWritable: NIOAtomic<Bool>
private let _isWritable: ManagedAtomic<Bool>

private let _isActive: NIOAtomic<Bool>
private let _isActive: ManagedAtomic<Bool>

typealias Initializer = (Channel, SSHChannelType) -> EventLoopFuture<Void>

Expand Down Expand Up @@ -135,8 +132,8 @@ final class SSHChildChannel {
self.multiplexer = multiplexer
self.initializer = initializer
self.windowManager = ChildChannelWindowManager(targetWindowSize: UInt32(targetWindowSize))
self._isWritable = .makeAtomic(value: true)
self._isActive = .makeAtomic(value: false)
self._isWritable = .init(true)
self._isActive = .init(false)
self.state = initialState
self.writabilityManager = ChildChannelWritabilityManager(initialWindowSize: initialOutboundWindowSize,
parentIsWritable: parent.isWritable)
Expand Down Expand Up @@ -240,11 +237,11 @@ extension SSHChildChannel: Channel, ChannelCore {
}

public var isWritable: Bool {
self._isWritable.load()
self._isWritable.load(ordering: .relaxed)
}

public var isActive: Bool {
self._isActive.load()
self._isActive.load(ordering: .relaxed)
}

public var _channelCore: ChannelCore {
Expand Down Expand Up @@ -618,7 +615,7 @@ extension SSHChildChannel: Channel, ChannelCore {
}

private func changeWritability(to newWritability: Bool) {
self._isWritable.store(newWritability)
self._isWritable.store(newWritability, ordering: .relaxed)
self.pipeline.fireChannelWritabilityChanged()
}

Expand Down Expand Up @@ -1030,14 +1027,14 @@ extension SSHChildChannel {
switch self.activationState {
case .neverActivated:
self.activationState = .activated
self._isActive.store(true)
self._isActive.store(true, ordering: .relaxed)
self.pipeline.fireChannelActive()

case .activated:
assert(self._isActive.load() == true)
assert(self._isActive.load(ordering: .relaxed) == true)

case .deactivated:
assert(self._isActive.load() == false)
assert(self._isActive.load(ordering: .relaxed) == false)
}
}

Expand All @@ -1046,15 +1043,15 @@ extension SSHChildChannel {
case .neverActivated:
// Do nothing, transition to inactive.
self.activationState = .deactivated
assert(self._isActive.load() == false)
assert(self._isActive.load(ordering: .relaxed) == false)

case .activated:
self.activationState = .deactivated
self._isActive.store(false)
self._isActive.store(false, ordering: .relaxed)
self.pipeline.fireChannelInactive()

case .deactivated:
assert(self._isActive.load() == false)
assert(self._isActive.load(ordering: .relaxed) == false)
}
}
}
Expand Down