Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fall back to coarsetime #32

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading