Skip to content
Snippets Groups Projects
Commit ca65b83d authored by Federico Lolli's avatar Federico Lolli
Browse files

Fixed some timing and release issues

parent a9c86a97
Branches
Tags
No related merge requests found
...@@ -3,7 +3,7 @@ use std::{ ...@@ -3,7 +3,7 @@ use std::{
ops::Deref, ops::Deref,
sync::Arc, sync::Arc,
thread::{self, JoinHandle}, thread::{self, JoinHandle},
time::{Duration, Instant}, time::Duration,
}; };
use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender}; use crossbeam_channel::{unbounded, Receiver, RecvTimeoutError, Sender};
...@@ -67,9 +67,13 @@ impl SerialManager { ...@@ -67,9 +67,13 @@ impl SerialManager {
let mut buf = vec![0; n]; let mut buf = vec![0; n];
// implement a read exact to allow better error messages // implement a read exact to allow better error messages
let mut filled = 0; let mut filled = 0;
let timeout = Instant::now() + port.read_timeout;
while filled < n { while filled < n {
match port.reader_ch.as_ref().unwrap().recv_deadline(timeout) { match port
.reader_ch
.as_ref()
.unwrap()
.recv_timeout(port.read_timeout)
{
Ok(b) => { Ok(b) => {
buf[filled] = b; buf[filled] = b;
filled += 1; filled += 1;
...@@ -125,7 +129,8 @@ impl SerialQueue { ...@@ -125,7 +129,8 @@ impl SerialQueue {
let ser = Arc::clone(&serial); let ser = Arc::clone(&serial);
handles.push(thread::spawn(move || { handles.push(thread::spawn(move || {
while let Ok(data) = wrx.recv() { while let Ok(data) = wrx.recv() {
ser.lock().as_mut().unwrap().write_all(&data).unwrap(); data.chunks(256)
.for_each(|chunk| ser.lock().as_mut().unwrap().write_all(chunk).unwrap());
} }
})); }));
...@@ -133,7 +138,7 @@ impl SerialQueue { ...@@ -133,7 +138,7 @@ impl SerialQueue {
let (rtx, rrx) = unbounded::<u8>(); let (rtx, rrx) = unbounded::<u8>();
let ser = Arc::clone(&serial); let ser = Arc::clone(&serial);
handles.push(thread::spawn(move || { handles.push(thread::spawn(move || {
let mut buf = [0; 1024]; let mut buf = [0; 256];
loop { loop {
match ser.lock().as_mut().map(|p| p.read(&mut buf)) { match ser.lock().as_mut().map(|p| p.read(&mut buf)) {
Some(Ok(n)) => { Some(Ok(n)) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment