Skip to content

Commit

Permalink
DEBUG test if this pleases TSAN
Browse files Browse the repository at this point in the history
  • Loading branch information
Pehrsons committed Jun 25, 2024
1 parent 484b881 commit 52299fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,13 +674,19 @@ extern "C" fn audiounit_input_callback(

fn host_time_to_ns(host_time: u64) -> u64 {
static HOST_TIME_TO_NS_RATIO: OnceLock<(u32, u32)> = OnceLock::new();
let (num, den) = HOST_TIME_TO_NS_RATIO.get_or_init(|| {
let mut val = HOST_TIME_TO_NS_RATIO.get();
if val.is_none() {
// Slow path with extra get() because TSAN flags OnceLock as having a data race
// when dereferencing `num` below.
let mut timebase_info = mach_timebase_info { numer: 0, denom: 0 };
unsafe {
mach_timebase_info(&mut timebase_info);
}
(timebase_info.numer, timebase_info.denom)
});
let new_val = (timebase_info.numer, timebase_info.denom);
HOST_TIME_TO_NS_RATIO.set(new_val);
val = HOST_TIME_TO_NS_RATIO.get();
}
let (num, den) = val.unwrap();
let mut rv: f64 = host_time as f64;
rv *= *num as f64;
rv /= *den as f64;
Expand Down

0 comments on commit 52299fe

Please sign in to comment.