Crate guardian

source ·
Expand description

Guardian provides owned mutex guards for refcounted mutexes.

Normally, lock guards (be it for Mutex or RwLock) are bound to the lifetime of the borrow of the underlying lock. Specifically, the function signatures all resemble: fn lock<'a>(&'a self) -> Guard<'a>.

If the mutex is refcounted using an Rc or an Arc, it is not necessary for the guard to be scoped in this way – it could instead carry with it a ref to the mutex in question, which allows the guard to be held for as long as is necessary. This is particularly useful for writing iterators where it is advantageous to hold a read lock for the duration of the iteration.

Poisoning

When taking a lock using a guardian, similarly to when taking an RwLock or Mutex, the result may be poisoned on panics. The poison is propagated from that of the underlying lock() method, so for RwLocks, the same rule applies for when a lock may be poisioned.

Structs

  • An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked. Keeps a handle to an Arc so that the lock is not dropped until the guard is.
  • RAII structure used to release the shared read access of a lock when dropped. Keeps a handle to an Arc so that the lock is not dropped until the guard is.
  • RAII structure used to release the exclusive write access of a lock when dropped. Keeps a handle to an Arc so that the lock is not dropped until the guard is.
  • An RAII implementation of a “scoped lock” of a mutex. When this structure is dropped (falls out of scope), the lock will be unlocked. Keeps a handle to an Rc so that the lock is not dropped until the guard is.
  • RAII structure used to release the shared read access of a lock when dropped. Keeps a handle to an Rc so that the lock is not dropped until the guard is.
  • RAII structure used to release the exclusive write access of a lock when dropped. Keeps a handle to an Rc so that the lock is not dropped until the guard is.