Skip to content

Commit 7c91c2c

Browse files
author
Quincy
committed
fix: 1. fix example. 2. export read_tsc.
1 parent 3d4a75c commit 7c91c2c

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

.github/workflows/ci.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ jobs:
2222
uses: dtolnay/rust-toolchain@stable
2323
with:
2424
toolchain: nightly
25+
- name: Build example
26+
run: cargo build -r --example=tsc_example --verbose
2527
- name: Run tests
2628
run: cargo test --verbose
2729
- name: Run bench
2830
run: cargo +nightly bench --verbose
31+
- name: Run example
32+
run: ./target/release/examples/tsc_example

examples/tsc_example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tscns::{CALIBRATE_INTERVAL_NANOS, INIT_CALIBRATE_NANOS};
55
pub struct TscTime;
66

77
impl TscTime {
8-
pub fn now(&self) -> u64 {
8+
pub fn now(&self) -> i64 {
99
tscns::read_nanos()
1010
}
1111
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
mod tscns;
22

33
pub use tscns::{
4-
read_nanos, calibrate, init, get_tsc_ghz, INIT_CALIBRATE_NANOS, CALIBRATE_INTERVAL_NANOS,
4+
read_nanos, read_tsc, calibrate, init, get_tsc_ghz, INIT_CALIBRATE_NANOS, CALIBRATE_INTERVAL_NANOS,
55
};
66

src/tscns.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ pub fn init(init_calibrate_ns: i64, calibrate_interval_ns: i64) {
6868
/// println!("now ns: {}", ns);
6969
/// ```
7070
#[inline(always)]
71-
pub fn read_nanos() -> u64 {
72-
tsc2ns(read_tsc()) as u64
71+
pub fn read_nanos() -> i64 {
72+
tsc2ns(read_tsc())
7373
}
7474

7575

@@ -220,7 +220,7 @@ fn sync_time() -> (i64, i64) {
220220

221221
/// Read tsc count, support x86_64 and aarch64 architecture cpu
222222
#[inline(always)]
223-
fn read_tsc() -> i64 {
223+
pub fn read_tsc() -> i64 {
224224
#[cfg(target_arch = "x86_64")]
225225
unsafe {
226226
std::arch::x86_64::_rdtsc() as i64

0 commit comments

Comments
 (0)