Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions FirebaseAuth/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Replaced unsafe uses of `os_unfair_lock` (#14548).

# 11.9.0
- [changed] Using reCAPTCHA Enterprise and Firebase Auth requires reCAPTCHA
Enterprise 18.7.0 or later.
Expand Down
7 changes: 4 additions & 3 deletions FirebaseAuth/Sources/Swift/Auth/AuthComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import FirebaseAppCheckInterop
import FirebaseAuthInterop
import FirebaseCore
import FirebaseCoreExtension
import FirebaseCoreInternal

@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
@objc(FIRAuthComponent)
Expand All @@ -33,7 +34,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: FirebaseCoreInternal.FIRAllocatedUnfairLock<Void> = .init()

// MARK: - Initializers

Expand All @@ -58,10 +59,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
62 changes: 62 additions & 0 deletions FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import os.lock

/// A reference wrapper around `os_unfair_lock`. Replace this class with
/// `OSAllocatedUnfairLock` once we support only iOS 16+. For an explanation
/// on why this is necessary, see the docs:
/// https://developer.apple.com/documentation/os/osallocatedunfairlock
public final class FIRAllocatedUnfairLock<State>: @unchecked Sendable {
private var lockPointer: UnsafeMutablePointer<os_unfair_lock>
private var state: State

public init(initialState: sending State) {

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-integration (macos-14, Xcode_15.4)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-integration (macos-14, Xcode_15.4)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-integration (macos-14, Xcode_15.4)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-integration (macos-14, Xcode_15.4)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-integration (macos-14, Xcode_15.4)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-integration (macos-14, Xcode_15.4)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-13, Xcode_15.2, iOS)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-13, Xcode_15.2, iOS)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-13, Xcode_15.2, iOS)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-14, Xcode_15.4, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

cannot find type 'sending' in scope

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

expected ',' separator

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

unnamed parameters must be written with the empty name '_'

Check failure on line 26 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

cannot find type 'sending' in scope
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need an alternative signature for Swift 5.9

lockPointer = UnsafeMutablePointer<os_unfair_lock>
.allocate(capacity: 1)
lockPointer.initialize(to: os_unfair_lock())
state = initialState
}

public convenience init() where State == Void {
self.init(initialState: ())

Check failure on line 34 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS)

argument passed to call that takes no arguments

Check failure on line 34 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-14, Xcode_15.4, iOS)

argument passed to call that takes no arguments

Check failure on line 34 in FirebaseCore/Internal/Sources/FIRAllocatedUnfairLock.swift

View workflow job for this annotation

GitHub Actions / spm (macos-13, Xcode_15.2, iOS spm)

argument passed to call that takes no arguments
}

public func lock() {
os_unfair_lock_lock(lockPointer)
}

public func unlock() {
os_unfair_lock_unlock(lockPointer)
}

public func withLock<R>(_ body: (inout State) throws -> R) rethrows -> R where R: Sendable {
let value: R
lock(); defer { unlock() }
value = try body(&state)
return value
}

public func withLock<R>(_ body: () throws -> R) rethrows -> R where R: Sendable {
let value: R
lock(); defer { unlock() }
value = try body()
return value
}

deinit {
lockPointer.deallocate()
}
}
3 changes: 3 additions & 0 deletions FirebaseFunctions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Replaced unsafe uses of `os_unfair_lock` (#14548).

# 11.10.0
- [added] Streaming callable functions are now supported.

Expand Down
2 changes: 1 addition & 1 deletion FirebaseFunctions/Sources/Callable+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public extension Callable where Request: Sendable, Response: Sendable {
// `StreamResponseProtocol`, we know the `Response` generic argument
// is `StreamResponse<_, _>`.
let responseJSON = switch response {
case .message(let json), .result(let json): json
case let .message(json), let .result(json): json
}
let response = try decoder.decode(Response.self, from: responseJSON)
if response is StreamResponseProtocol {
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 @@
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 = FirebaseCoreInternal.FIRAllocatedUnfairLock<Void>()

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 59 in FirebaseFunctions/Sources/Functions.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

/// The custom domain to use for all functions references (optional).
let customDomain: String?
Expand Down Expand Up @@ -304,10 +304,10 @@
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
3 changes: 3 additions & 0 deletions FirebaseStorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Replaced unsafe uses of `os_unfair_lock` (#14548).

# 11.1.0
- [fixed] Fix a potential data race in Storage initialization. (#13369)

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 = FirebaseCoreInternal.FIRAllocatedUnfairLock<Void>()

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, visionOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, visionOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, visionOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, catalyst)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, catalyst)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm (macos-15, Xcode_16.2, catalyst)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / testapp-integration (iOS, macos-15)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, macOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, tvOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / storage-integration-tests (ObjC)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / storage-integration-tests (ObjC)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / storage-integration-tests (ObjC)

cannot find 'FirebaseCoreInternal' in scope

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

View workflow job for this annotation

GitHub Actions / storage-integration-tests (ObjC)

cannot find 'FirebaseCoreInternal' 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 'FirebaseCoreInternal' 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 'FirebaseCoreInternal' 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 'FirebaseCoreInternal' 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
3 changes: 3 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Unreleased
- [fixed] Replaced unsafe uses of `os_unfair_lock` (#14548).

# 11.10.0
- [feature] The Vertex AI SDK no longer requires `@preconcurrency` when imported in Swift 6.
- [feature] The Vertex AI Sample App now includes an image generation example.
Expand Down
13 changes: 5 additions & 8 deletions FirebaseVertexAI/Sources/VertexAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,17 @@

let apiConfig: APIConfig

/// Lock to manage access to the `instances` array to avoid race conditions.
private static let instancesLock = FirebaseCoreInternal.FIRAllocatedUnfairLock<Void>()

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / testapp-integration (iOS, macos-15)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, visionOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, iOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, watchOS)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, catalyst)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, catalyst)

cannot find 'FirebaseCoreInternal' in scope

Check failure on line 127 in FirebaseVertexAI/Sources/VertexAI.swift

View workflow job for this annotation

GitHub Actions / spm-unit (macos-15, Xcode_16.2, catalyst)

cannot find 'FirebaseCoreInternal' in scope

#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 @@ -148,10 +145,10 @@
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