Skip to content

Commit 39cc955

Browse files
committed
Polish comments.
1 parent 53abc69 commit 39cc955

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/lock/api.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use core::ops::{Deref, DerefMut};
1212
pub unsafe trait RawLock: Default + Send + Sync {
1313
/// Raw lock's token type.
1414
///
15-
/// We don't enforce Send/Sync, as some locks may not satisfy it. We restrict them at
16-
/// Send/Sync impl for [LockGuard].
15+
/// We don't enforce `Send`/`Sync`, as some locks may not satisfy it. We restrict them at
16+
/// `Send`/`Sync` impl for [`LockGuard`].
1717
type Token;
1818

1919
/// Acquires the raw lock.
@@ -23,7 +23,7 @@ pub unsafe trait RawLock: Default + Send + Sync {
2323
///
2424
/// # Safety
2525
///
26-
/// - `self` must be a an acquired lock.
26+
/// - `self` must be an acquired lock.
2727
/// - `token` must be from a [`RawLock::lock`] or [`RawTryLock::try_lock`] call to `self`.
2828
unsafe fn unlock(&self, token: Self::Token);
2929
}
@@ -112,24 +112,28 @@ impl<L: RawLock, T> Drop for LockGuard<'_, L, T> {
112112
// SAFETY: since `self` was created with `lock` and it's `token`, the `token` given to
113113
// `unlock()` is correct.
114114
unsafe { self.lock.inner.unlock(token) };
115+
116+
// Note: Important that nothing is done to `data` after `unlock()`.
115117
}
116118
}
117119

118120
impl<L: RawLock, T> Deref for LockGuard<'_, L, T> {
119121
type Target = T;
120122

121123
fn deref(&self) -> &Self::Target {
122-
// SAFETY: Having a `LockGuard` means the underlying lock is acquired, so the underlying
123-
// data is valid. Hence we can create a shared reference to it.
124+
// SAFETY:
125+
// - Existance of a `LockGuard` means the lock is acquired, so the data is valid.
126+
// - Having a shared reference to the `LockGuard` implies there is no accessor making a
127+
// mutable reference to the data.
124128
unsafe { &*self.lock.data.get() }
125129
}
126130
}
127131

128132
impl<L: RawLock, T> DerefMut for LockGuard<'_, L, T> {
129133
fn deref_mut(&mut self) -> &mut Self::Target {
130-
// SAFETY: Having a `LockGuard` means the underlying lock is acquired, so the underlying
131-
// data is valid. Having a mutable refererence to it implies that we are the only one with
132-
// access to the underlying data. Hence we can create a mutable reference to it.
134+
// SAFETY:
135+
// - Existance of a `LockGuard` means the lock is acquired, so the data is valid.
136+
// - Having a mutable reference to the `LockGuard` implies there is no accessor to data.
133137
unsafe { &mut *self.lock.data.get() }
134138
}
135139
}

0 commit comments

Comments
 (0)