mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-25 00:15:28 +01:00
Make DatabaseIDCache properly Sendable (instead of unchecked) by using an OSAllocatedUnfairLock.
This commit is contained in:
parent
138177858c
commit
ae77aece2a
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user