Skip to content

Commit

Permalink
mutex added
Browse files Browse the repository at this point in the history
  • Loading branch information
vats004 committed Feb 22, 2025
1 parent ac8a70b commit 568cc22
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ cfg-if = "1.0.0"
num-integer = "0.1.45"
lib_ccxr = { path = "lib_ccxr" }
url = "2.5.2"
lazy_static = "1.4.0"

[build-dependencies]
bindgen = "0.64.0"
Expand Down
13 changes: 10 additions & 3 deletions src/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use std::{
ffi::CStr,
io::Write,
os::raw::{c_char, c_double, c_int, c_long, c_uint},
sync::Mutex,
};

#[cfg(test)]
Expand All @@ -62,7 +63,6 @@ extern "C" {
static mut FILEBUFFERSIZE: c_int;
static mut MPEG_CLOCK_FREQ: c_int;
static mut tlt_config: ccx_s_teletext_config;
static mut ccx_options: ccx_s_options;
static mut pts_big_change: c_uint;
static mut current_fps: c_double;
static mut frames_since_ref_time: c_int;
Expand All @@ -76,6 +76,10 @@ extern "C" {
static mut profane: word_list;
}

lazy_static! {
static ref CCX_OPTIONS: Mutex<ccx_s_options> = Mutex::new(ccx_s_options::default());
}

/// Initialize env logger with custom format, using stdout as target
#[no_mangle]
pub extern "C" fn ccxr_init_logger() {
Expand Down Expand Up @@ -281,8 +285,11 @@ pub unsafe extern "C" fn ccxr_parse_parameters(argc: c_int, argv: *mut *mut c_ch
);
tlt_config = _tlt_config.to_ctype(&opt);

// Convert the rust struct (CcxOptions) to C struct (ccx_s_options), so that it can be used by the C code
ccx_options.copy_from_rust(opt);
// Lock the mutex before modifying ccx_options
{
let mut ccx_options = CCX_OPTIONS.lock().unwrap();
ccx_options.copy_from_rust(opt);
}

if !_capitalization_list.is_empty() {
capitalization_list = _capitalization_list.to_ctype();
Expand Down

0 comments on commit 568cc22

Please sign in to comment.