Skip to content

Commit b32246e

Browse files
author
vatsalkeshav
committed
xds module : add setter function for TS_START_OF_XDS from C code
1 parent 885008b commit b32246e

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/lib_ccx/ccx_decoders_xds.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ extern void ccxr_do_end_of_xds(
1616
struct ccx_decoders_xds_context *ctx,
1717
unsigned char expected_checksum);
1818

19+
// declare setter function for TS_START_OF_XDS from C code
20+
extern void ccxr_set_ts_start_of_xds(long long value);
21+
1922
LLONG ts_start_of_xds = -1; // Time at which we switched to XDS mode, =-1 hasn't happened yet
2023

2124
static const char *XDSclasses[] =
@@ -907,6 +910,7 @@ int xds_do_misc(struct ccx_decoders_xds_context *ctx)
907910
void do_end_of_xds(struct cc_subtitle *sub, struct ccx_decoders_xds_context *ctx, unsigned char expected_checksum)
908911
{
909912
#ifndef DISABLE_RUST
913+
ccxr_set_ts_start_of_xds(ts_start_of_xds);
910914
ccxr_do_end_of_xds(sub, ctx, expected_checksum); // use the rust implementation
911915
return;
912916
#endif

src/rust/src/xds/handlers.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ use libc::malloc;
5151

5252
use crate::xds::types::*;
5353

54-
static TS_START_OF_XDS: AtomicI64 = AtomicI64::new(-1); // Time at which we switched to XDS mode, =-1 hasn't happened yet
55-
// Usage example:
56-
// TS_START_OF_XDS.store(new_value, Ordering::SeqCst);
57-
// let value = TS_START_OF_XDS.load(Ordering::SeqCst);
54+
pub static TS_START_OF_XDS: AtomicI64 = AtomicI64::new(-1); // Time at which we switched to XDS mode, =-1 hasn't happened yet
55+
// Usage example:
56+
// TS_START_OF_XDS.store(new_value, Ordering::SeqCst);
57+
// let value = TS_START_OF_XDS.load(Ordering::SeqCst);
5858

5959
/// Represents failures during XDS string writing or processing.
6060
pub enum XDSError {

src/rust/src/xds/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ pub mod types;
1717

1818
use crate::bindings::*;
1919
use crate::ctorust::FromCType;
20-
use crate::xds::handlers::do_end_of_xds;
20+
use crate::xds::handlers::{do_end_of_xds, TS_START_OF_XDS};
2121
use crate::xds::types::{copy_xds_context_from_rust_to_c, CcxDecodersXdsContext};
2222
use std::os::raw::c_int;
23+
use std::sync::atomic::Ordering;
2324

2425
/// FFI wrapper for `do_end_of_xds`.
2526
///
@@ -82,3 +83,9 @@ pub unsafe extern "C" fn ccxr_process_xds_bytes(
8283
// Write changes back to C
8384
copy_xds_context_from_rust_to_c(ctx, &rust_ctx);
8485
}
86+
87+
/// setter function for TS_START_OF_XDS from C code
88+
#[no_mangle]
89+
pub extern "C" fn ccxr_set_ts_start_of_xds(value: i64) {
90+
TS_START_OF_XDS.store(value, Ordering::SeqCst);
91+
}

0 commit comments

Comments
 (0)