diff options
| author | Botahamec <botahamec@outlook.com> | 2022-11-18 22:51:18 -0500 |
|---|---|---|
| committer | Botahamec <botahamec@outlook.com> | 2022-11-18 22:51:18 -0500 |
| commit | 50f7c15e00c5c55604e0cda82cba577588b25360 (patch) | |
| tree | 0ae5d1ccd991847d634ad3796548c460e372ace3 /src/lock.rs | |
| parent | 8b93bb61b67d15df207ed677d7906f27b3e5876e (diff) | |
Implemented LockGuard
Diffstat (limited to 'src/lock.rs')
| -rw-r--r-- | src/lock.rs | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/lock.rs b/src/lock.rs index 101a061..a8662d0 100644 --- a/src/lock.rs +++ b/src/lock.rs @@ -17,7 +17,7 @@ pub struct Key<'a> { impl<'a> Key<'a> { /// Create a key to a lock. - const fn new(lock: &'a Lock) -> Self { + const unsafe fn new(lock: &'a Lock) -> Self { Self { lock } } } @@ -52,7 +52,8 @@ impl Lock { /// This is not a fair lock. It is not recommended to call this function /// repeatedly in a loop. pub fn try_lock(&self) -> Option<Key> { - (!self.is_locked.fetch_or(true, Ordering::Acquire)).then_some(Key::new(self)) + // safety: we just acquired the lock + (!self.is_locked.fetch_or(true, Ordering::Acquire)).then_some(unsafe { Key::new(self) }) } /// Forcibly unlocks the `Lock`. |
