Remove the public class

This commit is contained in:
Guoye Zhang committed 2024-10-23 12:21:05 -07:00
1 parent 6b3c3a26b7
commit 4ba4e72b06
1 file changed
-68
-68
View File
@@ -195,74 +195,6 @@ final class LockStorage<Value>: ManagedBuffer<Value, LockPrimitive> {
extension LockStorage: @unchecked Sendable {}
/// A threading lock based on `libpthread` instead of `libdispatch`.
///
/// - note: ``NIOLock`` has reference semantics.
///
/// This object provides a lock on top of a single `pthread_mutex_t`. This kind
/// of lock is safe to use with `libpthread`-based threading models, such as the
/// one used by NIO. On Windows, the lock is based on the substantially similar
/// `SRWLOCK` type.
public struct NIOLock {
@usableFromInline
internal let _storage: LockStorage<Void>
/// Create a new lock.
@inlinable
public init() {
self._storage = .create(value: ())
}
/// Acquire the lock.
///
/// Whenever possible, consider using `withLock` instead of this method and
/// `unlock`, to simplify lock handling.
@inlinable
public func lock() {
self._storage.lock()
}
/// Release the lock.
///
/// Whenever possible, consider using `withLock` instead of this method and
/// `lock`, to simplify lock handling.
@inlinable
public func unlock() {
self._storage.unlock()
}
@inlinable
internal func withLockPrimitive<T>(_ body: (UnsafeMutablePointer<LockPrimitive>) throws -> T) rethrows -> T {
try self._storage.withLockPrimitive(body)
}
}
extension NIOLock {
/// Acquire the lock for the duration of the given block.
///
/// This convenience method should be preferred to `lock` and `unlock` in
/// most situations, as it ensures that the lock will be released regardless
/// of how `body` exits.
///
/// - Parameter body: The block to execute while holding the lock.
/// - Returns: The value returned by the block.
@inlinable
public func withLock<T>(_ body: () throws -> T) rethrows -> T {
self.lock()
defer {
self.unlock()
}
return try body()
}
@inlinable
public func withLockVoid(_ body: () throws -> Void) rethrows {
try self.withLock(body)
}
}
extension NIOLock: Sendable {}
extension UnsafeMutablePointer {
@inlinable
func assertValidAlignment() {