summaryrefslogtreecommitdiff
path: root/src/lock.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lock.rs')
-rw-r--r--src/lock.rs5
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`.