keyfork-qrcode: add debug printing

This commit is contained in:
Ryan Heywood 2025-05-10 13:47:46 -04:00
parent acdf894558
commit 0737ca6907
Signed by: ryan
GPG Key ID: 8E401478A3FBEF72
1 changed files with 8 additions and 2 deletions

View File

@ -213,7 +213,7 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
let arced = Arc::new((Mutex::new(scan_queue), Condvar::new())); let arced = Arc::new((Mutex::new(scan_queue), Condvar::new()));
let (tx, rx) = channel(); let (tx, rx) = channel();
for _ in 0..thread_count { for i in 0..thread_count {
let tx = tx.clone(); let tx = tx.clone();
let arced = arced.clone(); let arced = arced.clone();
@ -244,13 +244,16 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
} }
let mut queue = condvar let mut queue = condvar
.wait_while(queue, |queue| { .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)); .expect(bug::bug!(POISONED_MUTEX));
if let Some(image) = queue.images.pop() { 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 the queue here since this is what's going to take time
drop(queue); drop(queue);
if let Some(content) = scanner.scan_image(image) { if let Some(content) = scanner.scan_image(image) {
println!("scanned: {content}");
tx.send(content).expect( tx.send(content).expect(
bug::bug!("A scanned image could not be sent") bug::bug!("A scanned image could not be sent")
); );
@ -263,6 +266,7 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
while Instant::now().duration_since(start) < timeout { while Instant::now().duration_since(start) < timeout {
if let Ok(content) = rx.try_recv() { if let Ok(content) = rx.try_recv() {
arced.0.lock().expect(bug::bug!(POISONED_MUTEX)).shutdown = true; arced.0.lock().expect(bug::bug!(POISONED_MUTEX)).shutdown = true;
eprintln!("shutting down threads (good)");
arced.1.notify_all(); arced.1.notify_all();
return Ok(Some(content)); return Ok(Some(content));
} }
@ -280,12 +284,14 @@ pub fn scan_camera(timeout: Duration, index: usize) -> Result<Option<String>, QR
.expect(bug::bug!(POISONED_MUTEX)) .expect(bug::bug!(POISONED_MUTEX))
.images .images
.push(image); .push(image);
eprintln!("notifying any thread");
arced.1.notify_one(); arced.1.notify_one();
} }
// dbg_elapsed(count, start); dbg_elapsed(count, start);
arced.0.lock().expect(bug::bug!(POISONED_MUTEX)).shutdown = true; arced.0.lock().expect(bug::bug!(POISONED_MUTEX)).shutdown = true;
eprintln!("shutting down threads (bad)");
arced.1.notify_all(); arced.1.notify_all();
Ok(None) Ok(None)