From a9ac6e62f1d0e73378490ccfa6aa436d39d5cdce Mon Sep 17 00:00:00 2001 From: Janggun Lee Date: Wed, 23 Oct 2024 20:23:55 +0900 Subject: [PATCH] Optimize some send/sync impls. --- src/lock/api.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lock/api.rs b/src/lock/api.rs index e48be61b5a..1bc66a3b60 100644 --- a/src/lock/api.rs +++ b/src/lock/api.rs @@ -11,6 +11,8 @@ use core::ops::{Deref, DerefMut}; // TODO: For weak memory, there needs to be a bit more stricter condition. unlock -hb→ lock. pub unsafe trait RawLock: Default + Send + Sync { /// Raw lock's token type. + // + // Send + Sync is needed to make LockGuard Send + Sync. type Token: Send + Sync; /// Acquires the raw lock. @@ -45,7 +47,7 @@ pub struct Lock { data: UnsafeCell, } -unsafe impl Send for Lock {} +// Send is automatically implemented for Lock. unsafe impl Sync for Lock {} impl Lock { @@ -83,15 +85,14 @@ impl Lock { } /// A guard that holds the lock and dereferences the inner value. +/// +/// Send/Sync are is automatically implemented. #[derive(Debug)] pub struct LockGuard<'s, L: RawLock, T> { lock: &'s Lock, token: ManuallyDrop, } -unsafe impl Send for LockGuard<'_, L, T> {} -unsafe impl Sync for LockGuard<'_, L, T> {} - impl Drop for LockGuard<'_, L, T> { fn drop(&mut self) { // SAFETY: `self.token` is not used anymore in this function, and as we are `drop`ing