From f203dbd29e7940b88ecab2e9432e8094e4d4246c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Tue, 10 Jan 2023 17:29:23 +0100 Subject: [PATCH] Respond to USB in parrallel to application processing --- src/lib.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 68bc3d2..a21dd20 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -100,21 +100,24 @@ impl Runner { ); log::info!("Ready for work"); - loop { - thread::sleep(Duration::from_millis(5)); - - #[cfg(feature = "ctaphid")] - apps.with_ctaphid_apps(|apps| ctaphid_dispatch.poll(apps)); - #[cfg(feature = "ccid")] - apps.with_ccid_apps(|apps| apdu_dispatch.poll(apps)); - - usb_device.poll(&mut [ + thread::scope(|s| { + s.spawn(move || loop { + thread::sleep(Duration::from_millis(5)); + usb_device.poll(&mut [ + #[cfg(feature = "ctaphid")] + &mut ctaphid, + #[cfg(feature = "ccid")] + &mut ccid, + ]); + }); + loop { + thread::sleep(Duration::from_millis(5)); #[cfg(feature = "ctaphid")] - &mut ctaphid, + apps.with_ctaphid_apps(|apps| ctaphid_dispatch.poll(apps)); #[cfg(feature = "ccid")] - &mut ccid, - ]); - } + apps.with_ccid_apps(|apps| apdu_dispatch.poll(apps)); + } + }); }) } }