keyfork-qrcode: add multithreaded scanner #82
|
@ -244,22 +244,21 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
|
|||
}
|
||||
let mut queue = condvar
|
||||
.wait_while(queue, |queue| {
|
||||
eprintln!("thread {i} received signal");
|
||||
queue.images.is_empty() || queue.shutdown
|
||||
queue.images.is_empty() && !queue.shutdown
|
||||
})
|
||||
.expect(bug::bug!(POISONED_MUTEX));
|
||||
if let Some(image) = queue.images.pop() {
|
||||
eprintln!("thread {i} received image");
|
||||
// drop the queue here since this is what's going to take time
|
||||
drop(queue);
|
||||
if let Some(content) = scanner.scan_image(image) {
|
||||
println!("scanned: {content}");
|
||||
tx.send(content).expect(
|
||||
bug::bug!("A scanned image could not be sent")
|
||||
);
|
||||
eprintln!("scanned: {content}");
|
||||
if tx.send(content).is_err() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
eprintln!("shutting down thread {i}");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -284,7 +283,6 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
|
|||
.expect(bug::bug!(POISONED_MUTEX))
|
||||
.images
|
||||
.push(image);
|
||||
eprintln!("notifying any thread");
|
||||
arced.1.notify_one();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue