Compare commits
1 Commits
ryansquare
...
main
Author | SHA1 | Date |
---|---|---|
|
c6e274c4da |
|
@ -215,7 +215,7 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
|
|||
let arced = Arc::new((Mutex::new(scan_queue), Condvar::new()));
|
||||
let (tx, rx) = channel();
|
||||
|
||||
for i in 0..thread_count {
|
||||
for _ in 0..thread_count {
|
||||
let tx = tx.clone();
|
||||
let arced = arced.clone();
|
||||
|
||||
|
@ -253,21 +253,18 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
|
|||
// drop the queue here since this is what's going to take time
|
||||
drop(queue);
|
||||
if let Some(content) = scanner.scan_image(image) {
|
||||
eprintln!("scanned: {content}");
|
||||
if tx.send(content).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
eprintln!("shutting down thread {i}");
|
||||
});
|
||||
}
|
||||
|
||||
while Instant::now().duration_since(start) < timeout {
|
||||
if let Ok(content) = rx.try_recv() {
|
||||
arced.0.lock().expect(bug::bug!(POISONED_MUTEX)).shutdown = true;
|
||||
eprintln!("shutting down threads (good)");
|
||||
arced.1.notify_all();
|
||||
return Ok(Some(content));
|
||||
}
|
||||
|
@ -288,10 +285,9 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
|
|||
arced.1.notify_one();
|
||||
}
|
||||
|
||||
dbg_elapsed(count, start);
|
||||
// dbg_elapsed(count, start);
|
||||
|
||||
arced.0.lock().expect(bug::bug!(POISONED_MUTEX)).shutdown = true;
|
||||
eprintln!("shutting down threads (bad)");
|
||||
arced.1.notify_all();
|
||||
|
||||
Ok(None)
|
||||
|
|
Loading…
Reference in New Issue