diff --git a/Package.swift b/Package.swift index 143c2fc..ed61c28 100644 --- a/Package.swift +++ b/Package.swift @@ -13,12 +13,14 @@ let package = Package( .package(url: "https://github.com/vapor/postgres-nio.git", from: "1.11.0"), .package(url: "https://github.com/vapor/sql-kit.git", from: "3.16.0"), .package(url: "https://github.com/vapor/async-kit.git", from: "1.0.0"), + .package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.0") ], targets: [ .target(name: "PostgresKit", dependencies: [ .product(name: "AsyncKit", package: "async-kit"), .product(name: "PostgresNIO", package: "postgres-nio"), .product(name: "SQLKit", package: "sql-kit"), + .product(name: "Atomics", package: "swift-atomics") ]), .testTarget(name: "PostgresKitTests", dependencies: [ .target(name: "PostgresKit"), diff --git a/Sources/PostgresKit/PostgresConnectionSource.swift b/Sources/PostgresKit/PostgresConnectionSource.swift index 57e2e27..4ceeeaa 100644 --- a/Sources/PostgresKit/PostgresConnectionSource.swift +++ b/Sources/PostgresKit/PostgresConnectionSource.swift @@ -1,10 +1,10 @@ -import NIOConcurrencyHelpers import NIOSSL +import Atomics public struct PostgresConnectionSource: ConnectionPoolSource { public let configuration: PostgresConfiguration public let sslContext: Result - private static let idGenerator = NIOAtomic.makeAtomic(value: 0) + private static let idGenerator = ManagedAtomic(0) public init(configuration: PostgresConfiguration) { self.configuration = configuration @@ -34,7 +34,7 @@ public struct PostgresConnectionSource: ConnectionPoolSource { authentication: .init(username: self.configuration.username, database: self.configuration.database, password: self.configuration.password), tls: tlsMode ), - id: Self.idGenerator.add(1), + id: Self.idGenerator.wrappingIncrementThenLoad(ordering: .relaxed), logger: logger )