File tree Expand file tree Collapse file tree 3 files changed +57
-12
lines changed Expand file tree Collapse file tree 3 files changed +57
-12
lines changed Original file line number Diff line number Diff line change @@ -149,13 +149,14 @@ private enum GoogleDataTransportConfig {
149
149
150
150
super. init ( )
151
151
152
- for subscriberName in SessionsDependencies . dependencies {
152
+ let dependencies = SessionsDependencies . dependencies
153
+ for subscriberName in dependencies {
153
154
subscriberPromises [ subscriberName] = Promise< Void> . pending( )
154
155
}
155
156
156
157
Logger
157
158
. logDebug (
158
- " Version \( FirebaseVersion ( ) ) . Expecting subscriptions from: \( SessionsDependencies . dependencies) "
159
+ " Version \( FirebaseVersion ( ) ) . Expecting subscriptions from: \( dependencies) "
159
160
)
160
161
161
162
self . initiator. beginListening {
Original file line number Diff line number Diff line change 15
15
16
16
import Foundation
17
17
18
- // Sessions Dependencies determines when a dependent SDK is
19
- // installed in the app. The Sessions SDK uses this to figure
20
- // out which dependencies to wait for to getting the data
21
- // collection state.
22
- //
23
- // This is important because the Sessions SDK starts up before
24
- // dependent SDKs
18
+ private final class AtomicBox < T> {
19
+ private var _value : T
20
+ private let lock = NSLock ( )
21
+
22
+ init ( _ value: T ) {
23
+ _value = value
24
+ }
25
+
26
+ func value( ) -> T {
27
+ lock. withLock {
28
+ _value
29
+ }
30
+ }
31
+
32
+ @discardableResult func withLock( _ body: ( _ value: inout T ) -> Void ) -> T {
33
+ lock. withLock {
34
+ body ( & _value)
35
+ return _value
36
+ }
37
+ }
38
+ }
39
+
40
+ /// Sessions Dependencies determines when a dependent SDK is
41
+ /// installed in the app. The Sessions SDK uses this to figure
42
+ /// out which dependencies to wait for to getting the data
43
+ /// collection state.
44
+ ///
45
+ /// This is important because the Sessions SDK starts up before
46
+ /// dependent SDKs
25
47
@objc ( FIRSessionsDependencies)
26
48
public class SessionsDependencies : NSObject {
27
- static var dependencies : Set < SessionsSubscriberName > = . init( )
49
+ #if compiler(>=6)
50
+ private nonisolated ( unsafe) static let _dependencies : AtomicBox < Set < SessionsSubscriberName > > =
51
+ AtomicBox (
52
+ Set ( )
53
+ )
54
+ #else
55
+ private static let _dependencies : AtomicBox < Set < SessionsSubscriberName > > = AtomicBox (
56
+ Set ( )
57
+ )
58
+ #endif
59
+
60
+ static var dependencies : Set < SessionsSubscriberName > {
61
+ _dependencies. value ( )
62
+ }
28
63
29
64
@objc public static func addDependency( name: SessionsSubscriberName ) {
30
- SessionsDependencies . dependencies. insert ( name)
65
+ _dependencies. withLock { dependencies in
66
+ dependencies. insert ( name)
67
+ }
68
+ }
69
+
70
+ /// For testing only.
71
+ static func removeAll( ) {
72
+ _dependencies. withLock { dependencies in
73
+ dependencies. removeAll ( )
74
+ }
31
75
}
32
76
}
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ class FirebaseSessionsTestsBase: XCTestCase {
77
77
postLogEvent: @escaping ( Result < Void , FirebaseSessionsError > ,
78
78
[ SessionsSubscriber ] ) -> Void ) {
79
79
// This class is static, so we need to clear global state
80
- SessionsDependencies . dependencies . removeAll ( )
80
+ SessionsDependencies . removeAll ( )
81
81
82
82
for subscriberSDK in subscriberSDKs {
83
83
SessionsDependencies . addDependency ( name: subscriberSDK. sessionsSubscriberName)
You can’t perform that action at this time.
0 commit comments