From c7f06384dc5ce7e8506de5ed9b59e35b4d88c64b Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 10 Dec 2019 12:35:02 +0000 Subject: [PATCH] Adopt NIOAtomic (#67) Motivation: We deprecated Atomic because we made a new, better one. We should use it. Modifications: Replaced all use of Atomic with NIOAtomic. Result: Better performance, fewer compiler warnings. --- Package.swift | 2 +- Sources/NIOTransportServices/NIOTSConnectionChannel.swift | 4 ++-- Sources/NIOTransportServices/NIOTSEventLoopGroup.swift | 2 +- Sources/NIOTransportServices/NIOTSListenerChannel.swift | 2 +- Sources/NIOTransportServices/StateManagedChannel.swift | 2 +- Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index 7e01ace..a583dfe 100644 --- a/Package.swift +++ b/Package.swift @@ -23,7 +23,7 @@ let package = Package( .executable(name: "NIOTSHTTPServer", targets: ["NIOTSHTTPServer"]), ], dependencies: [ - .package(url: "https://github.com/apple/swift-nio.git", from: "2.9.0"), + .package(url: "https://github.com/apple/swift-nio.git", from: "2.11.0"), ], targets: [ .target(name: "NIOTransportServices", diff --git a/Sources/NIOTransportServices/NIOTSConnectionChannel.swift b/Sources/NIOTransportServices/NIOTSConnectionChannel.swift index 45eb6ae..6b540c5 100644 --- a/Sources/NIOTransportServices/NIOTSConnectionChannel.swift +++ b/Sources/NIOTransportServices/NIOTSConnectionChannel.swift @@ -81,7 +81,7 @@ private struct BackpressureManager { /// because in most cases these loads/stores will be free, as the user will never actually check the /// channel writability from another thread, meaning this cache line is uncontended. CAS is never free: /// it always has some substantial runtime cost over loads/stores. - let writable = Atomic(value: true) + let writable = NIOAtomic.makeAtomic(value: true) /// The number of bytes outstanding on the network. private var outstandingBytes: Int = 0 @@ -184,7 +184,7 @@ internal final class NIOTSConnectionChannel { internal var state: ChannelState = .idle /// The active state, used for safely reporting the channel state across threads. - internal var isActive0: Atomic = Atomic(value: false) + internal var isActive0: NIOAtomic = .makeAtomic(value: false) /// The kinds of channel activation this channel supports internal let supportedActivationType: ActivationType = .connect diff --git a/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift b/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift index be20de1..66fc4c6 100644 --- a/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift +++ b/Sources/NIOTransportServices/NIOTSEventLoopGroup.swift @@ -49,7 +49,7 @@ import Network /// preferred networking backend. @available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) public final class NIOTSEventLoopGroup: EventLoopGroup { - private let index = Atomic(value: 0) + private let index = NIOAtomic.makeAtomic(value: 0) private let eventLoops: [NIOTSEventLoop] public init(loopCount: Int = 1, defaultQoS: DispatchQoS = .default) { diff --git a/Sources/NIOTransportServices/NIOTSListenerChannel.swift b/Sources/NIOTransportServices/NIOTSListenerChannel.swift index b18f20d..50af01f 100644 --- a/Sources/NIOTransportServices/NIOTSListenerChannel.swift +++ b/Sources/NIOTransportServices/NIOTSListenerChannel.swift @@ -65,7 +65,7 @@ internal final class NIOTSListenerChannel { internal let supportedActivationType: ActivationType = .bind /// The active state, used for safely reporting the channel state across threads. - internal var isActive0: Atomic = Atomic(value: false) + internal var isActive0: NIOAtomic = .makeAtomic(value: false) /// Whether a call to NWListener.receive has been made, but the completion /// handler has not yet been invoked. diff --git a/Sources/NIOTransportServices/StateManagedChannel.swift b/Sources/NIOTransportServices/StateManagedChannel.swift index 68a2e0e..3f21e53 100644 --- a/Sources/NIOTransportServices/StateManagedChannel.swift +++ b/Sources/NIOTransportServices/StateManagedChannel.swift @@ -104,7 +104,7 @@ internal protocol StateManagedChannel: Channel, ChannelCore { var state: ChannelState { get set } - var isActive0: Atomic { get set } + var isActive0: NIOAtomic { get set } var tsEventLoop: NIOTSEventLoop { get } diff --git a/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift b/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift index e415621..e36ab97 100644 --- a/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift +++ b/Tests/NIOTransportServicesTests/NIOTSEventLoopTests.swift @@ -103,7 +103,7 @@ class NIOTSEventLoopTest: XCTestCase { weakELG = group weakEL = group.next() - let counter = Atomic(value: 0) + let counter = NIOAtomic.makeAtomic(value: 0) let acceptedChan = group.next().makePromise(of: Channel.self) let server = try NIOTSListenerBootstrap(group: group) .childChannelInitializer { channel in