Commit 4382ba9c authored by Sven Liefgen's avatar Sven Liefgen
Browse files

Use SystemTime intead of Instant

Files of sender and receiver are combined, thus it is important to have
a timestamp that is relative to common anchor, UNIX_EPOCH in this case
parent 55e977b8
use std::time::Instant;
use std::time::SystemTime;
#[cfg(feature = "use-xlap")]
use std::{
convert::AsRef,
......@@ -50,7 +50,7 @@ include!(concat!(env!("OUT_DIR"), "/xlap_generated.rs"));
#[cfg(feature = "use-xlap")]
struct Timestamp {
c: u64,
t: Instant,
t: SystemTime,
}
#[cfg(feature = "use-xlap")]
......@@ -65,9 +65,6 @@ pub struct TimestampTable {
rows: [TimestampTableRow; TS_ROWS],
}
#[cfg(feature = "use-xlap")]
static mut ZERO: Option<Instant> = None;
#[macro_export]
/// Update the clock and cycle value of a timestamp by setting them to en explicit value
macro_rules! set_timestamp {
......@@ -81,7 +78,7 @@ macro_rules! set_timestamp {
#[cfg(feature = "use-xlap")]
#[inline(always)]
pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (Instant, u64)) {
pub unsafe fn set_timestamp(kind: Kind, row: usize, id: TimestampId, (t, c): (SystemTime, u64)) {
set_timestamp_clock(kind, row, id, t);
set_timestamp_cycle(kind, row, id, c);
}
......@@ -99,7 +96,7 @@ macro_rules! set_timestamp_clock {
#[cfg(feature = "use-xlap")]
#[inline(always)]
pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value: Instant) {
pub unsafe fn set_timestamp_clock(kind: Kind, row: usize, id: TimestampId, value: SystemTime) {
(*XLAP[kind as usize].load(Ordering::Acquire)).rows[row % TS_ROWS].timestamp[id as usize].t =
value;
}
......@@ -137,7 +134,7 @@ macro_rules! timestamp_clock {
#[inline(always)]
pub unsafe fn timestamp_clock(kind: Kind, row: usize, id: TimestampId) {
(*XLAP[kind as usize].load(Ordering::Acquire)).rows[row % TS_ROWS].timestamp[id as usize].t =
Instant::now();
SystemTime::now();
}
#[macro_export]
......@@ -167,8 +164,8 @@ macro_rules! get_timestamp_clock {
}
#[inline(always)]
pub fn get_timestamp_clock() -> Instant {
Instant::now()
pub fn get_timestamp_clock() -> SystemTime {
SystemTime::now()
}
#[macro_export]
......@@ -243,7 +240,6 @@ pub unsafe fn init() {
#[cfg(debug_assertions)] {
println!("Initialised XLAP with {} rows.", TS_ROWS)
}
ZERO = Some(Instant::now());
for ptr in XLAP.iter() {
// Create a zeroed Timestamp table
let table: TimestampTable = std::mem::zeroed();
......@@ -298,7 +294,7 @@ impl TimestampTable {
for (i, row) in table.rows.iter().enumerate().skip(1) {
write!(&mut file, "{}, {}", i, *kind as usize)?;
for timestamp in row.timestamp.iter() {
let t = timestamp.t.saturating_duration_since(ZERO.unwrap());
let t = timestamp.t.duration_since(SystemTime::UNIX_EPOCH).unwrap();
write!(&mut file, ", {}, {}", t.as_micros(), timestamp.c)?;
}
writeln!(&mut file)?;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment