Skip to content

Commit e5f2d50

Browse files
committed
Fix some Swift 6 concurrency issues in SWBUtil
1 parent ed66ddc commit e5f2d50

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

Sources/SWBUtil/AsyncLock.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public actor ActorLock {
1818
public init() {
1919
}
2020

21-
public func withLock<T: Sendable, E>(_ body: @Sendable () async throws(E) -> T) async throws(E) -> T {
21+
public func withLock<T: Sendable, E>(_ body: sending () async throws(E) -> T) async throws(E) -> T {
2222
while busy {
2323
await withCheckedContinuation { cc in
2424
queue.append(cc)
@@ -47,7 +47,7 @@ public final class AsyncLockedValue<Wrapped: Sendable> {
4747
}
4848

4949
@discardableResult @inlinable
50-
public func withLock<Result: Sendable, E>(_ block: @Sendable (inout Wrapped) async throws(E) -> Result) async throws(E) -> Result {
50+
public func withLock<Result: Sendable, E>(_ block: sending (inout Wrapped) async throws(E) -> Result) async throws(E) -> Result {
5151
return try await lock.withLock { () throws(E) -> Result in try await block(&value) }
5252
}
5353
}

Sources/SWBUtil/HeavyCache.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public func withHeavyCacheGlobalState<T>(isolated: Bool = true, _ body: () throw
6060
/// A cache designed for holding few, relatively heavy-weight objects.
6161
///
6262
/// This cache is specifically designed for holding a limited number of objects (usually less than 100) which are expensive enough to merit particular attention in terms of being purgeable under memory pressure, evictable in-mass, or cached with more complex parameters like time-to-live (TTL).
63-
public final class HeavyCache<Key: Hashable, Value>: _HeavyCacheBase, KeyValueStorage, @unchecked Sendable {
63+
public final class HeavyCache<Key: Hashable & Sendable, Value>: _HeavyCacheBase, KeyValueStorage, @unchecked Sendable {
6464
public typealias HeavyCacheClock = SuspendingClock
6565

6666
/// Controls the non-deterministic eviction policy of the cache. Note that this is distinct from deterministic _pruning_ (due to TTL or size limits).
@@ -86,7 +86,7 @@ public final class HeavyCache<Key: Hashable, Value>: _HeavyCacheBase, KeyValueSt
8686
}
8787

8888
/// The lock to protect shared instance state.
89-
private let stateLock = Lock()
89+
private let stateLock = SWBMutex(())
9090

9191
/// The underlying cache.
9292
private let _cache: any HeavyCacheImpl<Key, Entry>

Sources/SWBUtil/InterningArena.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public typealias FrozenStringArena = FrozenInterningArena<String>
1818
private let numberOfInternCalls = Statistic("InterningArena.numberOfInternCalls", "Number of calls to 'InterningArena.intern'")
1919
private let numberOfItemsInterned = Statistic("InterningArena.numberOfItemsInterned", "Number of items interned in InterningArenas")
2020

21-
public final class InterningArena<T: Hashable> {
21+
public final class InterningArena<T: Hashable & Sendable> {
2222
public struct Handle: Hashable, Sendable {
2323
fileprivate let value: UInt32
2424

Sources/SWBUtil/Lock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension LockedValue where Value: ~Copyable {
110110
extension LockedValue: @unchecked Sendable where Value: ~Copyable {
111111
}
112112

113-
extension LockedValue {
113+
extension LockedValue where Value: Sendable {
114114
/// Sets the value of the wrapped value to `newValue` and returns the original value.
115115
public func exchange(_ newValue: Value) -> Value {
116116
withLock {

Sources/SWBUtil/Statistics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public final class Statistic: @unchecked Sendable, _StatisticBackend {
115115
}
116116
}
117117

118-
public protocol _StatisticBackend {
118+
public protocol _StatisticBackend: Sendable {
119119
var name: String { get }
120120
var value: Int { get }
121121
func increment(_ n: Int)

0 commit comments

Comments
 (0)