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.
This commit is contained in:
Cory Benfield 2019-12-10 12:35:02 +00:00 committed by Johannes Weiss
parent c17d6a7b57
commit c7f06384dc
6 changed files with 7 additions and 7 deletions

View File

@ -23,7 +23,7 @@ let package = Package(
.executable(name: "NIOTSHTTPServer", targets: ["NIOTSHTTPServer"]), .executable(name: "NIOTSHTTPServer", targets: ["NIOTSHTTPServer"]),
], ],
dependencies: [ 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: [ targets: [
.target(name: "NIOTransportServices", .target(name: "NIOTransportServices",

View File

@ -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 /// 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: /// 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. /// it always has some substantial runtime cost over loads/stores.
let writable = Atomic<Bool>(value: true) let writable = NIOAtomic<Bool>.makeAtomic(value: true)
/// The number of bytes outstanding on the network. /// The number of bytes outstanding on the network.
private var outstandingBytes: Int = 0 private var outstandingBytes: Int = 0
@ -184,7 +184,7 @@ internal final class NIOTSConnectionChannel {
internal var state: ChannelState<ActiveSubstate> = .idle internal var state: ChannelState<ActiveSubstate> = .idle
/// The active state, used for safely reporting the channel state across threads. /// The active state, used for safely reporting the channel state across threads.
internal var isActive0: Atomic<Bool> = Atomic(value: false) internal var isActive0: NIOAtomic<Bool> = .makeAtomic(value: false)
/// The kinds of channel activation this channel supports /// The kinds of channel activation this channel supports
internal let supportedActivationType: ActivationType = .connect internal let supportedActivationType: ActivationType = .connect

View File

@ -49,7 +49,7 @@ import Network
/// preferred networking backend. /// preferred networking backend.
@available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) @available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *)
public final class NIOTSEventLoopGroup: EventLoopGroup { public final class NIOTSEventLoopGroup: EventLoopGroup {
private let index = Atomic<Int>(value: 0) private let index = NIOAtomic<Int>.makeAtomic(value: 0)
private let eventLoops: [NIOTSEventLoop] private let eventLoops: [NIOTSEventLoop]
public init(loopCount: Int = 1, defaultQoS: DispatchQoS = .default) { public init(loopCount: Int = 1, defaultQoS: DispatchQoS = .default) {

View File

@ -65,7 +65,7 @@ internal final class NIOTSListenerChannel {
internal let supportedActivationType: ActivationType = .bind internal let supportedActivationType: ActivationType = .bind
/// The active state, used for safely reporting the channel state across threads. /// The active state, used for safely reporting the channel state across threads.
internal var isActive0: Atomic<Bool> = Atomic(value: false) internal var isActive0: NIOAtomic<Bool> = .makeAtomic(value: false)
/// Whether a call to NWListener.receive has been made, but the completion /// Whether a call to NWListener.receive has been made, but the completion
/// handler has not yet been invoked. /// handler has not yet been invoked.

View File

@ -104,7 +104,7 @@ internal protocol StateManagedChannel: Channel, ChannelCore {
var state: ChannelState<ActiveSubstate> { get set } var state: ChannelState<ActiveSubstate> { get set }
var isActive0: Atomic<Bool> { get set } var isActive0: NIOAtomic<Bool> { get set }
var tsEventLoop: NIOTSEventLoop { get } var tsEventLoop: NIOTSEventLoop { get }

View File

@ -103,7 +103,7 @@ class NIOTSEventLoopTest: XCTestCase {
weakELG = group weakELG = group
weakEL = group.next() weakEL = group.next()
let counter = Atomic<Int>(value: 0) let counter = NIOAtomic<Int>.makeAtomic(value: 0)
let acceptedChan = group.next().makePromise(of: Channel.self) let acceptedChan = group.next().makePromise(of: Channel.self)
let server = try NIOTSListenerBootstrap(group: group) let server = try NIOTSListenerBootstrap(group: group)
.childChannelInitializer { channel in .childChannelInitializer { channel in