Skip to content

Commit 02d1226

Browse files
committed
Add Absorb::drop_second
1 parent e780497 commit 02d1226

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

evmap/src/write.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,19 @@ where
542542
fn drop_first(self: Box<Self>) {
543543
// since the two copies are exactly equal, we need to make sure that we *don't* call the
544544
// destructors of any of the values that are in our map, as they'll all be called when the
545-
// last read handle goes out of scope. to do so, we first clear w_handle, which won't drop
546-
// any elements since its values are kept as ManuallyDrop:
545+
// last read handle goes out of scope.
547546
//
548547
// Safety: ManuallyDrop<T> has the same layout as T.
549548
let inner =
550549
unsafe { Box::from_raw(Box::into_raw(self) as *mut Inner<K, ManuallyDrop<V>, M, S>) };
551550
drop(inner);
552551
}
552+
553+
fn drop_second(self: Box<Self>) {
554+
// when the second copy is dropped is where we want to _actually_ drop all the values in
555+
// the map. this happens automatically.
556+
drop(self);
557+
}
553558
}
554559

555560
impl<K, V, M, S> Extend<(K, V)> for WriteHandle<K, V, M, S>

left-right/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ pub trait Absorb<O> {
232232
///
233233
/// Defaults to calling `Self::drop`.
234234
fn drop_first(self: Box<Self>) {}
235+
236+
/// Drop the second of the two copies.
237+
///
238+
/// Defaults to calling `Self::drop`.
239+
fn drop_second(self: Box<Self>) {}
235240
}
236241

237242
/// Construct a new write and read handle pair from an empty data structure.

left-right/src/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ where
103103
// this is safe, since we know that no readers are using this pointer
104104
// anymore (due to the .wait() following swapping the pointer with NULL).
105105
//
106-
// safety: w_handle was initially crated from a `Box`, and is no longer aliased.
107-
drop(unsafe { Box::from_raw(r_handle) });
106+
// safety: r_handle was initially crated from a `Box`, and is no longer aliased.
107+
Absorb::drop_second(unsafe { Box::from_raw(r_handle) });
108108
}
109109
}
110110

0 commit comments

Comments
 (0)