From 26de8d8b9cc154098fb4ebc69b316b3dca3cce38 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 4 Apr 2024 20:44:40 -0700 Subject: [PATCH] Mark ArticleStatus.Key as Sendable. Put the locks in the right places. --- Articles/Sources/Articles/ArticleStatus.swift | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Articles/Sources/Articles/ArticleStatus.swift b/Articles/Sources/Articles/ArticleStatus.swift index a0a8bd696..d8c4cb162 100644 --- a/Articles/Sources/Articles/ArticleStatus.swift +++ b/Articles/Sources/Articles/ArticleStatus.swift @@ -17,7 +17,7 @@ import os /// by an internal lock, which makes `ArticleStatus` thread-safe. public final class ArticleStatus: Hashable, @unchecked Sendable { - public enum Key: String { + public enum Key: String, Sendable { case read = "read" case starred = "starred" } @@ -38,6 +38,14 @@ public final class ArticleStatus: Hashable, @unchecked Sendable { return _read } + set { + Self.lock.lock() + defer { + Self.lock.unlock() + } + + _read = newValue + } } public var starred: Bool { @@ -49,6 +57,14 @@ public final class ArticleStatus: Hashable, @unchecked Sendable { return _starred } + set { + Self.lock.lock() + defer { + Self.lock.unlock() + } + + _starred = newValue + } } private var _read = false @@ -66,6 +82,7 @@ public final class ArticleStatus: Hashable, @unchecked Sendable { } public func boolStatus(forKey key: ArticleStatus.Key) -> Bool { + switch key { case .read: return read @@ -76,11 +93,6 @@ public final class ArticleStatus: Hashable, @unchecked Sendable { public func setBoolStatus(_ status: Bool, forKey key: ArticleStatus.Key) { - Self.lock.lock() - defer { - Self.lock.unlock() - } - switch key { case .read: _read = status