Skip to content
Open
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
20 changes: 1 addition & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ pub struct Bus<T> {
mpsc::Receiver<(thread::Thread, usize)>,
),

// channel used to communicate to unparker that a given thread should be woken up
unpark: mpsc::Sender<thread::Thread>,

// cache used to keep track of threads waiting for next write.
// this is only here to avoid allocating one on every broadcast()
cache: Vec<(thread::Thread, usize)>,
Expand All @@ -310,7 +307,6 @@ impl<T> fmt::Debug for Bus<T> {
.field("rleft", &self.rleft)
.field("leaving", &self.leaving)
.field("waiting", &self.waiting)
.field("unpark", &self.unpark)
.field("cache", &self.cache)
.finish()
}
Expand Down Expand Up @@ -340,26 +336,12 @@ impl<T> Bus<T> {
let _ = time::Instant::now().elapsed();
}

// we run a separate thread responsible for unparking
// so we don't have to wait for unpark() to return in broadcast_inner
// sending on a channel without contention is cheap, unparking is not
let (unpark_tx, unpark_rx) = mpsc::unbounded::<thread::Thread>();
let _ = thread::Builder::new()
.name("bus_unparking".to_owned())
.spawn(move || {
for t in unpark_rx.iter() {
t.unpark();
}
});

Bus {
state: inner,
readers: 0,
rleft: iter::repeat(0).take(len).collect(),
leaving: mpsc::unbounded(),
waiting: mpsc::unbounded(),
unpark: unpark_tx,

cache: Vec::new(),
}
}
Expand Down Expand Up @@ -479,7 +461,7 @@ impl<T> Bus<T> {
if at == tail {
self.cache.push((t, at))
} else {
self.unpark.send(t).unwrap();
t.unpark();
}
}
for w in self.cache.drain(..) {
Expand Down