From 7c91c2c35a8558b7744f54d10bb5e040ec870768 Mon Sep 17 00:00:00 2001 From: Quincy Date: Tue, 3 Sep 2024 10:25:40 +0800 Subject: [PATCH] fix: 1. fix example. 2. export read_tsc. --- .github/workflows/ci.yaml | 4 ++++ examples/tsc_example.rs | 2 +- src/lib.rs | 2 +- src/tscns.rs | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e557b93..be6ce9a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -22,7 +22,11 @@ jobs: uses: dtolnay/rust-toolchain@stable with: toolchain: nightly + - name: Build example + run: cargo build -r --example=tsc_example --verbose - name: Run tests run: cargo test --verbose - name: Run bench run: cargo +nightly bench --verbose + - name: Run example + run: ./target/release/examples/tsc_example diff --git a/examples/tsc_example.rs b/examples/tsc_example.rs index f6ff53d..1684d73 100644 --- a/examples/tsc_example.rs +++ b/examples/tsc_example.rs @@ -5,7 +5,7 @@ use tscns::{CALIBRATE_INTERVAL_NANOS, INIT_CALIBRATE_NANOS}; pub struct TscTime; impl TscTime { - pub fn now(&self) -> u64 { + pub fn now(&self) -> i64 { tscns::read_nanos() } } diff --git a/src/lib.rs b/src/lib.rs index 0f3f528..c4b316c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ mod tscns; pub use tscns::{ - read_nanos, calibrate, init, get_tsc_ghz, INIT_CALIBRATE_NANOS, CALIBRATE_INTERVAL_NANOS, + read_nanos, read_tsc, calibrate, init, get_tsc_ghz, INIT_CALIBRATE_NANOS, CALIBRATE_INTERVAL_NANOS, }; diff --git a/src/tscns.rs b/src/tscns.rs index 59a1d6d..66a3868 100644 --- a/src/tscns.rs +++ b/src/tscns.rs @@ -68,8 +68,8 @@ pub fn init(init_calibrate_ns: i64, calibrate_interval_ns: i64) { /// println!("now ns: {}", ns); /// ``` #[inline(always)] -pub fn read_nanos() -> u64 { - tsc2ns(read_tsc()) as u64 +pub fn read_nanos() -> i64 { + tsc2ns(read_tsc()) } @@ -220,7 +220,7 @@ fn sync_time() -> (i64, i64) { /// Read tsc count, support x86_64 and aarch64 architecture cpu #[inline(always)] -fn read_tsc() -> i64 { +pub fn read_tsc() -> i64 { #[cfg(target_arch = "x86_64")] unsafe { std::arch::x86_64::_rdtsc() as i64