Skip to content

Commit 27bf96b

Browse files
authored
Use swift-atomics instead of NIOAtomics (#117)
`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.
1 parent fa0de40 commit 27bf96b

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ let package = Package(
2929
dependencies: [
3030
.package(url: "https://github.com/apple/swift-nio.git", from: "2.32.0"),
3131
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
32+
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
3233
],
3334
targets: [
3435
.target(
@@ -38,6 +39,7 @@ let package = Package(
3839
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
3940
.product(name: "NIOFoundationCompat", package: "swift-nio"),
4041
.product(name: "Crypto", package: "swift-crypto"),
42+
.product(name: "Atomics", package: "swift-atomics"),
4143
]
4244
),
4345
.executableTarget(

Sources/NIOSSH/Child Channels/SSHChannelType.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14-
#if swift(>=5.6)
15-
@preconcurrency import NIOCore
16-
#else
14+
1715
import NIOCore
18-
#endif // swift(>=5.6)
1916

2017
/// `SSHChannelType` represents the type of a single SSH channel.
2118
///

Sources/NIOSSH/Child Channels/SSHChildChannel.swift

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
#if swift(>=5.6)
16-
@preconcurrency import NIOCore
17-
#else
18-
import NIOCore
19-
#endif
15+
import Atomics
2016
import NIOConcurrencyHelpers
17+
import NIOCore
2118

2219
/// A NIO `Channel` that encapsulates a single SSH `Channel`.
2320
///
@@ -90,9 +87,9 @@ final class SSHChildChannel {
9087

9188
public let eventLoop: EventLoop
9289

93-
private let _isWritable: NIOAtomic<Bool>
90+
private let _isWritable: ManagedAtomic<Bool>
9491

95-
private let _isActive: NIOAtomic<Bool>
92+
private let _isActive: ManagedAtomic<Bool>
9693

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

@@ -135,8 +132,8 @@ final class SSHChildChannel {
135132
self.multiplexer = multiplexer
136133
self.initializer = initializer
137134
self.windowManager = ChildChannelWindowManager(targetWindowSize: UInt32(targetWindowSize))
138-
self._isWritable = .makeAtomic(value: true)
139-
self._isActive = .makeAtomic(value: false)
135+
self._isWritable = .init(true)
136+
self._isActive = .init(false)
140137
self.state = initialState
141138
self.writabilityManager = ChildChannelWritabilityManager(initialWindowSize: initialOutboundWindowSize,
142139
parentIsWritable: parent.isWritable)
@@ -240,11 +237,11 @@ extension SSHChildChannel: Channel, ChannelCore {
240237
}
241238

242239
public var isWritable: Bool {
243-
self._isWritable.load()
240+
self._isWritable.load(ordering: .relaxed)
244241
}
245242

246243
public var isActive: Bool {
247-
self._isActive.load()
244+
self._isActive.load(ordering: .relaxed)
248245
}
249246

250247
public var _channelCore: ChannelCore {
@@ -618,7 +615,7 @@ extension SSHChildChannel: Channel, ChannelCore {
618615
}
619616

620617
private func changeWritability(to newWritability: Bool) {
621-
self._isWritable.store(newWritability)
618+
self._isWritable.store(newWritability, ordering: .relaxed)
622619
self.pipeline.fireChannelWritabilityChanged()
623620
}
624621

@@ -1030,14 +1027,14 @@ extension SSHChildChannel {
10301027
switch self.activationState {
10311028
case .neverActivated:
10321029
self.activationState = .activated
1033-
self._isActive.store(true)
1030+
self._isActive.store(true, ordering: .relaxed)
10341031
self.pipeline.fireChannelActive()
10351032

10361033
case .activated:
1037-
assert(self._isActive.load() == true)
1034+
assert(self._isActive.load(ordering: .relaxed) == true)
10381035

10391036
case .deactivated:
1040-
assert(self._isActive.load() == false)
1037+
assert(self._isActive.load(ordering: .relaxed) == false)
10411038
}
10421039
}
10431040

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

10511048
case .activated:
10521049
self.activationState = .deactivated
1053-
self._isActive.store(false)
1050+
self._isActive.store(false, ordering: .relaxed)
10541051
self.pipeline.fireChannelInactive()
10551052

10561053
case .deactivated:
1057-
assert(self._isActive.load() == false)
1054+
assert(self._isActive.load(ordering: .relaxed) == false)
10581055
}
10591056
}
10601057
}

0 commit comments

Comments
 (0)