Skip to content

Commit 1b0eb72

Browse files
committed
lock
1 parent 070d866 commit 1b0eb72

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

Sources/Swift/Core/Helper/SentryExtraPackages.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22

33
@objc @_spi(Private) public final class SentryExtraPackages: NSObject {
44
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()
66

77
@objc
88
public static func addPackageName(_ name: String?, version: String?) {
@@ -12,28 +12,21 @@ import Foundation
1212

1313
let newPackage = ["name": name, "version": version]
1414

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 {
1816
extraPackages.insert(newPackage)
1917
}
2018
}
2119

2220
@objc
2321
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)
3024
}
31-
return NSMutableSet(set: copy as NSSet)
3225
}
3326

3427
#if SENTRY_TEST || SENTRY_TEST_CI
3528
static func clear() {
36-
syncQueue.async(flags: .barrier) {
29+
lock.synchronized {
3730
extraPackages.removeAll()
3831
}
3932
}

0 commit comments

Comments
 (0)