diff options
Diffstat (limited to 'alacritty_terminal/src/sync.rs')
-rw-r--r-- | alacritty_terminal/src/sync.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/alacritty_terminal/src/sync.rs b/alacritty_terminal/src/sync.rs index 43148a78..848bab62 100644 --- a/alacritty_terminal/src/sync.rs +++ b/alacritty_terminal/src/sync.rs @@ -21,6 +21,14 @@ impl<T> FairMutex<T> { FairMutex { data: Mutex::new(data), next: Mutex::new(()) } } + /// Acquire a lease to reserve the mutex lock. + /// + /// This will prevent others from acquiring a terminal lock, but block if anyone else is + /// already holding a lease. + pub fn lease(&self) -> MutexGuard<'_, ()> { + self.next.lock() + } + /// Lock the mutex. pub fn lock(&self) -> MutexGuard<'_, T> { // Must bind to a temporary or the lock will be freed before going @@ -28,4 +36,14 @@ impl<T> FairMutex<T> { let _next = self.next.lock(); self.data.lock() } + + /// Unfairly lock the mutex. + pub fn lock_unfair(&self) -> MutexGuard<'_, T> { + self.data.lock() + } + + /// Unfairly try to lock the mutex. + pub fn try_lock_unfair(&self) -> Option<MutexGuard<'_, T>> { + self.data.try_lock() + } } |