RWLock

public final class RWLock

A read-write thread lock. Permits multiple readers to hold the while, while only allowing at most one writer to hold the lock. For a writer to acquire the lock all readers must have unlocked. For a reader to acquire the lock no writers must hold the lock.

  • Initialize a new read-write lock.

    Declaration

    Swift

    public init()
  • Attempt to acquire the lock for reading. Returns false if an error occurs.

    Declaration

    Swift

    public func readLock() -> Bool
  • Attempts to acquire the lock for reading. Returns false if the lock is held by a writer or an error occurs.

    Declaration

    Swift

    public func tryReadLock() -> Bool
  • Attempt to acquire the lock for writing. Returns false if an error occurs.

    Declaration

    Swift

    public func writeLock() -> Bool
  • Attempt to acquire the lock for writing. Returns false if the lock is held by readers or a writer or an error occurs.

    Declaration

    Swift

    public func tryWriteLock() -> Bool
  • Unlock a lock which is held for either reading or writing. Returns false if an error occurs.

    Declaration

    Swift

    public func unlock() -> Bool
  • Acquire the read lock, execute the closure, release the lock.

    Declaration

    Swift

    public func doWithReadLock(closure: () throws -> ()) rethrows
  • Acquire the write lock, execute the closure, release the lock.

    Declaration

    Swift

    public func doWithWriteLock(closure: () throws -> ()) rethrows