@@ -11,6 +11,8 @@ use core::ops::{Deref, DerefMut};
11
11
// TODO: For weak memory, there needs to be a bit more stricter condition. unlock -hb→ lock.
12
12
pub unsafe trait RawLock : Default + Send + Sync {
13
13
/// Raw lock's token type.
14
+ //
15
+ // Send + Sync is needed to make LockGuard Send + Sync.
14
16
type Token : Send + Sync ;
15
17
16
18
/// Acquires the raw lock.
@@ -45,7 +47,7 @@ pub struct Lock<L: RawLock, T> {
45
47
data : UnsafeCell < T > ,
46
48
}
47
49
48
- unsafe impl < L : RawLock , T : Send > Send for Lock < L , T > { }
50
+ // Send is automatically implemented for Lock.
49
51
unsafe impl < L : RawLock , T : Send > Sync for Lock < L , T > { }
50
52
51
53
impl < L : RawLock , T > Lock < L , T > {
@@ -83,15 +85,14 @@ impl<L: RawTryLock, T> Lock<L, T> {
83
85
}
84
86
85
87
/// A guard that holds the lock and dereferences the inner value.
88
+ ///
89
+ /// Send/Sync are is automatically implemented.
86
90
#[ derive( Debug ) ]
87
91
pub struct LockGuard < ' s , L : RawLock , T > {
88
92
lock : & ' s Lock < L , T > ,
89
93
token : ManuallyDrop < L :: Token > ,
90
94
}
91
95
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
-
95
96
impl < L : RawLock , T > Drop for LockGuard < ' _ , L , T > {
96
97
fn drop ( & mut self ) {
97
98
// SAFETY: `self.token` is not used anymore in this function, and as we are `drop`ing
0 commit comments