@@ -2,7 +2,7 @@ import Foundation
2
2
3
3
@objc @_spi ( Private) public final class SentryExtraPackages : NSObject {
4
4
private static var extraPackages = Set < [ String : String ] > ( )
5
- private static let syncQueue = DispatchQueue ( label : " io.sentry.SentryExtraPackages.sync " , attributes : . concurrent )
5
+ private static let lock = NSRecursiveLock ( )
6
6
7
7
@objc
8
8
public static func addPackageName( _ name: String ? , version: String ? ) {
@@ -12,28 +12,21 @@ import Foundation
12
12
13
13
let newPackage = [ " name " : name, " version " : version]
14
14
15
- // Thread-safe write using a barrier block on a concurrent queue.
16
- // Ensures no other reads or writes happen during this insertion.
17
- syncQueue. async ( flags: . barrier) {
15
+ _ = lock. synchronized {
18
16
extraPackages. insert ( newPackage)
19
17
}
20
18
}
21
19
22
20
@objc
23
21
public static func getPackages( ) -> NSMutableSet {
24
- var copy : Set < [ String : String ] > = [ ]
25
- // Thread-safe synchronous read on a concurrent queue.
26
- // Multiple reads can happen concurrently unless a write barrier is active.
27
- // Returns a copy to prevent external mutation of internal state.
28
- syncQueue. sync {
29
- copy = extraPackages
22
+ lock. synchronized {
23
+ NSMutableSet ( set: extraPackages as NSSet )
30
24
}
31
- return NSMutableSet ( set: copy as NSSet )
32
25
}
33
26
34
27
#if SENTRY_TEST || SENTRY_TEST_CI
35
28
static func clear( ) {
36
- syncQueue . async ( flags : . barrier ) {
29
+ lock . synchronized {
37
30
extraPackages. removeAll ( )
38
31
}
39
32
}
0 commit comments