Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "lockmap"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

authors = ["SF-Zhou <sfzhou.scut@gmail.com>"]
Expand Down
6 changes: 4 additions & 2 deletions src/lockmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K: Eq + Hash + Send, V: Send> Send for Entry<'_, K, V> {}
unsafe impl<K: Eq + Hash + Send + Sync, V: Send + Sync> 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<V>) to be safe to share, not ownership transfer.
unsafe impl<K: Eq + Hash + Sync, V: Sync> Sync for Entry<'_, K, V> {}
Comment thread
SF-Zhou marked this conversation as resolved.

impl<K: Eq + Hash, V> Entry<'_, K, V> {
/// Returns a reference to the entry's key.
Expand Down
6 changes: 4 additions & 2 deletions src/lru_lockmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<K: Eq + Hash + Send, V: Send> Send for LruEntry<'_, K, V> {}
unsafe impl<K: Eq + Hash + Send + Sync, V: Send + Sync> 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<V>) to be safe to share, not ownership transfer.
unsafe impl<K: Eq + Hash + Sync, V: Sync> Sync for LruEntry<'_, K, V> {}
Comment thread
SF-Zhou marked this conversation as resolved.

impl<K: Eq + Hash, V> LruEntry<'_, K, V> {
/// Returns a reference to the entry's key.
Expand Down