From a207f3411e74dbc2e9aa27d49920ef76ddff74e5 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Wed, 21 Oct 2026 19:08:32 -0700 Subject: [PATCH] Switch from OSAllocatedUnfairLock to Mutex. --- Modules/Articles/Sources/Articles/ArticleStatus.swift | 6 +++--- Modules/Articles/Sources/Articles/AuthorCache.swift | 4 ++-- .../Sources/ArticlesDatabase/ArticlesTable.swift | 3 ++- .../Sources/ArticlesDatabase/StatusesTable.swift | 3 ++- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Modules/Articles/Sources/Articles/ArticleStatus.swift b/Modules/Articles/Sources/Articles/ArticleStatus.swift index 5e664a8bc..0bcc10aae 100644 --- a/Modules/Articles/Sources/Articles/ArticleStatus.swift +++ b/Modules/Articles/Sources/Articles/ArticleStatus.swift @@ -7,7 +7,7 @@ // import Foundation -import os +import Synchronization public final class ArticleStatus: Hashable, Sendable { @@ -27,7 +27,7 @@ public final class ArticleStatus: Hashable, Sendable { var starred: Bool } - private let state: OSAllocatedUnfairLock + private let state: Mutex public var read: Bool { get { @@ -49,7 +49,7 @@ public final class ArticleStatus: Hashable, Sendable { public init(articleID: String, read: Bool, starred: Bool, dateArrived: Date) { self.articleID = articleID - self.state = OSAllocatedUnfairLock(initialState: State(read: read, starred: starred)) + self.state = Mutex(State(read: read, starred: starred)) self.dateArrived = dateArrived } diff --git a/Modules/Articles/Sources/Articles/AuthorCache.swift b/Modules/Articles/Sources/Articles/AuthorCache.swift index 1db82143e..323ed267a 100644 --- a/Modules/Articles/Sources/Articles/AuthorCache.swift +++ b/Modules/Articles/Sources/Articles/AuthorCache.swift @@ -6,7 +6,7 @@ // import Foundation -import os +import Synchronization import RSCore /// Caches `Author` values by `authorID` so articles by the same author share @@ -15,7 +15,7 @@ public final class AuthorCache: Sendable { public static let shared = AuthorCache() - private let cache = OSAllocatedUnfairLock<[String: Author]>(initialState: [:]) + private let cache = Mutex<[String: Author]>([:]) init() { if !Platform.isRunningUnitTests { diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift index 961d53444..555430122 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift @@ -12,6 +12,7 @@ import RSCore import RSDatabase import RSDatabaseObjC import RSParser +import Synchronization import Articles final class ArticlesTable: DatabaseTable, Sendable { @@ -22,7 +23,7 @@ final class ArticlesTable: DatabaseTable, Sendable { private let statusesTable: StatusesTable private let searchTable: SearchTable private let retentionStyle: ArticlesDatabase.RetentionStyle - private let articlesCache = OSAllocatedUnfairLock(initialState: [String: Article]()) + private let articlesCache = Mutex([String: Article]()) private static let logger = Logger(subsystem: Logger.nnwSubsystem, category: "ArticlesTable") private static let signposter = OSSignposter(subsystem: Logger.nnwSubsystem, category: .pointsOfInterest) diff --git a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift index 47afcede1..937676e39 100644 --- a/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift +++ b/Modules/ArticlesDatabase/Sources/ArticlesDatabase/StatusesTable.swift @@ -11,6 +11,7 @@ import os import RSCore import RSDatabase import RSDatabaseObjC +import Synchronization import Articles // Article->ArticleStatus is a to-one relationship. @@ -325,7 +326,7 @@ private final class StatusCache: Sendable { var dictionary = [String: ArticleStatus]() } - private let state = OSAllocatedUnfairLock(initialState: State()) + private let state = Mutex(State()) func addStatusIfNotCached(_ status: ArticleStatus) { addIfNotCached(Set([status]))