Skip to content

Commit

Permalink
Migrate to Swift Atomics (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
fatto authored Aug 19, 2022
1 parent e436a94 commit e979753
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
6 changes: 3 additions & 3 deletions Sources/PostgresKit/PostgresConnectionSource.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import NIOConcurrencyHelpers
import NIOSSL
import Atomics

public struct PostgresConnectionSource: ConnectionPoolSource {
public let configuration: PostgresConfiguration
public let sslContext: Result<NIOSSLContext?, Error>
private static let idGenerator = NIOAtomic.makeAtomic(value: 0)
private static let idGenerator = ManagedAtomic<Int>(0)

public init(configuration: PostgresConfiguration) {
self.configuration = configuration
Expand Down Expand Up @@ -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
)

Expand Down

0 comments on commit e979753

Please sign in to comment.