Skip to content

Commit

Permalink
Remove the public class
Browse files Browse the repository at this point in the history
  • Loading branch information
guoye-zhang committed Oct 23, 2024
1 parent 6b3c3a2 commit 4ba4e72
Showing 1 changed file with 0 additions and 68 deletions.
68 changes: 0 additions & 68 deletions Sources/HTTPTypes/NIOLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4ba4e72

Please sign in to comment.