diff --git a/Cargo.toml b/Cargo.toml index 3d19ce0..70db905 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "lockmap" -version = "0.2.0" +version = "0.2.1" edition = "2021" authors = ["SF-Zhou "] diff --git a/src/lockmap.rs b/src/lockmap.rs index 6442717..acf73b6 100644 --- a/src/lockmap.rs +++ b/src/lockmap.rs @@ -699,8 +699,10 @@ pub struct Entry<'a, K: Eq + Hash, V> { } // SAFETY: The guard holds a per-key mutex lock and a valid, ref-counted pointer. -unsafe impl Send for Entry<'_, K, V> {} -unsafe impl Sync for Entry<'_, K, V> {} +// Entry is intentionally !Send — like MutexGuard, it should not be moved across threads. +// For Sync, only K: Sync and V: Sync are needed: sharing &Entry across threads only +// requires shared references (&K, &Option) to be safe to share, not ownership transfer. +unsafe impl Sync for Entry<'_, K, V> {} impl Entry<'_, K, V> { /// Returns a reference to the entry's key. diff --git a/src/lru_lockmap.rs b/src/lru_lockmap.rs index a95a7c4..ddf6c94 100644 --- a/src/lru_lockmap.rs +++ b/src/lru_lockmap.rs @@ -809,8 +809,10 @@ pub struct LruEntry<'a, K: Eq + Hash, V> { } // SAFETY: The guard holds a per-key mutex lock and a valid, ref-counted pointer. -unsafe impl Send for LruEntry<'_, K, V> {} -unsafe impl Sync for LruEntry<'_, K, V> {} +// LruEntry is intentionally !Send — like MutexGuard, it should not be moved across threads. +// For Sync, only K: Sync and V: Sync are needed: sharing &LruEntry across threads only +// requires shared references (&K, &Option) to be safe to share, not ownership transfer. +unsafe impl Sync for LruEntry<'_, K, V> {} impl LruEntry<'_, K, V> { /// Returns a reference to the entry's key.