Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop memory after releasing the global lock #261

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ impl<Static> Drop for Atom<Static> {

// Out of line to guide inlining.
fn drop_slow<Static>(this: &mut Atom<Static>) {
DYNAMIC_SET
// We temporarily store the string in the stack to drop after releasing the lock
let _removed = DYNAMIC_SET
.lock()
.remove(this.unsafe_data.get() as *mut Entry);
}
Expand Down
9 changes: 4 additions & 5 deletions src/dynamic_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Set {
ptr
}

pub(crate) fn remove(&mut self, ptr: *mut Entry) {
pub(crate) fn remove(&mut self, ptr: *mut Entry) -> Option<Box<Entry>> {
let bucket_index = {
let value: &Entry = unsafe { &*ptr };
debug_assert!(value.ref_count.load(SeqCst) == 0);
Expand All @@ -97,12 +97,11 @@ impl Set {
while let Some(entry_ptr) = current.as_mut() {
let entry_ptr: *mut Entry = &mut **entry_ptr;
if entry_ptr == ptr {
mem::drop(mem::replace(current, unsafe {
(*entry_ptr).next_in_bucket.take()
}));
break;
return mem::replace(current, unsafe { (*entry_ptr).next_in_bucket.take() });
}
current = unsafe { &mut (*entry_ptr).next_in_bucket };
}

None
}
}