From 0da1713cb6fef2553e868cb2f62c937febda83de Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 10 Nov 2025 22:27:56 -0800 Subject: [PATCH] Use Mutex. --- .../Sources/Articles/ArticleStatus.swift | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Modules/Articles/Sources/Articles/ArticleStatus.swift b/Modules/Articles/Sources/Articles/ArticleStatus.swift index 8d7deb5e0..a736f29ee 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 nonisolated public final class ArticleStatus: Hashable, Sendable { @@ -19,31 +19,34 @@ nonisolated public final class ArticleStatus: Hashable, Sendable { public let articleID: String public let dateArrived: Date - private let _read: OSAllocatedUnfairLock - private let _starred: OSAllocatedUnfairLock + private struct State: Sendable { + var read: Bool + var starred: Bool + } + + private let state: Mutex public var read: Bool { get { - _read.withLock { $0 } + state.withLock { $0.read } } set { - _read.withLock { $0 = newValue } + state.withLock { $0.read = newValue } } } public var starred: Bool { get { - _starred.withLock { $0 } + state.withLock { $0.starred } } set { - _starred.withLock { $0 = newValue } + state.withLock { $0.starred = newValue } } } public init(articleID: String, read: Bool, starred: Bool, dateArrived: Date) { self.articleID = articleID - self._read = OSAllocatedUnfairLock(initialState: read) - self._starred = OSAllocatedUnfairLock(initialState: starred) + self.state = Mutex(State(read: read, starred: starred)) self.dateArrived = dateArrived }