diff --git a/Flow/Locking.swift b/Flow/Locking.swift index 2992889..1896d0e 100644 --- a/Flow/Locking.swift +++ b/Flow/Locking.swift @@ -39,7 +39,6 @@ public final class Mutex { } } -@usableFromInline enum MutexType { case normal case recursive @@ -54,25 +53,25 @@ enum MutexType { internal extension pthread_mutex_t { - @inlinable mutating func initialize(as type: MutexType = .normal) { + @inline(__always) mutating func initialize(as type: MutexType = .normal) { withUnsafeMutablePointer(to: &self) { $0.initialize(as: type) } } - @inlinable mutating func deinitialize() { + @inline(__always) mutating func deinitialize() { withUnsafeMutablePointer(to: &self) { $0.deinitialize() } } - @inlinable mutating func lock() { + @inline(__always) mutating func lock() { withUnsafeMutablePointer(to: &self) { $0.lock() } } - @inlinable mutating func unlock() { + @inline(__always) mutating func unlock() { withUnsafeMutablePointer(to: &self) { $0.unlock() } @@ -85,7 +84,7 @@ typealias PThreadMutex = UnsafeMutablePointer /// Helper methods to work directly with a Pthread mutex pointer to avoid overhead of alloction and reference counting of using the Mutex reference type. /// - Note: You have to explicity call `initialize()` before use (typically in a class init) and `deinitialize()` when done (typically in a class deinit) extension UnsafeMutablePointer where Pointee == pthread_mutex_t { - @usableFromInline + func initialize(as type: MutexType = .normal) { var attr = pthread_mutexattr_t() defer { pthread_mutexattr_destroy(&attr) } @@ -100,23 +99,19 @@ extension UnsafeMutablePointer where Pointee == pthread_mutex_t { } } - @usableFromInline func deinitialize() { pthread_mutex_destroy(self) } /// Attempt to acquire the lock, blocking a thread’s execution until the lock can be acquired. - @usableFromInline func lock() { pthread_mutex_lock(self) } /// Releases a previously acquired lock. - @usableFromInline func unlock() { pthread_mutex_unlock(self) } - } /// Internal helper to help manage state in stateful transforms.