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 src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
missing_docs,
missing_debug_implementations,
unreachable_pub,
intra_doc_link_resolution_failure
broken_intra_doc_links
)]
#![warn(rust_2018_idioms)]
#![allow(clippy::cognitive_complexity)]
Expand Down
22 changes: 14 additions & 8 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1815,11 +1815,14 @@ where
let current_value = unsafe { current_value.deref() };

if no_replacement {
// the key is not absent, so don't update
// because of `no_replacement`, we don't use the
// new value, so we need to clean it up
// the key is not absent, so don't update because of
// `no_replacement`, we don't use the new value, so we need to clean
// it up and return it back to the caller
// safety: we own value and did not share it
let _ = unsafe { value.into_owned() };
return PutResult::Exists {
current: current_value,
not_inserted: unsafe { value.into_owned().into_box() },
};
} else {
// update the value in the existing node
let now_garbage = n.value.swap(value, Ordering::SeqCst, guard);
Expand Down Expand Up @@ -1902,11 +1905,14 @@ where
// next epoch, which won't arrive until after we drop our guard.
let current_value = unsafe { current_value.deref() };
if no_replacement {
// the key is not absent, so don't update
// because of `no_replacement`, we don't use the
// new value, so we need to clean it up
// the key is not absent, so don't update because of
// `no_replacement`, we don't use the new value, so we need to clean
// it up and return it back to the caller
// safety: we own value and did not share it
let _ = unsafe { value.into_owned() };
return PutResult::Exists {
current: current_value,
not_inserted: unsafe { value.into_owned().into_box() },
};
} else {
let now_garbage =
tree_node.node.value.swap(value, Ordering::SeqCst, guard);
Expand Down
18 changes: 18 additions & 0 deletions tests/regressions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use flurry::{epoch::pin, *};
use rand::{thread_rng, Rng};

#[test]
fn issue90() {
#[cfg(not(miri))]
const ITERATIONS: usize = 100_000;
#[cfg(miri)]
const ITERATIONS: usize = 100;

let mut rng = thread_rng();
let map = HashMap::new();
let g = pin();
for _ in 0..ITERATIONS {
let el = rng.gen_range(0, 1000);
let _ = map.try_insert(el, el, &g);
}
}