From 474b086b4da58485ed8c10268509d2b45f5225b2 Mon Sep 17 00:00:00 2001 From: Andrew Straw Date: Mon, 30 Dec 2024 20:09:53 +0100 Subject: [PATCH] remove use of parking_lot crate --- Cargo.toml | 1 - braid-http-session/Cargo.toml | 1 - braid-http-session/src/lib.rs | 3 +- braid/braid-run/Cargo.toml | 3 - braid/braid-run/src/callback_handling.rs | 14 +- braid/braid-run/src/mainbrain.rs | 63 +++++---- .../src/multicam_http_session_handler.rs | 16 ++- bui-backend-session/Cargo.toml | 1 - bui-backend-session/src/lib.rs | 7 +- camera/ci2-async/Cargo.toml | 1 - camera/ci2-async/src/lib.rs | 91 +++++++------ camera/ci2-pyloncxx/Cargo.toml | 1 - camera/ci2-pyloncxx/src/lib.rs | 108 +++++++-------- camera/ci2-vimba/Cargo.toml | 1 - camera/ci2-vimba/src/lib.rs | 89 +++++++++---- flydra2/Cargo.toml | 1 - flydra2/src/connected_camera_manager.rs | 54 ++++---- flytrax-csv-to-braidz/Cargo.toml | 2 - http-video-streaming/Cargo.toml | 1 - http-video-streaming/src/lib.rs | 8 +- led-box-standalone/Cargo.toml | 1 - led-box-standalone/src/app.rs | 8 +- led-box-standalone/src/box_status.rs | 11 +- led-box-standalone/src/main.rs | 4 +- strand-cam/Cargo.toml | 1 - strand-cam/src/flydratrax_handle_msg.rs | 7 +- strand-cam/src/frame_process_task.rs | 51 +++---- strand-cam/src/strand-cam.rs | 125 +++++++++--------- 28 files changed, 354 insertions(+), 320 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b5a30517e..b3fd9f5c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -204,7 +204,6 @@ obj = { version = "0.10", features = ["genmesh"] } opencv-ros-camera = { version = "0.15.1", features = ["serde-serialize"] } openh264 = "0.6.0" ordered-float = { version = "3.4", features = ["serde"] } -parking_lot = "0.12" parry2d-f64 = "0.17" parry3d-f64 = "0.17" pin-project = "1.0.11" diff --git a/braid-http-session/Cargo.toml b/braid-http-session/Cargo.toml index e73d9826e..17e6036ae 100644 --- a/braid-http-session/Cargo.toml +++ b/braid-http-session/Cargo.toml @@ -18,4 +18,3 @@ http-body-util.workspace = true bytes = "1.5.0" axum.workspace = true cookie_store.workspace = true -parking_lot = "0.12.1" diff --git a/braid-http-session/src/lib.rs b/braid-http-session/src/lib.rs index 68d9bedf2..d5abcd7eb 100644 --- a/braid-http-session/src/lib.rs +++ b/braid-http-session/src/lib.rs @@ -1,6 +1,5 @@ use bui_backend_session::HttpSession; -use parking_lot::RwLock; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; use tracing::{debug, error}; #[derive(thiserror::Error, Debug)] diff --git a/braid/braid-run/Cargo.toml b/braid/braid-run/Cargo.toml index 64611d1af..a64afd2ce 100644 --- a/braid/braid-run/Cargo.toml +++ b/braid/braid-run/Cargo.toml @@ -14,7 +14,6 @@ build-util.workspace = true configure.workspace = true thiserror.workspace = true eyre.workspace = true -parking_lot.workspace = true serde.workspace = true serde_json.workspace = true toml.workspace = true @@ -75,8 +74,6 @@ strand-cam-storetype.workspace = true [features] default = ["bundle_files"] -deadlock_detection = ["parking_lot/deadlock_detection"] - # BUI frontend. must pick one of the following two: bundle_files = ["flydra2/bundle_files", "tower-serve-static", "include_dir"] serve_files = ["flydra2/serve_files"] diff --git a/braid/braid-run/src/callback_handling.rs b/braid/braid-run/src/callback_handling.rs index 65baea723..2042adf90 100644 --- a/braid/braid-run/src/callback_handling.rs +++ b/braid/braid-run/src/callback_handling.rs @@ -9,7 +9,7 @@ use rust_cam_bui_types::RecordingPath; use crate::mainbrain::*; fn start_saving_mp4s_all_cams(app_state: &BraidAppState, start_saving: bool) { - let mut tracker = app_state.shared_store.write(); + let mut tracker = app_state.shared_store.write().unwrap(); tracker.modify(|store| { if start_saving { store.fake_mp4_recording_path = Some(RecordingPath::new("".to_string())); @@ -43,7 +43,7 @@ pub(crate) async fn callback_handler( ) .map_err(|msg| (StatusCode::BAD_REQUEST, msg))?; - let mut current_cam_data = app_state.per_cam_data_arc.write(); + let mut current_cam_data = app_state.per_cam_data_arc.write().unwrap(); if current_cam_data .insert( cam_info.raw_cam_name.clone(), @@ -64,21 +64,21 @@ pub(crate) async fn callback_handler( "got new image for camera \"{}\"", image_info.raw_cam_name.as_str() ); - let mut current_cam_data = app_state.per_cam_data_arc.write(); + let mut current_cam_data = app_state.per_cam_data_arc.write().unwrap(); current_cam_data .get_mut(&image_info.raw_cam_name) .unwrap() .current_image_png = image_info.inner.current_image_png; } UpdateCamSettings(cam_settings) => { - let mut current_cam_data = app_state.per_cam_data_arc.write(); + let mut current_cam_data = app_state.per_cam_data_arc.write().unwrap(); current_cam_data .get_mut(&cam_settings.raw_cam_name) .unwrap() .cam_settings_data = Some(cam_settings.inner); } UpdateFeatureDetectSettings(feature_detect_settings) => { - let mut current_cam_data = app_state.per_cam_data_arc.write(); + let mut current_cam_data = app_state.per_cam_data_arc.write().unwrap(); current_cam_data .get_mut(&feature_detect_settings.raw_cam_name) .unwrap() @@ -137,7 +137,7 @@ pub(crate) async fn callback_handler( })?; { - let mut tracker = app_state.shared_store.write(); + let mut tracker = app_state.shared_store.write().unwrap(); tracker.modify(|store| { store.post_trigger_buffer_size = val; }); @@ -147,7 +147,7 @@ pub(crate) async fn callback_handler( debug!("got PostTriggerMp4Recording"); let is_saving = { - let tracker = app_state.shared_store.read(); + let tracker = app_state.shared_store.read().unwrap(); (*tracker).as_ref().fake_mp4_recording_path.is_some() }; diff --git a/braid/braid-run/src/mainbrain.rs b/braid/braid-run/src/mainbrain.rs index cae1a9f1c..0ad731d9d 100644 --- a/braid/braid-run/src/mainbrain.rs +++ b/braid/braid-run/src/mainbrain.rs @@ -4,7 +4,7 @@ use std::{ path::PathBuf, sync::{ atomic::{AtomicBool, Ordering}, - Arc, + Arc, RwLock, }, }; @@ -15,7 +15,6 @@ use axum::{ }; use futures::StreamExt; use http::{HeaderValue, StatusCode}; -use parking_lot::RwLock; use preferences_serde1::{AppInfo, Preferences}; use serde::Serialize; use tokio::net::UdpSocket; @@ -33,7 +32,7 @@ use flydra_types::{ }; use rust_cam_bui_types::{ClockModel, RecordingPath}; -use eyre::{self, WrapErr, Result}; +use eyre::{self, Result, WrapErr}; use crate::multicam_http_session_handler::{MaybeSession, StrandCamHttpSessionHandler}; @@ -60,25 +59,19 @@ pub(crate) enum MainbrainError { HyperError { #[from] source: hyper::Error, - }, #[error("{source}")] BuiBackendSessionError { #[from] source: bui_backend_session::Error, - }, #[error("{source}")] PreferencesError { #[from] source: preferences_serde1::PreferencesError, - }, #[error("unknown camera \"{cam_name}\"")] - UnknownCamera { - cam_name: RawCamName, - - }, + UnknownCamera { cam_name: RawCamName }, } pub(crate) type MainbrainResult = std::result::Result; @@ -108,7 +101,7 @@ async fn events_handler( ) -> impl axum::response::IntoResponse { session_key.is_present(); let key = { - let mut next_connection_id = app_state.next_connection_id.write(); + let mut next_connection_id = app_state.next_connection_id.write().unwrap(); let key = *next_connection_id; *next_connection_id += 1; key @@ -117,7 +110,7 @@ async fn events_handler( // Send an initial copy of our state. { - let current_state = app_state.shared_store.read().as_ref().clone(); + let current_state = app_state.shared_store.read().unwrap().as_ref().clone(); let frame_string = to_event_frame(¤t_state); match tx .send(Ok(http_body::Frame::data(frame_string.into()))) @@ -169,7 +162,13 @@ async fn remote_camera_info_handler( if let Some(config) = cam_cfg { let software_limit_framerate = app_state.software_limit_framerate.clone(); - let trig_config = app_state.shared_store.read().as_ref().trigger_type.clone(); + let trig_config = app_state + .shared_store + .read() + .unwrap() + .as_ref() + .trigger_type + .clone(); let msg = flydra_types::RemoteCameraInfoResponse { camdata_udp_port: app_state.lowlatency_camdata_udp_addr.port(), @@ -399,7 +398,7 @@ struct SendConnectedCamToBuiBackend { impl flydra2::ConnectedCamCallback for SendConnectedCamToBuiBackend { fn on_cam_changed(&self, new_cam_list: Vec) { - let mut tracker = self.shared_store.write(); + let mut tracker = self.shared_store.write().unwrap(); tracker.modify(|shared| shared.connected_cameras = new_cam_list.clone()); } } @@ -570,7 +569,7 @@ pub(crate) async fn do_run_forever( cookie_store::CookieStore::new(None) } }; - let jar = Arc::new(parking_lot::RwLock::new(jar.clone())); + let jar = Arc::new(RwLock::new(jar.clone())); let strand_cam_http_session_handler = StrandCamHttpSessionHandler::new(cam_manager.clone(), jar); @@ -824,11 +823,11 @@ pub(crate) async fn do_run_forever( }); let cm = tm.clone(); { - let mut guard = time_model_arc.write(); + let mut guard = time_model_arc.write().unwrap(); *guard = tm; } { - let mut tracker_guard = tracker.write(); + let mut tracker_guard = tracker.write().unwrap(); tracker_guard.modify(|shared| shared.clock_model = cm.clone()); } let strand_cam_http_session_handler2 = strand_cam_http_session_handler.clone(); @@ -887,7 +886,7 @@ pub(crate) async fn do_run_forever( tx.send(Cmd::StartPulses).await?; { - let mut expected_framerate = expected_framerate_arc.write(); + let mut expected_framerate = expected_framerate_arc.write().unwrap(); *expected_framerate = Some(rate_actual as f32); } @@ -921,7 +920,7 @@ pub(crate) async fn do_run_forever( signal_triggerbox_connected.store(true, Ordering::SeqCst); - let mut expected_framerate = expected_framerate_arc.write(); + let mut expected_framerate = expected_framerate_arc.write().unwrap(); *expected_framerate = Some(*framerate as f32); let gain = 1.0 / framerate; @@ -941,7 +940,7 @@ pub(crate) async fn do_run_forever( if let Some(periodic_signal_period_usec) = ptpcfg.periodic_signal_period_usec { let framerate = 1e6 / periodic_signal_period_usec; - let mut expected_framerate = expected_framerate_arc.write(); + let mut expected_framerate = expected_framerate_arc.write().unwrap(); *expected_framerate = Some(framerate as f32); } } @@ -1006,7 +1005,7 @@ pub(crate) async fn do_run_forever( info!("All cameras done synchronizing."); // Send message to listeners. - let mut tracker = shared_store.write(); + let mut tracker = shared_store.write().unwrap(); tracker.modify(|shared| shared.all_expected_cameras_are_synced = true); break; } @@ -1108,7 +1107,7 @@ pub(crate) async fn do_run_forever( Some(synced_frame) => { let trigger_timestamp = match &trigger_cfg { TriggerType::TriggerboxV1(_) | TriggerType::FakeSync(_) => { - let time_model = time_model_arc.read(); + let time_model = time_model_arc.read().unwrap(); compute_trigger_timestamp(&time_model, synced_frame) } TriggerType::PtpSync(_) => { @@ -1172,11 +1171,11 @@ pub(crate) async fn do_run_forever( tokio::spawn(flydra2::new_model_server(data_rx, model_pose_server_addr)); { - let mut tracker = tracker2.write(); + let mut tracker = tracker2.write().unwrap(); tracker.modify(|shared| shared.model_server_addr = Some(model_pose_server_addr)) } - let expected_framerate: Option = *expected_framerate_arc9.read(); + let expected_framerate: Option = *expected_framerate_arc9.read().unwrap(); info!("expected_framerate: {:?}", expected_framerate); coord_processor.add_listener(data_tx); @@ -1255,7 +1254,7 @@ impl LiveStatsCollector { fn register_new_frame_data(&self, name: &RawCamName, n_points: usize) { let to_send = { // scope for lock on self.collected - let mut collected = self.collected.write(); + let mut collected = self.collected.write().unwrap(); let entry = collected .entry(name.clone()) .or_insert_with(LiveStatsAccum::new); @@ -1269,7 +1268,7 @@ impl LiveStatsCollector { }; if let Some((name, recent_stats)) = to_send { // scope for shared scope - let mut tracker = self.shared.write(); + let mut tracker = self.shared.write().unwrap(); tracker.modify(|shared| { for cc in shared.connected_cameras.iter_mut() { if cc.name == name { @@ -1294,14 +1293,14 @@ pub(crate) async fn toggle_saving_csv_tables( shared_data: SharedStore, ) { if start_saving { - let expected_framerate: Option = *expected_framerate_arc.read(); + let expected_framerate: Option = *expected_framerate_arc.read().unwrap(); let local: chrono::DateTime = chrono::Local::now(); let dirname = local.format("%Y%m%d_%H%M%S.braid").to_string(); let mut my_dir = output_base_dirname.clone(); my_dir.push(dirname); let per_cam_data = { // small scope for read lock - let per_cam_data_ref = per_cam_data_arc.read(); + let per_cam_data_ref = per_cam_data_arc.read().unwrap(); (*per_cam_data_ref).clone() }; let cfg = flydra2::StartSavingCsvConfig { @@ -1326,7 +1325,7 @@ pub(crate) async fn toggle_saving_csv_tables( } { - let mut tracker = shared_data.write(); + let mut tracker = shared_data.write().unwrap(); tracker.modify(|store| { store.csv_tables_dirname = Some(RecordingPath::new(my_dir.display().to_string())); }); @@ -1344,7 +1343,7 @@ pub(crate) async fn toggle_saving_csv_tables( } { - let mut tracker = shared_data.write(); + let mut tracker = shared_data.write().unwrap(); tracker.modify(|store| { store.csv_tables_dirname = None; }); @@ -1363,7 +1362,7 @@ async fn synchronize_cameras( // This time must be prior to actually resetting sync data. { - let mut sync_pulse_pause_started = sync_pulse_pause_started_arc.write(); + let mut sync_pulse_pause_started = sync_pulse_pause_started_arc.write().unwrap(); *sync_pulse_pause_started = Some(std::time::Instant::now()); } @@ -1371,7 +1370,7 @@ async fn synchronize_cameras( cam_manager.reset_sync_data(); { - let mut guard = time_model_arc.write(); + let mut guard = time_model_arc.write().unwrap(); *guard = None; } diff --git a/braid/braid-run/src/multicam_http_session_handler.rs b/braid/braid-run/src/multicam_http_session_handler.rs index 2781e91db..67668341d 100644 --- a/braid/braid-run/src/multicam_http_session_handler.rs +++ b/braid/braid-run/src/multicam_http_session_handler.rs @@ -1,6 +1,8 @@ -use parking_lot::RwLock; use preferences_serde1::Preferences; -use std::{collections::BTreeMap, sync::Arc}; +use std::{ + collections::BTreeMap, + sync::{Arc, RwLock}, +}; use tracing::{debug, error, info, warn}; use bui_backend_session::HttpSession; @@ -61,7 +63,7 @@ impl StrandCamHttpSessionHandler { bui_backend_session::create_session(&bui_server_addr_info, self.jar.clone()).await; let session = match result { Ok(session) => { - let mut name_to_session = self.name_to_session.write(); + let mut name_to_session = self.name_to_session.write().unwrap(); let session = MaybeSession::Alive(session); name_to_session.insert(cam_name.clone(), session.clone()); session @@ -77,7 +79,7 @@ impl StrandCamHttpSessionHandler { }; { // We have the cookie from braid now, so store it to disk. - let jar = self.jar.read(); + let jar = self.jar.read().unwrap(); Preferences::save( &*jar, &crate::mainbrain::APP_INFO, @@ -96,7 +98,7 @@ impl StrandCamHttpSessionHandler { cam_name: &RawCamName, ) -> Result { // Get session if it already exists. - let opt_session = { self.name_to_session.read().get(cam_name).cloned() }; + let opt_session = { self.name_to_session.read().unwrap().get(cam_name).cloned() }; // Create session if needed. match opt_session { @@ -132,7 +134,7 @@ impl StrandCamHttpSessionHandler { "For \"{}\": StrandCamHttpSessionHandler::post() got error {err:?}", cam_name.as_str(), ); - let mut name_to_session = self.name_to_session.write(); + let mut name_to_session = self.name_to_session.write().unwrap(); name_to_session.insert(cam_name.clone(), MaybeSession::Errored); // return Err(MainbrainError::blarg); } @@ -167,7 +169,7 @@ impl StrandCamHttpSessionHandler { let cam_result = self.post(cam_name, args).await; // If we are telling the camera to quit, we don't want to keep its session around - let mut name_to_session = self.name_to_session.write(); + let mut name_to_session = self.name_to_session.write().unwrap(); name_to_session.remove(cam_name); self.cam_manager.remove(cam_name); // TODO: we should cancel the stream of incoming frames so that they diff --git a/bui-backend-session/Cargo.toml b/bui-backend-session/Cargo.toml index 0203fca5b..87aa5e87b 100644 --- a/bui-backend-session/Cargo.toml +++ b/bui-backend-session/Cargo.toml @@ -9,7 +9,6 @@ rust-version = "1.76" tracing.workspace = true futures.workspace = true hyper.workspace = true -parking_lot.workspace = true http.workspace = true bytes.workspace = true serde.workspace = true diff --git a/bui-backend-session/src/lib.rs b/bui-backend-session/src/lib.rs index 8e02661d1..a671aec1a 100644 --- a/bui-backend-session/src/lib.rs +++ b/bui-backend-session/src/lib.rs @@ -1,7 +1,6 @@ use bui_backend_session_types::AccessToken; use http::{header::ACCEPT, HeaderValue}; -use parking_lot::RwLock; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; use thiserror::Error; const SET_COOKIE: &str = "set-cookie"; @@ -156,7 +155,7 @@ impl HttpSession { tracing::trace!("building request"); let url = url::Url::parse(req.uri().to_string().as_ref()).unwrap(); { - let jar = self.jar.read(); + let jar = self.jar.read().unwrap(); for (cookie_name, cookie_value) in jar.get_request_values(&url) { let cookie = cookie_store::RawCookie::new(cookie_name, cookie_value); tracing::trace!("adding cookie {}", cookie); @@ -203,7 +202,7 @@ fn handle_response( match response.headers_mut().entry(SET_COOKIE) { Occupied(e) => { let (_key, drain) = e.remove_entry_mult(); - let mut jar = jar2.write(); + let mut jar = jar2.write().unwrap(); jar.store_response_cookies( drain.map(|cookie_raw| { cookie_store::RawCookie::parse(cookie_raw.to_str().unwrap().to_string()) diff --git a/camera/ci2-async/Cargo.toml b/camera/ci2-async/Cargo.toml index 07888f21c..320c214bf 100644 --- a/camera/ci2-async/Cargo.toml +++ b/camera/ci2-async/Cargo.toml @@ -8,7 +8,6 @@ rust-version = "1.76" [dependencies] futures = "0.3" tracing.workspace = true -parking_lot.workspace = true thread-control = "0.1.2" ci2 = { path = "../ci2" } diff --git a/camera/ci2-async/src/lib.rs b/camera/ci2-async/src/lib.rs index c08b3596c..8748cebc5 100644 --- a/camera/ci2-async/src/lib.rs +++ b/camera/ci2-async/src/lib.rs @@ -31,8 +31,7 @@ use basic_frame::DynamicFrame; use machine_vision_formats as formats; use ci2::Result; -use parking_lot::Mutex; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; pub enum FrameResult { Frame(DynamicFrame), @@ -110,7 +109,7 @@ where // We need to release and re-acquire the lock every cycle to // allow other threads the chance to grab the lock. { - let mut cam = cam_arc.lock(); + let mut cam = cam_arc.lock().unwrap(); let msg = match cam.next_frame() { Ok(frame) => FrameResult::Frame(frame), Err(ci2::Error::SingleFrameError(s)) => FrameResult::SingleFrameError(s), @@ -223,198 +222,198 @@ where // ----- start: weakly typed but easier to implement API ----- // fn feature_access_query(&self, name: &str) -> ci2::Result { - // let c = self.camera.lock(); + // let c = self.camera.lock().unwrap(); // c.feature_access_query(name) // } fn command_execute(&self, name: &str, verify: bool) -> ci2::Result<()> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.command_execute(name, verify) } fn feature_bool(&self, name: &str) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_bool(name) } fn feature_bool_set(&self, name: &str, value: bool) -> ci2::Result<()> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_bool_set(name, value) } fn feature_enum(&self, name: &str) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum(name) } fn feature_enum_set(&self, name: &str, value: &str) -> ci2::Result<()> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum_set(name, value) } fn feature_float(&self, name: &str) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_float(name) } fn feature_float_set(&self, name: &str, value: f64) -> ci2::Result<()> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_float_set(name, value) } fn feature_int(&self, name: &str) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_int(name) } fn feature_int_set(&self, name: &str, value: i64) -> ci2::Result<()> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_int_set(name, value) } // ----- end: weakly typed but easier to implement API ----- fn node_map_load(&self, settings: &str) -> Result<()> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.node_map_load(settings) } fn node_map_save(&self) -> Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.node_map_save() } fn width(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.width() } fn height(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.height() } fn pixel_format(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.pixel_format() } fn possible_pixel_formats(&self) -> ci2::Result> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.possible_pixel_formats() } fn set_pixel_format(&mut self, pixel_format: formats::PixFmt) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_pixel_format(pixel_format) } fn exposure_time(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.exposure_time() } fn exposure_time_range(&self) -> ci2::Result<(f64, f64)> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.exposure_time_range() } fn set_exposure_time(&mut self, value: f64) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_exposure_time(value) } fn gain(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.gain() } fn gain_range(&self) -> ci2::Result<(f64, f64)> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.gain_range() } fn set_gain(&mut self, value: f64) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_gain(value) } fn exposure_auto(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.exposure_auto() } fn set_exposure_auto(&mut self, value: ci2::AutoMode) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_exposure_auto(value) } fn gain_auto(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.gain_auto() } fn set_gain_auto(&mut self, value: ci2::AutoMode) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_gain_auto(value) } fn start_default_external_triggering(&mut self) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.start_default_external_triggering() } fn set_software_frame_rate_limit(&mut self, fps_limit: f64) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_software_frame_rate_limit(fps_limit) } fn trigger_mode(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.trigger_mode() } fn set_trigger_mode(&mut self, value: ci2::TriggerMode) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_trigger_mode(value) } fn acquisition_frame_rate_enable(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.acquisition_frame_rate_enable() } fn set_acquisition_frame_rate_enable(&mut self, value: bool) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_acquisition_frame_rate_enable(value) } fn acquisition_frame_rate(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.acquisition_frame_rate() } fn acquisition_frame_rate_range(&self) -> ci2::Result<(f64, f64)> { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.acquisition_frame_rate_range() } fn set_acquisition_frame_rate(&mut self, value: f64) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_acquisition_frame_rate(value) } fn trigger_selector(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.trigger_selector() } fn set_trigger_selector(&mut self, value: ci2::TriggerSelector) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_trigger_selector(value) } fn acquisition_mode(&self) -> ci2::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.acquisition_mode() } fn set_acquisition_mode(&mut self, value: ci2::AcquisitionMode) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.set_acquisition_mode(value) } fn acquisition_start(&mut self) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.acquisition_start() } fn acquisition_stop(&mut self) -> ci2::Result<()> { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.acquisition_stop() } /// blocks forever. fn next_frame(&mut self) -> ci2::Result { - let mut c = self.camera.lock(); + let mut c = self.camera.lock().unwrap(); c.next_frame() } } diff --git a/camera/ci2-pyloncxx/Cargo.toml b/camera/ci2-pyloncxx/Cargo.toml index 6054b8926..61845db4b 100644 --- a/camera/ci2-pyloncxx/Cargo.toml +++ b/camera/ci2-pyloncxx/Cargo.toml @@ -12,7 +12,6 @@ tracing.workspace = true thiserror.workspace = true anyhow.workspace = true chrono.workspace = true -parking_lot.workspace = true lazy_static.workspace = true ci2 = { path = "../ci2" } diff --git a/camera/ci2-pyloncxx/src/lib.rs b/camera/ci2-pyloncxx/src/lib.rs index 631361f54..e57a12201 100644 --- a/camera/ci2-pyloncxx/src/lib.rs +++ b/camera/ci2-pyloncxx/src/lib.rs @@ -2,8 +2,7 @@ extern crate machine_vision_formats as formats; use anyhow::Context; use chrono::{DateTime, Utc}; -use parking_lot::Mutex; -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use basic_frame::DynamicFrame; use ci2::{AcquisitionMode, AutoMode, TriggerMode, TriggerSelector}; @@ -34,19 +33,14 @@ pub enum Error { PylonError { #[from] source: pylon_cxx::PylonError, - }, #[error("int parse error: {source}")] IntParseError { #[from] source: std::num::ParseIntError, - }, #[error("other error: {msg}")] - OtherError { - msg: String, - - }, + OtherError { msg: String }, } impl From for ci2::Error { @@ -446,7 +440,6 @@ impl<'a> WrappedCamera<'a> { } Err(Error::OtherError { msg: format!("requested camera '{}' was not found", name), - } .into()) } @@ -491,7 +484,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { // } fn command_execute(&self, name: &str, verify: bool) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -502,7 +495,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_bool(&self, name: &str) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -513,7 +506,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_bool_set(&self, name: &str, value: bool) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -524,7 +517,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_enum(&self, name: &str) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let node = camera .node_map() .map_pylon_err()? @@ -534,18 +527,18 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_enum_set(&self, name: &str, value: &str) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let mut node = camera .node_map() .map_pylon_err()? .enum_node(name) .map_pylon_err()?; - node.set_value_pfs(&mut self.pfs_cache.lock(), value) + node.set_value_pfs(&mut self.pfs_cache.lock().unwrap(), value) .map_pylon_err() } fn feature_float(&self, name: &str) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -556,7 +549,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_float_set(&self, name: &str, value: f64) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -567,7 +560,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_int(&self, name: &str) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -578,7 +571,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn feature_int_set(&self, name: &str, value: i64) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -596,7 +589,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { // LF line endings. So here we convert line endings to LF only. let settings_lf_only = settings.lines().collect::>().join("\n"); - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? @@ -609,7 +602,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { // Ideally we would simply call camera.node_map().map_pylon_err()?.save_to_string() here, // but this requires stopping the camera. Instead we cache the node // values. - Ok(self.pfs_cache.lock().to_header_string()) + Ok(self.pfs_cache.lock().unwrap().to_header_string()) } /// Return the sensor width in pixels @@ -617,6 +610,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { Ok(self .inner .lock() + .unwrap() .node_map() .map_pylon_err()? .integer_node("Width") @@ -630,6 +624,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { Ok(self .inner .lock() + .unwrap() .node_map() .map_pylon_err()? .integer_node("Height") @@ -641,7 +636,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { // Settings: PixFmt ---------------------------- fn pixel_format(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let pixel_format_node = camera .node_map() .map_pylon_err()? @@ -650,7 +645,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { convert_to_pixel_format(pixel_format_node.value().map_pylon_err()?.as_ref()) } fn possible_pixel_formats(&self) -> ci2::Result> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let pixel_format_node = camera .node_map() .map_pylon_err()? @@ -673,14 +668,14 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } fn set_pixel_format(&mut self, pixel_format: formats::PixFmt) -> ci2::Result<()> { let s = convert_pixel_format(pixel_format)?; - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let mut pixel_format_node = camera .node_map() .map_pylon_err()? .enum_node("PixelFormat") .map_pylon_err()?; pixel_format_node - .set_value_pfs(&mut self.pfs_cache.lock(), s) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), s) .map_pylon_err() } @@ -688,7 +683,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { /// value given in microseconds fn exposure_time(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let name = self.exposure_time_param_name(); if self.is_sfnc2 { camera @@ -712,7 +707,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { /// value given in microseconds fn exposure_time_range(&self) -> ci2::Result<(f64, f64)> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let name = self.exposure_time_param_name(); if self.is_sfnc2 { let node = camera @@ -736,7 +731,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { /// value given in microseconds fn set_exposure_time(&mut self, value: f64) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let name = self.exposure_time_param_name(); if self.is_sfnc2 { camera @@ -744,7 +739,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { .map_pylon_err()? .float_node(name) .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), value) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), value) .map_pylon_err() } else { camera @@ -752,14 +747,14 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { .map_pylon_err()? .integer_node(name) .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), value.round() as i64) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), value.round() as i64) .map_pylon_err() } } // Settings: Exposure Time Auto Mode ---------------------------- fn exposure_auto(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let val = camera .node_map() .map_pylon_err()? @@ -773,18 +768,19 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { let sval = mode_to_str(value); self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .enum_node("ExposureAuto") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), sval) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), sval) .map_pylon_err() } // Settings: Gain ---------------------------- /// value given in dB fn gain(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); if self.is_sfnc2 { camera .node_map() @@ -809,7 +805,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { } /// value given in dB fn gain_range(&self) -> ci2::Result<(f64, f64)> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); if self.is_sfnc2 { let gain_node = camera .node_map() @@ -838,14 +834,14 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { /// value given in dB fn set_gain(&mut self, gain_db: f64) -> ci2::Result<()> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); if self.is_sfnc2 { camera .node_map() .map_pylon_err()? .float_node("Gain") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), gain_db) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), gain_db) .map_pylon_err()?; } else { let gain_raw = gain_db_to_raw(gain_db)?; @@ -854,7 +850,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { .map_pylon_err()? .integer_node("GainRaw") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), gain_raw) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), gain_raw) .map_pylon_err()?; } Ok(()) @@ -862,7 +858,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { // Settings: Gain Auto Mode ---------------------------- fn gain_auto(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let val = camera .node_map() .map_pylon_err()? @@ -877,17 +873,18 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { let sval = mode_to_str(value); self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .enum_node("GainAuto") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), sval) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), sval) .map_pylon_err() } // Settings: TriggerMode ---------------------------- fn trigger_mode(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let val = camera .node_map() .map_pylon_err()? @@ -911,11 +908,12 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { }; self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .enum_node("TriggerMode") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), sval) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), sval) .map_pylon_err() } @@ -923,6 +921,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { fn acquisition_frame_rate_enable(&self) -> ci2::Result { self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .boolean_node("AcquisitionFrameRateEnable") @@ -933,17 +932,18 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { fn set_acquisition_frame_rate_enable(&mut self, value: bool) -> ci2::Result<()> { self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .boolean_node("AcquisitionFrameRateEnable") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), value) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), value) .map_pylon_err() } // Settings: AcquisitionFrameRate ---------------------------- fn acquisition_frame_rate(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let node = camera .node_map() .map_pylon_err()? @@ -952,7 +952,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { node.value().map_pylon_err() } fn acquisition_frame_rate_range(&self) -> ci2::Result<(f64, f64)> { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let node = camera .node_map() .map_pylon_err()? @@ -963,17 +963,18 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { fn set_acquisition_frame_rate(&mut self, value: f64) -> ci2::Result<()> { self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .float_node(self.acquisition_frame_rate_name()) .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), value) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), value) .map_pylon_err() } // Settings: TriggerSelector ---------------------------- fn trigger_selector(&self) -> ci2::Result { - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); let val = camera .node_map() .map_pylon_err()? @@ -1005,13 +1006,13 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { ))); } }; - let camera = self.inner.lock(); + let camera = self.inner.lock().unwrap(); camera .node_map() .map_pylon_err()? .enum_node("TriggerSelector") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), sval) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), sval) .map_pylon_err() } @@ -1020,6 +1021,7 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { let mode = self .inner .lock() + .unwrap() .node_map() .map_pylon_err()? .enum_node("AcquisitionMode") @@ -1046,11 +1048,12 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { }; self.inner .lock() + .unwrap() .node_map() .map_pylon_err()? .enum_node("AcquisitionMode") .map_pylon_err()? - .set_value_pfs(&mut self.pfs_cache.lock(), sval) + .set_value_pfs(&mut self.pfs_cache.lock().unwrap(), sval) .map_pylon_err() } @@ -1058,12 +1061,13 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { fn acquisition_start(&mut self) -> ci2::Result<()> { self.inner .lock() + .unwrap() .start_grabbing(&pylon_cxx::GrabOptions::default()) .map_pylon_err()?; Ok(()) } fn acquisition_stop(&mut self) -> ci2::Result<()> { - self.inner.lock().stop_grabbing().map_pylon_err()?; + self.inner.lock().unwrap().stop_grabbing().map_pylon_err()?; Ok(()) } @@ -1071,8 +1075,8 @@ impl<'a> ci2::Camera for WrappedCamera<'a> { fn next_frame(&mut self) -> ci2::Result { let pixel_format = self.pixel_format()?; - let mut gr = self.grab_result.lock(); - let cam = self.inner.lock(); + let mut gr = self.grab_result.lock().unwrap(); + let cam = self.inner.lock().unwrap(); // Wait for an image and then retrieve it. A timeout of 99999 ms is used. cam.retrieve_result(99999, &mut gr, pylon_cxx::TimeoutHandling::ThrowException) diff --git a/camera/ci2-vimba/Cargo.toml b/camera/ci2-vimba/Cargo.toml index e3cadfd4b..ccfc41cb8 100644 --- a/camera/ci2-vimba/Cargo.toml +++ b/camera/ci2-vimba/Cargo.toml @@ -13,7 +13,6 @@ thiserror.workspace = true anyhow.workspace = true machine-vision-formats.workspace = true chrono.workspace = true -parking_lot = "0.12.1" lazy_static.workspace = true tempfile.workspace = true diff --git a/camera/ci2-vimba/src/lib.rs b/camera/ci2-vimba/src/lib.rs index 9aaa62f06..8cced77ec 100644 --- a/camera/ci2-vimba/src/lib.rs +++ b/camera/ci2-vimba/src/lib.rs @@ -1,12 +1,11 @@ -use tracing::{error, warn}; -use parking_lot::Mutex; use std::{ convert::TryInto, sync::{ atomic::{AtomicBool, Ordering}, - Arc, + Arc, Mutex, }, }; +use tracing::{error, warn}; use chrono::{DateTime, Utc}; use lazy_static::lazy_static; @@ -150,7 +149,7 @@ fn callback_rust( let tx = { // In this scope, we keep the lock on the SENDERS mutex. - let vec_senders = &mut *SENDERS.lock(); + let vec_senders = &mut *SENDERS.lock().unwrap(); if let Some(idx) = vec_senders .iter() .position(|x| x.handle.inner == camera_handle) @@ -305,7 +304,7 @@ impl<'a> ci2::CameraModule for &'a WrappedModule { let rx = { // In this scope, we keep the lock on the SENDERS mutex. - let vec_senders = &mut *SENDERS.lock(); + let vec_senders = &mut *SENDERS.lock().unwrap(); let (tx, rx) = std::sync::mpsc::sync_channel(N_CHANNEL_FRAMES); let sender = FrameSender { handle: CamHandle { @@ -414,7 +413,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { // fn feature_access_query(&self, name: &str) -> ci2::Result { // let (is_readable, is_writeable) = self // .camera - // .lock() + // .lock().unwrap() // .feature_access_query(name) // .map_vimba_err()?; // Ok(ci2::AccessQueryResult { @@ -424,16 +423,25 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { // } fn command_execute(&self, name: &str, _verify: bool) -> ci2::Result<()> { - self.camera.lock().command_run(name).map_vimba_err() + self.camera + .lock() + .unwrap() + .command_run(name) + .map_vimba_err() } fn feature_bool(&self, name: &str) -> ci2::Result { - self.camera.lock().feature_boolean(name).map_vimba_err() + self.camera + .lock() + .unwrap() + .feature_boolean(name) + .map_vimba_err() } fn feature_bool_set(&self, name: &str, value: bool) -> ci2::Result<()> { self.camera .lock() + .unwrap() .feature_boolean_set(name, value) .map_vimba_err() } @@ -441,6 +449,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { fn feature_enum(&self, name: &str) -> ci2::Result { self.camera .lock() + .unwrap() .feature_enum(name) .map_vimba_err() .map(Into::into) @@ -449,28 +458,39 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { fn feature_enum_set(&self, name: &str, value: &str) -> ci2::Result<()> { self.camera .lock() + .unwrap() .feature_enum_set(name, value) .map_vimba_err() } fn feature_float(&self, name: &str) -> ci2::Result { - self.camera.lock().feature_float(name).map_vimba_err() + self.camera + .lock() + .unwrap() + .feature_float(name) + .map_vimba_err() } fn feature_float_set(&self, name: &str, value: f64) -> ci2::Result<()> { self.camera .lock() + .unwrap() .feature_float_set(name, value) .map_vimba_err() } fn feature_int(&self, name: &str) -> ci2::Result { - self.camera.lock().feature_int(name).map_vimba_err() + self.camera + .lock() + .unwrap() + .feature_int(name) + .map_vimba_err() } fn feature_int_set(&self, name: &str, value: i64) -> ci2::Result<()> { self.camera .lock() + .unwrap() .feature_int_set(name, value) .map_vimba_err() } @@ -495,6 +515,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { let settings_settings = vimba::default_feature_persist_settings(); // let's get meta. settings to load the settings. self.camera .lock() + .unwrap() .camera_settings_load(&settings_path, &settings_settings) .map_vimba_err() @@ -510,6 +531,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { let settings_settings = vimba::default_feature_persist_settings(); // let's get meta. settings to save the settings. self.camera .lock() + .unwrap() .camera_settings_save(&settings_path, &settings_settings) .map_vimba_err()?; @@ -522,6 +544,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { Ok(self .camera .lock() + .unwrap() .feature_int("Width") .map_vimba_err()? .try_into()?) @@ -530,17 +553,19 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { Ok(self .camera .lock() + .unwrap() .feature_int("Height") .map_vimba_err()? .try_into()?) } fn pixel_format(&self) -> std::result::Result { - self.camera.lock().pixel_format().map_vimba_err() + self.camera.lock().unwrap().pixel_format().map_vimba_err() } fn possible_pixel_formats(&self) -> std::result::Result, ci2::Error> { let fmts = self .camera .lock() + .unwrap() .feature_enum_range_query("PixelFormat") .map_vimba_err()?; Ok(fmts @@ -554,6 +579,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { let pixfmt_vimba = vimba::pixel_format_to_str(pixfmt).map_vimba_err()?; self.camera .lock() + .unwrap() .feature_enum_set("PixelFormat", pixfmt_vimba) .map_vimba_err()?; Ok(()) @@ -561,54 +587,63 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { fn exposure_time(&self) -> std::result::Result { self.camera .lock() + .unwrap() .feature_float("ExposureTime") .map_vimba_err() } fn exposure_time_range(&self) -> std::result::Result<(f64, f64), ci2::Error> { self.camera .lock() + .unwrap() .feature_float_range_query("ExposureTime") .map_vimba_err() } fn set_exposure_time(&mut self, value: f64) -> std::result::Result<(), ci2::Error> { self.camera .lock() + .unwrap() .feature_float_set("ExposureTime", value) .map_vimba_err() } fn exposure_auto(&self) -> std::result::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); let mystr = c.feature_enum("ExposureAuto").map_vimba_err()?; str_to_auto_mode(mystr) } fn set_exposure_auto(&mut self, value: AutoMode) -> std::result::Result<(), ci2::Error> { let valstr = auto_mode_to_str(value); - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum_set("ExposureAuto", valstr).map_vimba_err() } fn gain(&self) -> std::result::Result { - self.camera.lock().feature_float("Gain").map_vimba_err() + self.camera + .lock() + .unwrap() + .feature_float("Gain") + .map_vimba_err() } fn gain_range(&self) -> std::result::Result<(f64, f64), ci2::Error> { self.camera .lock() + .unwrap() .feature_float_range_query("Gain") .map_vimba_err() } fn set_gain(&mut self, value: f64) -> std::result::Result<(), ci2::Error> { self.camera .lock() + .unwrap() .feature_float_set("Gain", value) .map_vimba_err() } fn gain_auto(&self) -> std::result::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); let mystr = c.feature_enum("GainAuto").map_vimba_err()?; str_to_auto_mode(mystr) } fn set_gain_auto(&mut self, value: AutoMode) -> std::result::Result<(), ci2::Error> { let valstr = auto_mode_to_str(value); - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum_set("GainAuto", valstr).map_vimba_err() } @@ -623,7 +658,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { // The trigger selector must be set before the trigger mode. self.set_trigger_selector(ci2::TriggerSelector::FrameStart)?; { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum_set("TriggerSource", "Line0") .map_vimba_err()?; } @@ -655,7 +690,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { } fn trigger_mode(&self) -> std::result::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); let val = c.feature_enum("TriggerMode").map_vimba_err()?; match val { "Off" => Ok(ci2::TriggerMode::Off), @@ -673,12 +708,13 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { ci2::TriggerMode::Off => "Off", ci2::TriggerMode::On => "On", }; - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum_set("TriggerMode", valstr).map_vimba_err() } fn acquisition_frame_rate_enable(&self) -> std::result::Result { self.camera .lock() + .unwrap() .feature_boolean("AcquisitionFrameRateEnable") .map_vimba_err() } @@ -688,29 +724,33 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { ) -> std::result::Result<(), ci2::Error> { self.camera .lock() + .unwrap() .feature_boolean_set("AcquisitionFrameRateEnable", value) .map_vimba_err() } fn acquisition_frame_rate(&self) -> std::result::Result { self.camera .lock() + .unwrap() .feature_float("AcquisitionFrameRate") .map_vimba_err() } fn acquisition_frame_rate_range(&self) -> std::result::Result<(f64, f64), ci2::Error> { self.camera .lock() + .unwrap() .feature_float_range_query("AcquisitionFrameRate") .map_vimba_err() } fn set_acquisition_frame_rate(&mut self, value: f64) -> std::result::Result<(), ci2::Error> { self.camera .lock() + .unwrap() .feature_float_set("AcquisitionFrameRate", value) .map_vimba_err() } fn trigger_selector(&self) -> std::result::Result { - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); let val = c.feature_enum("TriggerSelector").map_vimba_err()?; match val { "AcquisitionStart" => Ok(ci2::TriggerSelector::AcquisitionStart), @@ -741,7 +781,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { ))) } }; - let c = self.camera.lock(); + let c = self.camera.lock().unwrap(); c.feature_enum_set("TriggerSelector", valstr) .map_vimba_err() } @@ -749,6 +789,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { let val = self .camera .lock() + .unwrap() .feature_enum("AcquisitionMode") .map_vimba_err()?; Ok(match val { @@ -770,6 +811,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { let modes = self .camera .lock() + .unwrap() .feature_enum_range_query("AcquisitionMode") .map_vimba_err()?; println!("modes {:?}", modes); @@ -781,13 +823,14 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { }; self.camera .lock() + .unwrap() .feature_enum_set("AcquisitionMode", sval) .map_vimba_err() } fn acquisition_start(&mut self) -> std::result::Result<(), ci2::Error> { IS_DONE.store(false, Ordering::Relaxed); // indicate we are done - let camera = self.camera.lock(); + let camera = self.camera.lock().unwrap(); for _ in 0..N_BUFFER_FRAMES { let buffer = camera.allocate_buffer().map_vimba_err()?; @@ -814,7 +857,7 @@ impl<'lib> ci2::Camera for WrappedCamera<'lib> { Ok(()) } fn acquisition_stop(&mut self) -> std::result::Result<(), ci2::Error> { - let camera = self.camera.lock(); + let camera = self.camera.lock().unwrap(); IS_DONE.store(true, Ordering::Relaxed); // indicate we are done diff --git a/flydra2/Cargo.toml b/flydra2/Cargo.toml index 6ea067ce5..6b602dd89 100644 --- a/flydra2/Cargo.toml +++ b/flydra2/Cargo.toml @@ -14,7 +14,6 @@ build-util.workspace = true [dependencies] thiserror.workspace = true hdrhistogram.workspace = true -parking_lot.workspace = true futures.workspace = true pin-project.workspace = true csv.workspace = true diff --git a/flydra2/src/connected_camera_manager.rs b/flydra2/src/connected_camera_manager.rs index c6391da88..e3689fdcb 100644 --- a/flydra2/src/connected_camera_manager.rs +++ b/flydra2/src/connected_camera_manager.rs @@ -1,7 +1,8 @@ -use parking_lot::{Mutex, RwLock}; use std::collections::{BTreeMap, BTreeSet}; -use std::sync::atomic::{AtomicBool, Ordering}; -use std::sync::Arc; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, Mutex, RwLock, +}; use tracing::{debug, error, info}; use crate::{safe_u8, CamInfoRow, MyFloat}; @@ -91,6 +92,7 @@ impl HasCameraList for ConnectedCamerasManager { let inner: BTreeSet = self .inner .read() + .unwrap() .ccis .values() .map(|cci| cci.cam_num.0) @@ -156,7 +158,7 @@ impl ConnectedCamerasManager { pub fn reset_sync_data(&mut self) { info!("Camera manager dropping old cameras and expecting new cameras"); - let mut next_cam_num = { self.inner.read().next_cam_num.0 }; + let mut next_cam_num = { self.inner.read().unwrap().next_cam_num.0 }; let mut not_yet_connected = BTreeMap::new(); // pre-reserve cam numbers for cameras in calibration @@ -171,7 +173,7 @@ impl ConnectedCamerasManager { } let old_ccis = { - let mut inner = self.inner.write(); + let mut inner = self.inner.write().unwrap(); inner.next_cam_num = next_cam_num.into(); let old_ccis = std::mem::take(&mut inner.ccis); inner.not_yet_connected = not_yet_connected; @@ -195,7 +197,7 @@ impl ConnectedCamerasManager { f: Box, ) -> Option> { let old = { - let mut mutex_guard = self.on_cam_change_func.lock(); + let mut mutex_guard = self.on_cam_change_func.lock().unwrap(); mutex_guard.replace(f) }; @@ -205,13 +207,14 @@ impl ConnectedCamerasManager { } fn notify_cam_changed_listeners(&self) { - let mutex_guard = self.on_cam_change_func.lock(); + let mutex_guard = self.on_cam_change_func.lock().unwrap(); let inner_ref: Option<&Box> = mutex_guard.as_ref(); if let Some(cb) = inner_ref { let cams = { // scope for read lock on self.inner self.inner .read() + .unwrap() .ccis .values() .map(|cci| CamInfo { @@ -252,7 +255,7 @@ impl ConnectedCamerasManager { { let raw_cam_name = raw_cam_name.clone(); - let mut inner = this.inner.write(); + let mut inner = this.inner.write().unwrap(); assert!( !inner.ccis.contains_key(&raw_cam_name), @@ -293,7 +296,7 @@ impl ConnectedCamerasManager { } pub fn remove(&mut self, raw_cam_name: &RawCamName) { - self.inner.write().ccis.remove(raw_cam_name); + self.inner.write().unwrap().ccis.remove(raw_cam_name); self.notify_cam_changed_listeners(); } @@ -315,7 +318,7 @@ impl ConnectedCamerasManager { let raw_cam_name = raw_cam_name.clone(); let cam_num = { // This scope is for the write lock on self.inner. Keep it minimal. - let mut inner = self.inner.write(); + let mut inner = self.inner.write().unwrap(); if inner.ccis.contains_key(&raw_cam_name) { tracing::error!( @@ -417,14 +420,14 @@ impl ConnectedCamerasManager { let mut got_frame_during_sync_time = false; let mut do_check_if_all_cameras_present = false; { - let inner = self.inner.read(); + let inner = self.inner.read().unwrap(); if let Some(cci) = inner.ccis.get(&raw_cam_name) { // We know this camera already. use crate::ConnectedCameraSyncState::*; match cci.sync_state { Unsynchronized => { do_check_if_all_cameras_present = true; - let sync_pulse_pause_started = sync_pulse_pause_started_arc.read(); + let sync_pulse_pause_started = sync_pulse_pause_started_arc.read().unwrap(); if let Some(pulse_time) = *sync_pulse_pause_started { let elapsed = pulse_time.elapsed(); if sync_time_min < elapsed && elapsed < sync_time_max { @@ -480,7 +483,7 @@ impl ConnectedCamerasManager { if got_frame_during_sync_time { let frames_during_sync = { // This scope is for the write lock on self.inner. Keep it minimal. - let mut inner = self.inner.write(); + let mut inner = self.inner.write().unwrap(); let frames_during_sync = match inner.ccis.get_mut(&raw_cam_name) { Some(cci) => { cci.frames_during_sync += 1; @@ -520,7 +523,7 @@ impl ConnectedCamerasManager { let my_span = tracing::span!(tracing::Level::DEBUG, "got_new_frame_live_ptp", cam); let _enter = my_span.enter(); - let inner = self.inner.read(); + let inner = self.inner.read().unwrap(); if let Some(cci) = inner.ccis.get(&raw_cam_name) { let camera_periodic_signal_period_usec = self .periodic_signal_period_usec @@ -605,7 +608,7 @@ impl ConnectedCamerasManager { // Perform the book-keeping associated with synchronization. { // This scope is for the write lock on self.inner. Keep it minimal. - let mut inner = self.inner.write(); + let mut inner = self.inner.write().unwrap(); match inner.ccis.get_mut(&raw_cam_name) { Some(cci) => { cci.sync_state = ConnectedCameraSyncState::Synchronized(frame0); @@ -628,8 +631,10 @@ impl ConnectedCamerasManager { do_check_if_all_cameras_synchronized = true; } - if do_check_if_all_cameras_present && !self.inner.read().all_expected_cameras_are_present { - let mut inner = self.inner.write(); + if do_check_if_all_cameras_present + && !self.inner.read().unwrap().all_expected_cameras_are_present + { + let mut inner = self.inner.write().unwrap(); let i2: &mut ConnectedCamerasManagerInner = &mut inner; if i2.first_frame_arrived.insert(raw_cam_name.clone()) { info!( @@ -647,9 +652,9 @@ impl ConnectedCamerasManager { } if do_check_if_all_cameras_synchronized - && !self.inner.read().all_expected_cameras_are_synced + && !self.inner.read().unwrap().all_expected_cameras_are_synced { - let mut inner = self.inner.write(); + let mut inner = self.inner.write().unwrap(); let i2: &mut ConnectedCamerasManagerInner = &mut inner; // if i2.first_frame_arrived.insert(raw_cam_name.clone()) { // info!("first frame from camera {} arrived.", raw_cam_name); @@ -678,7 +683,7 @@ impl ConnectedCamerasManager { } pub fn get_raw_cam_name(&self, cam_num: CamNum) -> Option { - for cci in self.inner.read().ccis.values() { + for cci in self.inner.read().unwrap().ccis.values() { if cci.cam_num == cam_num { return Some(cci.raw_cam_name.clone()); } @@ -689,6 +694,7 @@ impl ConnectedCamerasManager { pub fn all_raw_cam_names(&self) -> Vec { self.inner .read() + .unwrap() .ccis .values() .map(|cci| cci.raw_cam_name.clone()) @@ -698,13 +704,14 @@ impl ConnectedCamerasManager { pub fn http_camserver_info(&self, raw_cam_name: &RawCamName) -> Option { self.inner .read() + .unwrap() .ccis .get(raw_cam_name) .map(|cci| cci.http_camserver_info.clone()) } pub fn cam_num(&self, raw_cam_name: &RawCamName) -> Option { - let inner = self.inner.read(); + let inner = self.inner.read().unwrap(); match inner.ccis.get(raw_cam_name) { Some(cci) => Some(cci.cam_num), None => inner.not_yet_connected.get(raw_cam_name).copied(), @@ -714,6 +721,7 @@ impl ConnectedCamerasManager { pub(crate) fn sample(&self) -> Vec { self.inner .read() + .unwrap() .ccis .values() .map(|cci| cci.copy_to_caminfo()) @@ -721,11 +729,11 @@ impl ConnectedCamerasManager { } pub fn len(&self) -> usize { - self.inner.read().ccis.len() + self.inner.read().unwrap().ccis.len() } pub fn is_empty(&self) -> bool { - self.inner.read().ccis.is_empty() + self.inner.read().unwrap().ccis.is_empty() } } diff --git a/flytrax-csv-to-braidz/Cargo.toml b/flytrax-csv-to-braidz/Cargo.toml index 339756dfe..0b57603f9 100644 --- a/flytrax-csv-to-braidz/Cargo.toml +++ b/flytrax-csv-to-braidz/Cargo.toml @@ -8,7 +8,6 @@ rust-version = "1.76" [dependencies] tracing.workspace = true clap.workspace = true -parking_lot.workspace = true csv.workspace = true chrono.workspace = true serde.workspace = true @@ -16,7 +15,6 @@ serde_json.workspace = true serde_yaml.workspace = true toml.workspace = true nalgebra.workspace = true -configure.workspace = true itertools.workspace = true lazy_static.workspace = true futures.workspace = true diff --git a/http-video-streaming/Cargo.toml b/http-video-streaming/Cargo.toml index a640bc0f4..7dbd464f4 100644 --- a/http-video-streaming/Cargo.toml +++ b/http-video-streaming/Cargo.toml @@ -11,7 +11,6 @@ chrono.workspace = true base64.workspace = true tokio.workspace = true tokio-stream.workspace = true -parking_lot.workspace = true serde_json.workspace = true futures.workspace = true machine-vision-formats.workspace = true diff --git a/http-video-streaming/src/lib.rs b/http-video-streaming/src/lib.rs index 0645c13c5..369221d54 100644 --- a/http-video-streaming/src/lib.rs +++ b/http-video-streaming/src/lib.rs @@ -1,6 +1,8 @@ use http_video_streaming_types::StrokeStyle; -use parking_lot::Mutex; -use std::{collections::HashMap, sync::Arc}; +use std::{ + collections::HashMap, + sync::{Arc, Mutex}, +}; use tokio_stream::StreamExt; @@ -94,7 +96,7 @@ impl PerSender { // sent_time computed early so that latency includes duration to encode, etc. let sent_time = chrono::Local::now(); let tc = { - let most_recent_frame_data = most_recent_frame_data.lock(); + let most_recent_frame_data = most_recent_frame_data.lock().unwrap(); let bytes = basic_frame::match_all_dynamic_fmts!( &most_recent_frame_data.frame, x, diff --git a/led-box-standalone/Cargo.toml b/led-box-standalone/Cargo.toml index 91b1aa78c..4a20189f9 100644 --- a/led-box-standalone/Cargo.toml +++ b/led-box-standalone/Cargo.toml @@ -15,7 +15,6 @@ tokio = { version = "1.0.1", default-features = false, features = [ ] } tokio-util = { version = "0.7.3", features = ["codec"] } tokio-serial = "5.4.1" -parking_lot = "0.12.1" anyhow.workspace = true byteorder.workspace = true eframe = { version = "0.22.0", default-features = false, features = [ diff --git a/led-box-standalone/src/app.rs b/led-box-standalone/src/app.rs index 6ad1daa74..bdcf2af92 100644 --- a/led-box-standalone/src/app.rs +++ b/led-box-standalone/src/app.rs @@ -1,6 +1,4 @@ -use std::sync::Arc; - -use parking_lot::Mutex; +use std::sync::{Arc, Mutex}; use eframe::egui; @@ -22,7 +20,7 @@ impl LedBoxApp { cmd_tx: tokio::sync::mpsc::Sender, cc: &eframe::CreationContext<'_>, ) -> Self { - box_manager.lock().frame = Some(cc.egui_ctx.clone()); + box_manager.lock().unwrap().frame = Some(cc.egui_ctx.clone()); Self { available_ports, box_manager, @@ -49,7 +47,7 @@ impl eframe::App for LedBoxApp { ui.heading("LED box control"); { - let status = box_manager.lock().status(); + let status = box_manager.lock().unwrap().status(); match &status { BoxStatus::Unconnected => { ui.label(" Unconnected "); diff --git a/led-box-standalone/src/box_status.rs b/led-box-standalone/src/box_status.rs index 5ca718540..c684bbe0c 100644 --- a/led-box-standalone/src/box_status.rs +++ b/led-box-standalone/src/box_status.rs @@ -1,12 +1,10 @@ -use std::sync::Arc; +use std::sync::{Arc, Mutex}; use eframe::egui; use futures::{SinkExt, StreamExt}; use tokio_serial::SerialPortBuilderExt; use tokio_util::codec::Decoder; -use parking_lot::Mutex; - use tracing::{debug, error, info}; use json_lines::codec::JsonLinesCodec; @@ -72,7 +70,7 @@ pub async fn handle_box( mut cmd_rx: tokio::sync::mpsc::Receiver, ) -> anyhow::Result<()> { // initial state - unconnected - assert_eq!(box_manager.lock().status(), BoxStatus::Unconnected); + assert_eq!(box_manager.lock().unwrap().status(), BoxStatus::Unconnected); let device_name; loop { @@ -160,7 +158,7 @@ pub async fn handle_box( to_box_writer.send(msg).await.unwrap(); let mut frame = { - let mut guard = box_manager.lock(); + let mut guard = box_manager.lock().unwrap(); guard.inner = Some(BoxManagerInner { to_box_writer, state: next_state, @@ -212,6 +210,7 @@ pub async fn handle_box( let stream_future = { let to_box_writer = box_manager .lock() + .unwrap() .inner .as_ref() .unwrap() @@ -261,7 +260,7 @@ async fn handle_cmd(cmd: Cmd, box_manager: &mut Arc>) -> anyho tracing::warn!("already connected"); } Cmd::Toggle(chan) => { - let mut guard = box_manager.lock(); + let mut guard = box_manager.lock().unwrap(); { let inner = guard.inner.as_mut().unwrap(); { diff --git a/led-box-standalone/src/main.rs b/led-box-standalone/src/main.rs index be9f43f2d..6a4a7dd97 100644 --- a/led-box-standalone/src/main.rs +++ b/led-box-standalone/src/main.rs @@ -1,6 +1,4 @@ -use std::sync::Arc; - -use parking_lot::Mutex; +use std::sync::{Arc, Mutex}; mod app; mod box_status; diff --git a/strand-cam/Cargo.toml b/strand-cam/Cargo.toml index 3f4d6c522..af90c1306 100644 --- a/strand-cam/Cargo.toml +++ b/strand-cam/Cargo.toml @@ -30,7 +30,6 @@ preferences-serde1.workspace = true base64.workspace = true directories = "4.0.1" eyre.workspace = true -parking_lot.workspace = true ipp-sys = { workspace = true, optional = true } ci2.workspace = true ci2-async.workspace = true diff --git a/strand-cam/src/flydratrax_handle_msg.rs b/strand-cam/src/flydratrax_handle_msg.rs index e5e813a96..762ecfcbb 100644 --- a/strand-cam/src/flydratrax_handle_msg.rs +++ b/strand-cam/src/flydratrax_handle_msg.rs @@ -1,7 +1,6 @@ use async_change_tracker::ChangeTracker; use nalgebra as na; -use parking_lot::RwLock; -use std::sync::Arc; +use std::sync::{Arc, RwLock}; use tracing::{debug, error, info}; use crate::Result; @@ -88,7 +87,7 @@ pub async fn create_message_handler( { let led_program_config: LedProgramConfig = { - let store = ssa2.read(); + let store = ssa2.read().unwrap(); store.as_ref().led_program_config.clone() }; let led_trigger_mode = led_program_config.led_trigger_mode; @@ -143,7 +142,7 @@ pub async fn create_message_handler( if *led_state != next_led_state { info!("switching LED to ON={:?}", next_led_state); let device_state: Option = { - let tracker = ssa2.read(); + let tracker = ssa2.read().unwrap(); tracker.as_ref().led_box_device_state.clone() }; if let Some(mut device_state) = device_state { diff --git a/strand-cam/src/frame_process_task.rs b/strand-cam/src/frame_process_task.rs index 89b96f9d7..3a26470a6 100644 --- a/strand-cam/src/frame_process_task.rs +++ b/strand-cam/src/frame_process_task.rs @@ -13,7 +13,7 @@ use std::{ fs::File, net::SocketAddr, path::{Path, PathBuf}, - sync::Arc, + sync::{Arc, RwLock}, }; use tracing::{debug, error, info, trace}; @@ -56,7 +56,7 @@ pub(crate) async fn frame_process_task<'a>( #[cfg(feature = "flydratrax")] http_camserver_info: flydra_types::BuiServerAddrInfo, transmit_msg_tx: Option>, camdata_udp_addr: Option, - led_box_heartbeat_update_arc: Arc>>, + led_box_heartbeat_update_arc: Arc>>, #[cfg(feature = "checkercal")] collected_corners_arc: crate::CollectedCornersArc, #[cfg(feature = "flydratrax")] args: &crate::StrandCamArgs, #[cfg(feature = "flydra_feat_detect")] acquisition_duration_allowed_imprecision_msec: Option< @@ -165,7 +165,7 @@ pub(crate) async fn frame_process_task<'a>( )?; #[cfg(feature = "flydra_feat_detect")] let mut csv_save_state = SavingState::NotSaving; - let mut shared_store_arc: Option>>> = None; + let mut shared_store_arc: Option>>> = None; let mut fps_calc = FpsCalc::new(100); // average 100 frames to get mean fps #[cfg(feature = "flydratrax")] let mut kalman_tracking_config = strand_cam_storetype::KalmanTrackingConfig::default(); // this is replaced below @@ -183,7 +183,7 @@ pub(crate) async fn frame_process_task<'a>( #[cfg(feature = "flydratrax")] let red_style = http_video_streaming_types::StrokeStyle::from_rgb(255, 100, 100); - let expected_framerate_arc = Arc::new(parking_lot::RwLock::new(None)); + let expected_framerate_arc = Arc::new(RwLock::new(None)); let mut post_trig_buffer = post_trigger_buffer::PostTriggerBuffer::new(); @@ -213,7 +213,7 @@ pub(crate) async fn frame_process_task<'a>( #[cfg(feature = "checkercal")] let mut checkerboard_loop_dur = std::time::Duration::from_millis(500); - // let current_image_timer_arc = Arc::new(parking_lot::RwLock::new(std::time::Instant::now())); + // let current_image_timer_arc = Arc::new(RwLock::new(std::time::Instant::now())); let mut im_ops_socket: Option = None; @@ -224,7 +224,7 @@ pub(crate) async fn frame_process_task<'a>( #[cfg(feature = "flydra_feat_detect")] { if let Some(ref ssa) = shared_store_arc { - if let Some(store) = ssa.try_read() { + if let Ok(store) = ssa.try_read() { let tracker = store.as_ref(); is_doing_object_detection = tracker.is_doing_object_detection; // make copy. TODO only copy on change. @@ -242,7 +242,7 @@ pub(crate) async fn frame_process_task<'a>( } let kalman_tracking_enabled = if let Some(ref ssa) = shared_store_arc { - let tracker = ssa.read(); + let tracker = ssa.read().unwrap(); tracker.as_ref().kalman_tracking_config.enabled } else { false @@ -255,7 +255,7 @@ pub(crate) async fn frame_process_task<'a>( let mut new_cam = None; if let Some(ref ssa) = shared_store_arc { let region = { - let tracker = ssa.read(); + let tracker = ssa.read().unwrap(); kalman_tracking_config = tracker.as_ref().kalman_tracking_config.clone(); led_program_config = tracker.as_ref().led_program_config.clone(); tracker.as_ref().im_pt_detect_cfg.valid_region.clone() @@ -367,7 +367,7 @@ pub(crate) async fn frame_process_task<'a>( coord_processor.add_listener(model_sender); // the local LED control thing coord_processor.add_listener(model_server_data_tx); // the HTTP thing - let expected_framerate = *expected_framerate_arc2.read(); + let expected_framerate = *expected_framerate_arc2.read().unwrap(); let consume_future = coord_processor.consume_stream(flydra2_rx, expected_framerate); @@ -398,7 +398,7 @@ pub(crate) async fn frame_process_task<'a>( } if let Some(cam) = new_cam { if let Some(ref mut store) = shared_store_arc { - let mut tracker = store.write(); + let mut tracker = store.write().unwrap(); tracker.modify(|tracker| { tracker.camera_calibration = Some(cam); }); @@ -435,7 +435,7 @@ pub(crate) async fn frame_process_task<'a>( } }; let store_cache = if let Some(ref ssa) = shared_store_arc { - let tracker = ssa.read(); + let tracker = ssa.read().unwrap(); Some(tracker.as_ref().clone()) } else { None @@ -467,13 +467,13 @@ pub(crate) async fn frame_process_task<'a>( Msg::Store(stor) => { // We get the shared store once at startup. if is_braid { - let mut tracker = stor.write(); + let mut tracker = stor.write().unwrap(); tracker.modify(|tracker| { tracker.is_doing_object_detection = true; }); } { - let tracker = stor.read(); + let tracker = stor.read().unwrap(); let shared = tracker.as_ref(); post_trig_buffer.set_size(shared.post_trigger_buffer_size); } @@ -507,7 +507,7 @@ pub(crate) async fn frame_process_task<'a>( let (format_str_mp4, mp4_recording_config) = { // scope for reading cache - let tracker = shared_store_arc.as_ref().unwrap().read(); + let tracker = shared_store_arc.as_ref().unwrap().read().unwrap(); let shared: &StoreType = tracker.as_ref(); let mp4_recording_config = FinalMp4RecordingConfig::new(shared, creation_time); @@ -536,7 +536,7 @@ pub(crate) async fn frame_process_task<'a>( my_mp4_writer = Some(raw); if let Some(ref mut store) = shared_store_arc { - let mut tracker = store.write(); + let mut tracker = store.write().unwrap(); tracker.modify(|tracker| { tracker.is_recording_mp4 = is_recording_mp4; }); @@ -566,7 +566,7 @@ pub(crate) async fn frame_process_task<'a>( Msg::SetPostTriggerBufferSize(size) => { post_trig_buffer.set_size(size); if let Some(ref mut store) = shared_store_arc { - let mut tracker = store.write(); + let mut tracker = store.write().unwrap(); tracker.modify(|tracker| { tracker.post_trigger_buffer_size = size; }); @@ -638,14 +638,14 @@ pub(crate) async fn frame_process_task<'a>( if let Some(new_fps) = fps_calc.update(&extracted_frame_info) { if let Some(ref mut store) = shared_store_arc { - let mut tracker = store.write(); + let mut tracker = store.write().unwrap(); tracker.modify(|tracker| { tracker.measured_fps = new_fps as f32; }); } { - let mut expected_framerate = expected_framerate_arc.write(); + let mut expected_framerate = expected_framerate_arc.write().unwrap(); *expected_framerate = Some(new_fps as f32); } } @@ -788,14 +788,15 @@ pub(crate) async fn frame_process_task<'a>( .collect(); let num_checkerboards_collected = { - let mut collected_corners = collected_corners_arc.write(); + let mut collected_corners = + collected_corners_arc.write().unwrap(); collected_corners.push(corners); collected_corners.len().try_into().unwrap() }; if let Some(ref ssa) = shared_store_arc { // scope for write lock on ssa - let mut tracker = ssa.write(); + let mut tracker = ssa.write().unwrap(); tracker.modify(|shared| { shared.checkerboard_data.num_checkerboards_collected = num_checkerboards_collected; @@ -1107,7 +1108,7 @@ pub(crate) async fn frame_process_task<'a>( // scope for write lock on ssa let new_val = RecordingPath::new(csv_path.display().to_string()); - let mut tracker = ssa.write(); + let mut tracker = ssa.write().unwrap(); tracker.modify(|shared| { shared.is_saving_im_pt_detect_csv = Some(new_val); }); @@ -1292,7 +1293,7 @@ pub(crate) async fn frame_process_task<'a>( .collect(); // check led_box device heartbeat - if let Some(reader) = *led_box_heartbeat_update_arc.read() { + if let Some(reader) = *led_box_heartbeat_update_arc.read().unwrap() { let elapsed = reader.elapsed(); if elapsed > std::time::Duration::from_millis(2 * LED_BOX_HEARTBEAT_INTERVAL_MSEC) @@ -1301,7 +1302,7 @@ pub(crate) async fn frame_process_task<'a>( // No heartbeat within the specified interval. if let Some(ref ssa) = shared_store_arc { - let mut tracker = ssa.write(); + let mut tracker = ssa.write().unwrap(); tracker.modify(|store| store.led_box_device_lost = true); } } @@ -1425,7 +1426,7 @@ pub(crate) async fn frame_process_task<'a>( // update UI if let Some(ref ssa) = shared_store_arc { // scope for write lock on ssa - let mut tracker = ssa.write(); + let mut tracker = ssa.write().unwrap(); tracker.modify(|shared| { shared.is_saving_im_pt_detect_csv = None; }); @@ -1459,7 +1460,7 @@ pub(crate) async fn frame_process_task<'a>( inner.finish()?; } if let Some(ref mut store) = shared_store_arc { - let mut tracker = store.write(); + let mut tracker = store.write().unwrap(); tracker.modify(|tracker| { tracker.is_recording_mp4 = None; }); diff --git a/strand-cam/src/strand-cam.rs b/strand-cam/src/strand-cam.rs index 81a98f579..a9b589b99 100644 --- a/strand-cam/src/strand-cam.rs +++ b/strand-cam/src/strand-cam.rs @@ -66,7 +66,7 @@ use strand_cam_storetype::{KalmanTrackingConfig, LedProgramConfig}; use std::{ io::Write, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket}, - sync::Arc, + sync::{Arc, RwLock}, }; pub const APP_INFO: AppInfo = AppInfo { @@ -148,7 +148,7 @@ pub(crate) enum Msg { SetIsSavingObjDetectionCsv(CsvSaveConfig), #[cfg(feature = "flydra_feat_detect")] SetExpConfig(ImPtDetectCfg), - Store(Arc>>), + Store(Arc>>), #[cfg(feature = "flydra_feat_detect")] TakeCurrentImageAsBackground, #[cfg(feature = "flydra_feat_detect")] @@ -241,7 +241,7 @@ where } #[cfg(feature = "checkercal")] -type CollectedCornersArc = Arc>>>; +type CollectedCornersArc = Arc>>>; async fn convert_stream( raw_cam_name: RawCamName, @@ -342,7 +342,7 @@ struct StrandCamAppState { event_broadcaster: EventBroadcaster, callback_senders: StrandCamCallbackSenders, tx_new_connection: tokio::sync::mpsc::Sender, - shared_store_arc: Arc>>, + shared_store_arc: Arc>>, } type MyBody = http_body_util::combinators::BoxBody; @@ -359,12 +359,12 @@ async fn check_version( MyBody, // http_body_util::Empty, >, - known_version: Arc>, + known_version: Arc>, app_name: &'static str, ) -> Result<()> { let url = format!("https://version-check.strawlab.org/{app_name}"); let url = url.parse::().unwrap(); - let agent = format!("{}/{}", app_name, *known_version.read()); + let agent = format!("{}/{}", app_name, *known_version.read().unwrap()); let req = hyper::Request::builder() .uri(&url) @@ -403,7 +403,7 @@ async fn check_version( return Ok(()); } }; - let mut known_v = known_version3.write(); + let mut known_v = known_version3.write().unwrap(); if version.available > *known_v { info!( "New version of {} is available: {}. {}", @@ -705,7 +705,7 @@ async fn events_handler( } // Send an initial copy of our state. - let shared_store = app_state.shared_store_arc.read().as_ref().clone(); + let shared_store = app_state.shared_store_arc.read().unwrap().as_ref().clone(); let frame_string = to_event_frame(&shared_store); match tx .send(Ok(http_body::Frame::data(frame_string.into()))) @@ -1052,7 +1052,7 @@ where cookie_store::CookieStore::new(None) } }; - let jar = Arc::new(parking_lot::RwLock::new(jar)); + let jar = Arc::new(RwLock::new(jar)); let mut mainbrain_session = braid_http_session::create_mainbrain_session( mainbrain_bui_loc.clone(), jar.clone(), @@ -1061,7 +1061,7 @@ where tracing::debug!("Opened HTTP session with Braid."); { // We have the cookie from braid now, so store it to disk. - let jar = jar.read(); + let jar = jar.read().unwrap(); Preferences::save(&*jar, &APP_INFO, BRAID_COOKIE_KEY)?; tracing::debug!("saved cookie store {BRAID_COOKIE_KEY}"); } @@ -1684,7 +1684,7 @@ where let (cam_args_tx, cam_args_rx) = tokio::sync::mpsc::channel(100); let (led_box_tx_std, mut led_box_rx) = tokio::sync::mpsc::channel(20); - let led_box_heartbeat_update_arc = Arc::new(parking_lot::RwLock::new(None)); + let led_box_heartbeat_update_arc = Arc::new(RwLock::new(None)); let gain_ranged = RangedValue { name: "gain".into(), @@ -1983,9 +1983,7 @@ where camera_calibration: None, }); - let frame_processing_error_state = Arc::new(parking_lot::RwLock::new( - FrameProcessingErrorState::default(), - )); + let frame_processing_error_state = Arc::new(RwLock::new(FrameProcessingErrorState::default())); // let mut config = get_default_config(); // config.cookie_name = "strand-camclient".to_string(); @@ -2004,7 +2002,7 @@ where let (tx_new_connection, rx_new_connection) = tokio::sync::mpsc::channel(10); - let shared_state = Arc::new(parking_lot::RwLock::new(shared_store)); + let shared_state = Arc::new(RwLock::new(shared_store)); let shared_store_arc = shared_state.clone(); // Create our app state. @@ -2145,7 +2143,7 @@ where } #[cfg(feature = "checkercal")] - let collected_corners_arc: CollectedCornersArc = Arc::new(parking_lot::RwLock::new(Vec::new())); + let collected_corners_arc: CollectedCornersArc = Arc::new(RwLock::new(Vec::new())); let frame_process_task_fut = { #[cfg(feature = "flydra_feat_detect")] @@ -2265,9 +2263,9 @@ where } if tx_frame.capacity() == 0 { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| { - let mut state = frame_processing_error_state.write(); + let mut state = frame_processing_error_state.write().unwrap(); { match &*state { FrameProcessingErrorState::IgnoreAll => {} @@ -2352,7 +2350,7 @@ where // TODO I just used Arc and RwLock to code this quickly. Convert to single-threaded // versions later. - let known_version = Arc::new(parking_lot::RwLock::new(app_version)); + let known_version = Arc::new(RwLock::new(app_version)); // Create a stream to call our closure now and every 30 minutes. let interval_stream = tokio::time::interval(std::time::Duration::from_secs(1800)); @@ -2409,7 +2407,7 @@ where #[allow(unused_variables)] match cam_args { CamArg::SetIngoreFutureFrameProcessingErrors(v) => { - let mut state = frame_processing_error_state.write(); + let mut state = frame_processing_error_state.write().unwrap(); match v { None => { *state = FrameProcessingErrorState::IgnoreAll; @@ -2425,7 +2423,7 @@ where } } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.had_frame_processing_error = false); } CamArg::SetExposureTime(v) => match cam.set_exposure_time(v) { @@ -2440,7 +2438,7 @@ where .await .unwrap(); } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.exposure_time.current = v); } Err(e) => { @@ -2459,7 +2457,7 @@ where .await .unwrap(); } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.gain.current = v); } Err(e) => { @@ -2478,7 +2476,7 @@ where .await .unwrap(); } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| match cam.gain_auto() { Ok(latest) => { shared.gain_auto = Some(latest); @@ -2494,23 +2492,23 @@ where } }, CamArg::SetRecordingFps(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.mp4_max_framerate = v); } CamArg::SetMp4CudaDevice(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.mp4_cuda_device = v); } CamArg::SetMp4MaxFramerate(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.mp4_max_framerate = v); } CamArg::SetMp4Bitrate(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.mp4_bitrate = v); } CamArg::SetMp4Codec(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.mp4_codec = v); } CamArg::SetExposureAuto(v) => match cam.set_exposure_auto(v) { @@ -2525,7 +2523,7 @@ where .await .unwrap(); } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| match cam.exposure_auto() { Ok(latest) => { shared.exposure_auto = Some(latest); @@ -2553,7 +2551,7 @@ where .await .unwrap(); } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { match cam.acquisition_frame_rate_enable() { Ok(latest) => { @@ -2582,7 +2580,7 @@ where .await .unwrap(); } - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| match cam.acquisition_frame_rate() { Ok(latest) => { if let Some(ref mut frl) = shared.frame_rate_limit { @@ -2616,13 +2614,13 @@ where .map_err(to_eyre)?; } CamArg::SetFormatStr(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|tracker| tracker.format_str = v); } CamArg::SetIsRecordingMp4(do_recording) => { // Copy values from cache and release the lock immediately. let is_recording_mp4 = { - let tracker = shared_store_arc.read(); + let tracker = shared_store_arc.read().unwrap(); let shared: &StoreType = tracker.as_ref(); shared.is_recording_mp4.is_some() }; @@ -2639,7 +2637,7 @@ where } } CamArg::ToggleAprilTagFamily(family) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { if let Some(ref mut ts) = shared.apriltag_state { if ts.is_recording_csv.is_some() { @@ -2653,7 +2651,7 @@ where }); } CamArg::ToggleAprilTagDetection(do_detection) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { if let Some(ref mut ts) = shared.apriltag_state { ts.do_detection = do_detection; @@ -2663,37 +2661,37 @@ where }); } CamArg::ToggleImOpsDetection(do_detection) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_ops_state.do_detection = do_detection; }); } CamArg::SetImOpsDestination(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_ops_state.destination = v; }); } CamArg::SetImOpsSource(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_ops_state.source = v; }); } CamArg::SetImOpsCenterX(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_ops_state.center_x = v; }); } CamArg::SetImOpsCenterY(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_ops_state.center_y = v; }); } CamArg::SetImOpsThreshold(v) => { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_ops_state.threshold = v; }); @@ -2701,7 +2699,7 @@ where CamArg::SetIsRecordingAprilTagCsv(do_recording) => { let new_val = { - let tracker = shared_store_arc.read(); + let tracker = shared_store_arc.read().unwrap(); let shared: &StoreType = tracker.as_ref(); if let Some(ref ts) = shared.apriltag_state { info!( @@ -2735,7 +2733,7 @@ where // Here we save the new recording state. if let Some(new_val) = new_val { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { if let Some(ref mut ts) = shared.apriltag_state { ts.is_recording_csv = new_val; @@ -2760,7 +2758,7 @@ where CamArg::SetIsRecordingFmf(do_recording) => { // Copy values from cache and release the lock immediately. let (is_recording_fmf, format_str, recording_framerate) = { - let tracker = shared_store_arc.read(); + let tracker = shared_store_arc.read().unwrap(); let shared: &StoreType = tracker.as_ref(); ( shared.is_recording_fmf.clone(), @@ -2789,7 +2787,7 @@ where tx_frame2.send(msg).await.map_err(to_eyre)?; // Save the new recording state. - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.is_recording_fmf = new_val; }); @@ -2800,7 +2798,7 @@ where { // Copy values from cache and release the lock immediately. let (is_recording_ufmf, format_str_ufmf) = { - let tracker = shared_store_arc.read(); + let tracker = shared_store_arc.read().unwrap(); let shared: &StoreType = tracker.as_ref(); ( shared.is_recording_ufmf.clone(), @@ -2833,7 +2831,7 @@ where tx_frame2.send(msg).await.map_err(to_eyre)?; // Save the new recording state. - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.is_recording_ufmf = new_val; }); @@ -2845,7 +2843,7 @@ where { { // update store - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.is_doing_object_detection = value; }); @@ -2883,7 +2881,7 @@ where .await .map_err(to_eyre)?; { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.im_pt_detect_cfg = cfg; }); @@ -2924,7 +2922,7 @@ where let cfg2 = cfg.clone(); { // Update config and send to frame process thread - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.kalman_tracking_config = cfg; }); @@ -2964,7 +2962,7 @@ where let cfg2 = cfg.clone(); { // Update config and send to frame process thread - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.led_program_config = cfg; }); @@ -2995,7 +2993,7 @@ where CamArg::ToggleCheckerboardDetection(val) => { #[cfg(feature = "checkercal")] { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.checkerboard_data.enabled = val; }); @@ -3004,7 +3002,7 @@ where CamArg::ToggleCheckerboardDebug(val) => { #[cfg(feature = "checkercal")] { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { if val { if shared.checkerboard_save_debug.is_none() { @@ -3038,7 +3036,7 @@ where CamArg::SetCheckerboardWidth(val) => { #[cfg(feature = "checkercal")] { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.checkerboard_data.width = val; }); @@ -3047,7 +3045,7 @@ where CamArg::SetCheckerboardHeight(val) => { #[cfg(feature = "checkercal")] { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.checkerboard_data.height = val; }); @@ -3057,12 +3055,12 @@ where #[cfg(feature = "checkercal")] { { - let mut collected_corners = collected_corners_arc.write(); + let mut collected_corners = collected_corners_arc.write().unwrap(); collected_corners.clear(); } { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.checkerboard_data.num_checkerboards_collected = 0; }); @@ -3075,7 +3073,7 @@ where { info!("computing calibration"); let (n_rows, n_cols, checkerboard_save_debug) = { - let tracker = shared_store_arc.read(); + let tracker = shared_store_arc.read().unwrap(); let shared = (*tracker).as_ref(); let n_rows = shared.checkerboard_data.height; let n_cols = shared.checkerboard_data.width; @@ -3085,7 +3083,7 @@ where }; let goodcorners: Vec = { - let collected_corners = collected_corners_arc.read(); + let collected_corners = collected_corners_arc.read().unwrap(); collected_corners .iter() .map(|corners| { @@ -3291,7 +3289,7 @@ where // open serial port let port = { - let tracker = shared_store_arc.read(); + let tracker = shared_store_arc.read().unwrap(); let shared = tracker.as_ref(); if let Some(serial_device) = shared.led_box_device_path.as_ref() { info!("opening LED box \"{}\"", serial_device); @@ -3361,7 +3359,8 @@ where debug!("LED box round trip time: {} msec", now_millis - sent_millis); // elsewhere check if this happens every LED_BOX_HEARTBEAT_INTERVAL_MSEC or so. - let mut led_box_heartbeat_update = led_box_heartbeat_update_arc.write(); + let mut led_box_heartbeat_update = + led_box_heartbeat_update_arc.write().unwrap(); *led_box_heartbeat_update = Some(std::time::Instant::now()); } Ok(led_box_comms::FromDevice::StateWasSet) => {} @@ -3384,7 +3383,7 @@ where writer.send(msg).await.unwrap(); // copy new device state and store it to our cache if let ToLedBoxDevice::DeviceState(new_state) = msg { - let mut tracker = shared_store_arc.write(); + let mut tracker = shared_store_arc.write().unwrap(); tracker.modify(|shared| { shared.led_box_device_state = Some(new_state); })