diff --git a/FirebaseCore/Internal/Sources/Utilities/AtomicBox.swift b/FirebaseCore/Internal/Sources/Utilities/AtomicBox.swift deleted file mode 100644 index 6346d05701c..00000000000 --- a/FirebaseCore/Internal/Sources/Utilities/AtomicBox.swift +++ /dev/null @@ -1,45 +0,0 @@ -// 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 - -final class AtomicBox { - private var _value: T - private let lock = NSLock() - - public init(_ value: T) { - _value = value - } - - public func value() -> T { - lock.withLock { - _value - } - } - - @discardableResult - public func withLock(_ mutatingBody: (_ value: inout T) -> Void) -> T { - lock.withLock { - mutatingBody(&_value) - return _value - } - } - - @discardableResult - public func withLock(_ mutatingBody: (_ value: inout T) throws -> R) rethrows -> R { - try lock.withLock { - try mutatingBody(&_value) - } - } -} diff --git a/FirebaseFunctions/Sources/Functions.swift b/FirebaseFunctions/Sources/Functions.swift index a87c68324a8..8ab6d63e780 100644 --- a/FirebaseFunctions/Sources/Functions.swift +++ b/FirebaseFunctions/Sources/Functions.swift @@ -25,36 +25,7 @@ import Foundation #endif internal import FirebaseCoreExtension - -final class AtomicBox: Sendable { - private nonisolated(unsafe) var _value: T - private let lock = NSLock() - - public init(_ value: T) where T: Sendable { - _value = value - } - - public func value() -> T { - lock.withLock { - _value - } - } - - @discardableResult - public func withLock(_ mutatingBody: (_ value: inout T) -> Void) -> T { - lock.withLock { - mutatingBody(&_value) - return _value - } - } - - @discardableResult - public func withLock(_ mutatingBody: (_ value: inout T) throws -> R) rethrows -> R { - try lock.withLock { - try mutatingBody(&_value) - } - } -} +private import FirebaseCoreInternal /// File specific constants. private enum Constants { @@ -82,8 +53,7 @@ enum FunctionsConstants { /// A map of active instances, grouped by app. Keys are FirebaseApp names and values are arrays /// containing all instances of Functions associated with the given app. - private static let instances: AtomicBox<[String: [Functions]]> = - AtomicBox([:]) + private static let instances = FIRAllocatedUnfairLock<[String: [Functions]]>(initialState: [:]) /// The custom domain to use for all functions references (optional). let customDomain: String? @@ -91,7 +61,7 @@ enum FunctionsConstants { /// The region to use for all function references. let region: String - private let _emulatorOrigin: AtomicBox + private let _emulatorOrigin: FIRAllocatedUnfairLock // MARK: - Public APIs @@ -371,7 +341,7 @@ enum FunctionsConstants { self.projectID = projectID self.region = region self.customDomain = customDomain - _emulatorOrigin = AtomicBox(nil) + _emulatorOrigin = FIRAllocatedUnfairLock(initialState: nil) contextProvider = FunctionsContextProvider(auth: auth, messaging: messaging, appCheck: appCheck) diff --git a/FirebaseFunctions/Sources/HTTPSCallable.swift b/FirebaseFunctions/Sources/HTTPSCallable.swift index b1d00830576..ab839003e17 100644 --- a/FirebaseFunctions/Sources/HTTPSCallable.swift +++ b/FirebaseFunctions/Sources/HTTPSCallable.swift @@ -14,6 +14,8 @@ import Foundation +private import FirebaseCoreInternal + /// A `HTTPSCallableResult` contains the result of calling a `HTTPSCallable`. @objc(FIRHTTPSCallableResult) open class HTTPSCallableResult: NSObject { @@ -163,7 +165,7 @@ private extension HTTPSCallable { // MARK: - Public Properties - let _timeoutInterval: AtomicBox = .init(70) + let _timeoutInterval = FIRAllocatedUnfairLock(initialState: 70) /// The timeout to use when calling the function. Defaults to 70 seconds. var timeoutInterval: TimeInterval { diff --git a/FirebaseSessions/Sources/Public/SessionsDependencies.swift b/FirebaseSessions/Sources/Public/SessionsDependencies.swift index e929fff98d4..9e0b3aafe6e 100644 --- a/FirebaseSessions/Sources/Public/SessionsDependencies.swift +++ b/FirebaseSessions/Sources/Public/SessionsDependencies.swift @@ -15,27 +15,7 @@ import Foundation -private final class AtomicBox { - private var _value: T - private let lock = NSLock() - - init(_ value: T) { - _value = value - } - - func value() -> T { - lock.withLock { - _value - } - } - - @discardableResult func withLock(_ body: (_ value: inout T) -> Void) -> T { - lock.withLock { - body(&_value) - return _value - } - } -} +private import FirebaseCoreInternal /// Sessions Dependencies determines when a dependent SDK is /// installed in the app. The Sessions SDK uses this to figure @@ -46,10 +26,8 @@ private final class AtomicBox { /// dependent SDKs @objc(FIRSessionsDependencies) public class SessionsDependencies: NSObject { - private nonisolated(unsafe) static let _dependencies: AtomicBox> = - AtomicBox( - Set() - ) + private static let _dependencies = + FIRAllocatedUnfairLock>(initialState: Set()) static var dependencies: Set { _dependencies.value()