Skip to content

Commit 00fab1c

Browse files
committed
Fix Sendability warnings
1 parent d067b0e commit 00fab1c

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

Sources/CoreMetrics/Locks.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import Musl
4646
/// of lock is safe to use with `libpthread`-based threading models, such as the
4747
/// one used by NIO. On Windows, the lock is based on the substantially similar
4848
/// `SRWLOCK` type.
49-
internal final class Lock {
49+
internal final class Lock: Sendable {
5050
#if os(Windows)
5151
fileprivate let mutex: UnsafeMutablePointer<SRWLOCK> =
5252
UnsafeMutablePointer.allocate(capacity: 1)

Sources/CoreMetrics/Metrics.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,11 @@ internal final class AccumulatingRoundingFloatingPointCounter: FloatingPointCoun
797797
}
798798

799799
/// Wraps a RecorderHandler, adding support for incrementing values by storing an accumulated value and recording increments to the underlying CounterHandler after crossing integer boundaries.
800-
internal final class AccumulatingMeter: MeterHandler {
800+
/// - Note: we can annotate this class as `@unchecked Sendable` because we are manually gating access to mutable state (i.e., the `value` property) via a Lock.
801+
internal final class AccumulatingMeter: MeterHandler, @unchecked Sendable {
801802
private let recorderHandler: RecorderHandler
802-
// FIXME: use atomics when available
803-
private var value: Double = 0
803+
// FIXME: use swift-atomics when floating point support is available
804+
private var value: Double = 0
804805
private let lock = Lock()
805806

806807
init(label: String, dimensions: [(String, String)]) {

Sources/Metrics/Metrics.swift

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ extension Timer {
7171
self.recordSeconds(value)
7272
case .never:
7373
self.record(0)
74+
@unknown default:
75+
self.record(0)
7476
}
7577
}
7678
}

Tests/MetricsTests/MetricsTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ extension DispatchTimeInterval {
196196
return value * 1_000_000_000
197197
case .never:
198198
return 0
199+
@unknown default:
200+
return 0
199201
}
200202
}
201203
}

0 commit comments

Comments
 (0)