From 6ef12c5859fecb7f6dbe12a139936c5cfea5a6e4 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sat, 9 Sep 2023 10:30:53 -0500 Subject: [PATCH] :shirt: refactor --- src/main.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index b679290..7427b13 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,15 @@ fn main() -> Result <(), TaskError> Ok (()) } -struct Driver <'a> +struct ThreadSystem <'a> { pool: &'a ThreadPool, send: mpsc::SyncSender , +} + +struct Driver <'a> +{ + thread_sys: ThreadSystem <'a>, recv: mpsc::Receiver , ctl: Controller, @@ -39,10 +44,15 @@ impl <'a> Driver <'_> { let (send, recv) = mpsc::sync_channel (8); - Driver + let thread_sys = ThreadSystem { pool, send, + }; + + Driver + { + thread_sys, recv, ctl: Default::default (), @@ -114,14 +124,15 @@ impl <'a> Driver <'_> let dur_encode = Duration::from_millis (20); let dur_transmit = Duration::from_millis (200); - let send = self.send.clone (); + let pool = &self.thread_sys.pool; + let send = self.thread_sys.send.clone (); match event { TxPipelineEvent::Capture => { let cap = self.capture.start (())?; - self.pool.spawn (move || + pool.spawn (move || { thread::sleep (dur_capture); let buf_raw = BufRaw @@ -151,7 +162,7 @@ impl <'a> Driver <'_> { let mut encoder = self.encoder.start (EncoderTaskMetadata {})?; - self.pool.spawn (move || + pool.spawn (move || { thread::sleep (dur_encode); encoder.try_handle_insert_data (&buf_raw.buf).unwrap (); @@ -160,7 +171,7 @@ impl <'a> Driver <'_> }, TxPipelineEvent::Transmit (_buf_enc) => { let tx = self.transmitter.start (())?; - self.pool.spawn (move || + pool.spawn (move || { thread::sleep (dur_transmit); send.send (TaskOutput::TxTransmit ((tx, false))).unwrap ();