👕 refactor

main
_ 2023-09-09 10:30:53 -05:00
parent 1acd125fdd
commit 6ef12c5859
1 changed files with 17 additions and 6 deletions

View File

@ -20,10 +20,15 @@ fn main() -> Result <(), TaskError>
Ok (()) Ok (())
} }
struct Driver <'a> struct ThreadSystem <'a>
{ {
pool: &'a ThreadPool, pool: &'a ThreadPool,
send: mpsc::SyncSender <TaskOutput>, send: mpsc::SyncSender <TaskOutput>,
}
struct Driver <'a>
{
thread_sys: ThreadSystem <'a>,
recv: mpsc::Receiver <TaskOutput>, recv: mpsc::Receiver <TaskOutput>,
ctl: Controller, ctl: Controller,
@ -39,10 +44,15 @@ impl <'a> Driver <'_>
{ {
let (send, recv) = mpsc::sync_channel (8); let (send, recv) = mpsc::sync_channel (8);
Driver let thread_sys = ThreadSystem
{ {
pool, pool,
send, send,
};
Driver
{
thread_sys,
recv, recv,
ctl: Default::default (), ctl: Default::default (),
@ -114,14 +124,15 @@ impl <'a> Driver <'_>
let dur_encode = Duration::from_millis (20); let dur_encode = Duration::from_millis (20);
let dur_transmit = Duration::from_millis (200); 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 match event
{ {
TxPipelineEvent::Capture => { TxPipelineEvent::Capture => {
let cap = self.capture.start (())?; let cap = self.capture.start (())?;
self.pool.spawn (move || pool.spawn (move ||
{ {
thread::sleep (dur_capture); thread::sleep (dur_capture);
let buf_raw = BufRaw let buf_raw = BufRaw
@ -151,7 +162,7 @@ impl <'a> Driver <'_>
{ {
let mut encoder = self.encoder.start (EncoderTaskMetadata {})?; let mut encoder = self.encoder.start (EncoderTaskMetadata {})?;
self.pool.spawn (move || pool.spawn (move ||
{ {
thread::sleep (dur_encode); thread::sleep (dur_encode);
encoder.try_handle_insert_data (&buf_raw.buf).unwrap (); encoder.try_handle_insert_data (&buf_raw.buf).unwrap ();
@ -160,7 +171,7 @@ impl <'a> Driver <'_>
}, },
TxPipelineEvent::Transmit (_buf_enc) => { TxPipelineEvent::Transmit (_buf_enc) => {
let tx = self.transmitter.start (())?; let tx = self.transmitter.start (())?;
self.pool.spawn (move || pool.spawn (move ||
{ {
thread::sleep (dur_transmit); thread::sleep (dur_transmit);
send.send (TaskOutput::TxTransmit ((tx, false))).unwrap (); send.send (TaskOutput::TxTransmit ((tx, false))).unwrap ();