Skip to content

Commit 20707d9

Browse files
committed
Update lock implementations
Vendored from NIO 2.86.0
1 parent 6b0e346 commit 20707d9

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

Sources/AsyncHelpers/Locking+ConditionLock.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
// Vendored from NIO 2.83.0
14+
// Vendored from NIO 2.86.0
1515

1616
//===----------------------------------------------------------------------===//
1717
//
@@ -33,18 +33,25 @@ import Darwin
3333
import ucrt
3434
import WinSDK
3535
#elseif canImport(Glibc)
36-
import Glibc
36+
@preconcurrency import Glibc
3737
#elseif canImport(Musl)
38-
import Musl
38+
@preconcurrency import Musl
39+
#elseif canImport(Bionic)
40+
@preconcurrency import Bionic
41+
#elseif canImport(WASILibc)
42+
@preconcurrency import WASILibc
43+
#if canImport(wasi_pthread)
44+
import wasi_pthread
45+
#endif
3946
#else
4047
#error("The concurrency lock module was unable to identify your C library.")
4148
#endif
4249

43-
/// A `Lock` with a built-in state variable.
44-
///
45-
/// This class provides a convenience addition to `Lock`: it provides the ability to wait
46-
/// until the state variable is set to a specific value to acquire the lock.
4750
extension Locking {
51+
/// A `Lock` with a built-in state variable.
52+
///
53+
/// This class provides a convenience addition to `Lock`: it provides the ability to wait
54+
/// until the state variable is set to a specific value to acquire the lock.
4855
public final class ConditionLock<T: Equatable> {
4956
private var _value: T
5057
private let mutex: FastLock
@@ -170,11 +177,7 @@ extension Locking {
170177
gettimeofday(&curTime, nil)
171178

172179
let allNSecs: Int64 = timeoutNS + Int64(curTime.tv_usec) * 1000
173-
#if canImport(wasi_pthread)
174-
let tvSec = curTime.tv_sec + (allNSecs / nsecPerSec)
175-
#else
176-
let tvSec = curTime.tv_sec + Int((allNSecs / nsecPerSec))
177-
#endif
180+
let tvSec = curTime.tv_sec + time_t((allNSecs / nsecPerSec))
178181

179182
var timeoutAbs = timespec(
180183
tv_sec: tvSec,

Sources/AsyncHelpers/Locking+FastLock.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//
1212
//===----------------------------------------------------------------------===//
1313

14-
// Vendored from NIO 2.83.0
14+
// Vendored from NIO 2.86.0
1515

1616
//===----------------------------------------------------------------------===//
1717
//
@@ -56,7 +56,7 @@ typealias LockPrimitive = pthread_mutex_t
5656
#endif
5757

5858
@usableFromInline
59-
enum LockOperations {}
59+
enum LockOperations: Sendable {}
6060

6161
extension LockOperations {
6262
@inlinable
@@ -200,7 +200,15 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
200200
}
201201
}
202202

203+
// This compiler guard is here becaue `ManagedBuffer` is already declaring
204+
// Sendable unavailability after 6.1, which `LockStorage` inherits.
205+
#if compiler(<6.2)
206+
@available(*, unavailable)
207+
extension LockStorage: Sendable {}
208+
#endif
209+
203210
extension Locking {
211+
204212
/// A threading lock based on `libpthread` instead of `libdispatch`.
205213
///
206214
/// - Note: ``NIOLock`` has reference semantics.

0 commit comments

Comments
 (0)