Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class AuthComponent: NSObject, Library, ComponentLifecycleMaintainer {
private var instances: [String: Auth] = [:]

/// Lock to manage access to the instances array to avoid race conditions.
private var instancesLock: os_unfair_lock = .init()
private let instancesLock = OSAllocatedUnfairLock()

// MARK: - Initializers

Expand All @@ -58,10 +58,10 @@ class AuthComponent: NSObject, Library, ComponentLifecycleMaintainer {
// MARK: - AuthProvider conformance

@discardableResult func auth() -> Auth {
os_unfair_lock_lock(&instancesLock)
instancesLock.lock()

// Unlock before the function returns.
defer { os_unfair_lock_unlock(&instancesLock) }
defer { instancesLock.unlock() }

if let instance = instances[app.name] {
return instance
Expand Down
6 changes: 3 additions & 3 deletions FirebaseFunctions/Sources/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ enum FunctionsConstants {
private static var instances: [String: [Functions]] = [:]

/// Lock to manage access to the instances array to avoid race conditions.
private static var instancesLock: os_unfair_lock = .init()
private static let instancesLock = OSAllocatedUnfairLock()

/// The custom domain to use for all functions references (optional).
let customDomain: String?
Expand Down Expand Up @@ -304,10 +304,10 @@ enum FunctionsConstants {
guard let app else {
fatalError("`FirebaseApp.configure()` needs to be called before using Functions.")
}
os_unfair_lock_lock(&instancesLock)
instancesLock.lock()

// Unlock before the function returns.
defer { os_unfair_lock_unlock(&instancesLock) }
defer { instancesLock.unlock() }

if let associatedInstances = instances[app.name] {
for instance in associatedInstances {
Expand Down
6 changes: 3 additions & 3 deletions FirebaseStorage/Sources/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@
private var instances: [String: Storage] = [:]

/// Lock to manage access to the instances array to avoid race conditions.
private var instancesLock: os_unfair_lock = .init()
private let instancesLock = OSAllocatedUnfairLock

Check failure on line 252 in FirebaseStorage/Sources/Storage.swift

View workflow job for this annotation

GitHub Actions / storage-integration-tests (ObjC)

cannot find 'OSAllocatedUnfairLock' in scope

Check failure on line 252 in FirebaseStorage/Sources/Storage.swift

View workflow job for this annotation

GitHub Actions / storage-integration-tests (Swift)

cannot find 'OSAllocatedUnfairLock' in scope

private init() {}

func storage(app: FirebaseApp, bucket: String) -> Storage {
os_unfair_lock_lock(&instancesLock)
defer { os_unfair_lock_unlock(&instancesLock) }
instancesLock.lock()
defer { instancesLock.unlock() }

if let instance = instances[bucket] {
return instance
Expand Down
13 changes: 5 additions & 8 deletions FirebaseVertexAI/Sources/VertexAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,20 +124,17 @@ public class VertexAI {

let apiConfig: APIConfig

/// Lock to manage access to the `instances` array to avoid race conditions.
private static let instancesLock = OSAllocatedUnfairLock()

#if compiler(>=6)
/// A map of active `VertexAI` instances keyed by the `FirebaseApp` name and the `location`, in
/// the format `appName:location`.
private nonisolated(unsafe) static var instances: [InstanceKey: VertexAI] = [:]

/// Lock to manage access to the `instances` array to avoid race conditions.
private nonisolated(unsafe) static var instancesLock: os_unfair_lock = .init()
#else
/// A map of active `VertexAI` instances keyed by the `FirebaseApp` name and the `location`, in
/// the format `appName:location`.
private static var instances: [InstanceKey: VertexAI] = [:]

/// Lock to manage access to the `instances` array to avoid race conditions.
private static var instancesLock: os_unfair_lock = .init()
#endif

let location: String?
Expand All @@ -149,10 +146,10 @@ public class VertexAI {
fatalError("No instance of the default Firebase app was found.")
}

os_unfair_lock_lock(&instancesLock)
instancesLock.lock()

// Unlock before the function returns.
defer { os_unfair_lock_unlock(&instancesLock) }
defer { instancesLock.unlock() }

let instanceKey = InstanceKey(appName: app.name, location: location, apiConfig: apiConfig)
if let instance = instances[instanceKey] {
Expand Down
Loading