feat: Dispatcher constructor separates render_rx
The dispatcher no longer owns the render results message channel, and instead passes it out as a separate item during construction.
This commit is contained in:
@@ -66,8 +66,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
thread::scope(|s| {
|
thread::scope(|s| {
|
||||||
let mut dispatcher = thread_utils::Dispatcher::new(&small_rng);
|
let (mut dispatcher, mut scanline_receiver) = thread_utils::Dispatcher::new(&small_rng);
|
||||||
let scanline_receiver = dispatcher.render_rx;
|
|
||||||
|
|
||||||
s.spawn(move || {
|
s.spawn(move || {
|
||||||
for y in (0..image.1).rev() {
|
for y in (0..image.1).rev() {
|
||||||
|
|||||||
@@ -30,11 +30,10 @@ pub struct Dispatcher{
|
|||||||
handles: Vec<thread::JoinHandle<()>>,
|
handles: Vec<thread::JoinHandle<()>>,
|
||||||
command_transmitters: Vec<mpsc::SyncSender<RenderCommand>>,
|
command_transmitters: Vec<mpsc::SyncSender<RenderCommand>>,
|
||||||
next_to_feed: usize, // gonna do a round-robin style dispatch, ig.
|
next_to_feed: usize, // gonna do a round-robin style dispatch, ig.
|
||||||
pub render_rx: mpsc::Receiver<RenderResult>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatcher {
|
impl Dispatcher {
|
||||||
pub fn new(srng: &SmallRng) -> Dispatcher {
|
pub fn new(srng: &SmallRng) -> (Dispatcher, mpsc::Receiver<RenderResult> ) {
|
||||||
let mut handles = Vec::new();
|
let mut handles = Vec::new();
|
||||||
let mut command_transmitters = Vec::<mpsc::SyncSender<RenderCommand>>::new();
|
let mut command_transmitters = Vec::<mpsc::SyncSender<RenderCommand>>::new();
|
||||||
|
|
||||||
@@ -67,13 +66,14 @@ impl Dispatcher {
|
|||||||
command_transmitters.push(command_tx);
|
command_transmitters.push(command_tx);
|
||||||
}
|
}
|
||||||
// finally, stash everything in the Dispatcher struct and return.
|
// finally, stash everything in the Dispatcher struct and return.
|
||||||
|
(
|
||||||
Dispatcher{
|
Dispatcher{
|
||||||
handles,
|
handles,
|
||||||
command_transmitters,
|
command_transmitters,
|
||||||
next_to_feed: 0,
|
next_to_feed: 0,
|
||||||
render_rx,
|
},
|
||||||
}
|
render_rx
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Reconsider round-robin dispatch
|
//TODO: Reconsider round-robin dispatch
|
||||||
|
|||||||
Reference in New Issue
Block a user