Skip to content

Commit

Permalink
Fall back to coarsetime (#32)
Browse files Browse the repository at this point in the history
* Fall back to coarsetime

Signed-off-by: Zhenchi <[email protected]>

* fix windows unstable

Signed-off-by: Zhenchi <[email protected]>

---------

Signed-off-by: Zhenchi <[email protected]>
  • Loading branch information
zhongzc authored Jan 23, 2024
1 parent 78ba6d5 commit 18bd3ea
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 116 deletions.
7 changes: 1 addition & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
ctor = "0.1.20"
coarsetime = "0.1"

[features]
atomic = []

[target.'cfg(not(target_os = "wasi"))'.dependencies]
libc = "0.2"

[target.'cfg(target_os = "wasi")'.dependencies]
wasi = "0.7"

[dev-dependencies]
criterion = "0.3"
quanta = "0.9"
Expand Down
103 changes: 0 additions & 103 deletions src/coarse_now.rs

This file was deleted.

20 changes: 13 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#![cfg_attr(docsrs, feature(doc_cfg))]

mod coarse_now;
mod instant;
#[cfg(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64")))]
mod tsc_now;
Expand Down Expand Up @@ -61,15 +60,22 @@ pub fn is_tsc_available() -> bool {

#[inline]
pub(crate) fn current_cycle() -> u64 {
let coarse_cycle = || {
let coarse = coarsetime::Instant::now_without_cache_update();
coarsetime::Duration::from_ticks(coarse.as_ticks()).as_nanos()
};

#[cfg(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64")))]
if is_tsc_available() {
tsc_now::current_cycle()
} else {
coarse_now::current_cycle()
{
if tsc_now::is_tsc_available() {
tsc_now::current_cycle()
} else {
coarse_cycle()
}
}
#[cfg(not(all(target_os = "linux", any(target_arch = "x86", target_arch = "x86_64"))))]
{
coarse_now::current_cycle()
coarse_cycle()
}
}

Expand Down Expand Up @@ -123,7 +129,7 @@ mod tests {
let duration_ns_std = std_instant.elapsed();

#[cfg(target_os = "windows")]
let expect_max_delta_ns = 20_000_000;
let expect_max_delta_ns = 40_000_000;
#[cfg(not(target_os = "windows"))]
let expect_max_delta_ns = 5_000_000;

Expand Down

0 comments on commit 18bd3ea

Please sign in to comment.