Skip to content

Commit

Permalink
remove use of parking_lot crate
Browse files Browse the repository at this point in the history
  • Loading branch information
astraw committed Dec 31, 2024
1 parent e60e41c commit 474b086
Show file tree
Hide file tree
Showing 28 changed files with 354 additions and 320 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion braid-http-session/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 1 addition & 2 deletions braid-http-session/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
3 changes: 0 additions & 3 deletions braid/braid-run/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
14 changes: 7 additions & 7 deletions braid/braid-run/src/callback_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down Expand Up @@ -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(),
Expand All @@ -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()
Expand Down Expand Up @@ -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;
});
Expand All @@ -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()
};

Expand Down
63 changes: 31 additions & 32 deletions braid/braid-run/src/mainbrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
path::PathBuf,
sync::{
atomic::{AtomicBool, Ordering},
Arc,
Arc, RwLock,
},
};

Expand All @@ -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;
Expand All @@ -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};

Expand All @@ -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<T> = std::result::Result<T, MainbrainError>;
Expand Down Expand Up @@ -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
Expand All @@ -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(&current_state);
match tx
.send(Ok(http_body::Frame::data(frame_string.into())))
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -399,7 +398,7 @@ struct SendConnectedCamToBuiBackend {

impl flydra2::ConnectedCamCallback for SendConnectedCamToBuiBackend {
fn on_cam_changed(&self, new_cam_list: Vec<CamInfo>) {
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());
}
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(_) => {
Expand Down Expand Up @@ -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<f32> = *expected_framerate_arc9.read();
let expected_framerate: Option<f32> = *expected_framerate_arc9.read().unwrap();
info!("expected_framerate: {:?}", expected_framerate);

coord_processor.add_listener(data_tx);
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -1294,14 +1293,14 @@ pub(crate) async fn toggle_saving_csv_tables(
shared_data: SharedStore,
) {
if start_saving {
let expected_framerate: Option<f32> = *expected_framerate_arc.read();
let expected_framerate: Option<f32> = *expected_framerate_arc.read().unwrap();
let local: chrono::DateTime<chrono::Local> = 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 {
Expand All @@ -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()));
});
Expand All @@ -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;
});
Expand All @@ -1363,15 +1362,15 @@ 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());
}

// Now we can reset the sync data.
cam_manager.reset_sync_data();

{
let mut guard = time_model_arc.write();
let mut guard = time_model_arc.write().unwrap();
*guard = None;
}

Expand Down
Loading

0 comments on commit 474b086

Please sign in to comment.