Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/span/src/map.rs')
-rw-r--r--crates/span/src/map.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/span/src/map.rs b/crates/span/src/map.rs
index 7faf6f1b1a..f5c083a9f6 100644
--- a/crates/span/src/map.rs
+++ b/crates/span/src/map.rs
@@ -163,7 +163,22 @@ impl Drop for SpanMap {
let (sender, receiver) = std::sync::mpsc::channel::<(SendPtr, fn(SendPtr))>();
std::thread::Builder::new()
.name("SpanMapDropper".to_owned())
- .spawn(move || receiver.iter().for_each(|(b, drop)| drop(b)))
+ .spawn(move || {
+ loop {
+ // block on a receive
+ if let Ok((b, drop)) = receiver.recv() {
+ drop(b);
+ }
+ // then drain the entire channel
+ while let Ok((b, drop)) = receiver.try_recv() {
+ drop(b);
+ }
+ // and sleep for a bit
+ std::thread::sleep(std::time::Duration::from_millis(100));
+ }
+ // why do this over just a `receiver.iter().for_each(drop)`? To reduce contention on the channel lock.
+ // otherwise this thread will constantly wake up and sleep again.
+ })
.unwrap();
sender
})