Skip to content

Commit a9ac6e6

Browse files
committed
Optimize some send/sync impls.
1 parent 95578bf commit a9ac6e6

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/lock/api.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use core::ops::{Deref, DerefMut};
1111
// TODO: For weak memory, there needs to be a bit more stricter condition. unlock -hb→ lock.
1212
pub unsafe trait RawLock: Default + Send + Sync {
1313
/// Raw lock's token type.
14+
//
15+
// Send + Sync is needed to make LockGuard Send + Sync.
1416
type Token: Send + Sync;
1517

1618
/// Acquires the raw lock.
@@ -45,7 +47,7 @@ pub struct Lock<L: RawLock, T> {
4547
data: UnsafeCell<T>,
4648
}
4749

48-
unsafe impl<L: RawLock, T: Send> Send for Lock<L, T> {}
50+
// Send is automatically implemented for Lock.
4951
unsafe impl<L: RawLock, T: Send> Sync for Lock<L, T> {}
5052

5153
impl<L: RawLock, T> Lock<L, T> {
@@ -83,15 +85,14 @@ impl<L: RawTryLock, T> Lock<L, T> {
8385
}
8486

8587
/// A guard that holds the lock and dereferences the inner value.
88+
///
89+
/// Send/Sync are is automatically implemented.
8690
#[derive(Debug)]
8791
pub struct LockGuard<'s, L: RawLock, T> {
8892
lock: &'s Lock<L, T>,
8993
token: ManuallyDrop<L::Token>,
9094
}
9195

92-
unsafe impl<L: RawLock, T: Send> Send for LockGuard<'_, L, T> {}
93-
unsafe impl<L: RawLock, T: Sync> Sync for LockGuard<'_, L, T> {}
94-
9596
impl<L: RawLock, T> Drop for LockGuard<'_, L, T> {
9697
fn drop(&mut self) {
9798
// SAFETY: `self.token` is not used anymore in this function, and as we are `drop`ing

0 commit comments

Comments
 (0)