Skip to content

Commit

Permalink
fix: 1. fix example. 2. export read_tsc.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quincy committed Sep 3, 2024
1 parent 3d4a75c commit 7c91c2c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion examples/tsc_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
};

6 changes: 3 additions & 3 deletions src/tscns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}


Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7c91c2c

Please sign in to comment.