mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-02 10:22:35 +00:00
Make DatabaseIDCache properly Sendable (instead of unchecked) by using an OSAllocatedUnfairLock.
This commit is contained in:
1 parent
138177858c
commit
ae77aece2a
1 file changed
+11
-8
@@ -8,22 +8,25 @@
|
||||
|
||||
import Foundation
|
||||
import FoundationExtras
|
||||
import os
|
||||
|
||||
class DatabaseIDCache: @unchecked Sendable {
|
||||
final class DatabaseIDCache: Sendable {
|
||||
|
||||
static let shared = DatabaseIDCache()
|
||||
|
||||
private var databaseIDCache = [String: String]()
|
||||
private let databaseIDCacheLock = NSLock()
|
||||
private let _databaseIDCache = OSAllocatedUnfairLock(initialState: [String: String]())
|
||||
private var databaseIDCache: [String: String] {
|
||||
get {
|
||||
_databaseIDCache.withLock { $0 }
|
||||
}
|
||||
set {
|
||||
_databaseIDCache.withLock { $0 = newValue }
|
||||
}
|
||||
}
|
||||
|
||||
/// Generates — or retrieves from cache — a database-suitable ID based on a String.
|
||||
func databaseIDWithString(_ s: String) -> String {
|
||||
|
||||
databaseIDCacheLock.lock()
|
||||
defer {
|
||||
databaseIDCacheLock.unlock()
|
||||
}
|
||||
|
||||
if let identifier = databaseIDCache[s] {
|
||||
return identifier
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user