Skip to content

Commit

Permalink
Rework remote_drop_collection
Browse files Browse the repository at this point in the history
  • Loading branch information
Finomnis committed Oct 22, 2023
1 parent c93011c commit b666d26
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/utils/remote_drop_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,23 @@ impl<T> Drop for RemoteDrop<T> {
// Important: lock first, then read the offset.
let mut data = data.lock().unwrap();

self.offset.upgrade().map(|offset| {
let offset = offset.load(Ordering::Acquire);
let offset = self
.offset
.upgrade()
.expect("Trying to delete non-existent item! Please report this.")
.load(Ordering::Acquire);

data.pop().map(|last_item| {
if offset != data.len() {
// There must have been at least two items, and we are not at the end.
// So swap first before dropping.
let last_item = data
.pop()
.expect("Trying to delete non-existent item! Please report this.");

last_item.offset.store(offset, Ordering::Release);
data[offset] = last_item;
}
});
});
if offset != data.len() {
// There must have been at least two items, and we are not at the end.
// So swap first before dropping.

last_item.offset.store(offset, Ordering::Release);
data[offset] = last_item;
}
}
}
}
Expand Down

0 comments on commit b666d26

Please sign in to comment.