mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 20:37:34 +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 Foundation
|
||||||
import FoundationExtras
|
import FoundationExtras
|
||||||
|
import os
|
||||||
|
|
||||||
class DatabaseIDCache: @unchecked Sendable {
|
final class DatabaseIDCache: Sendable {
|
||||||
|
|
||||||
static let shared = DatabaseIDCache()
|
static let shared = DatabaseIDCache()
|
||||||
|
|
||||||
private var databaseIDCache = [String: String]()
|
private let _databaseIDCache = OSAllocatedUnfairLock(initialState: [String: String]())
|
||||||
private let databaseIDCacheLock = NSLock()
|
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.
|
/// Generates — or retrieves from cache — a database-suitable ID based on a String.
|
||||||
func databaseIDWithString(_ s: String) -> String {
|
func databaseIDWithString(_ s: String) -> String {
|
||||||
|
|
||||||
databaseIDCacheLock.lock()
|
|
||||||
defer {
|
|
||||||
databaseIDCacheLock.unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
if let identifier = databaseIDCache[s] {
|
if let identifier = databaseIDCache[s] {
|
||||||
return identifier
|
return identifier
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user