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

Calculate the duration when timeout is absolute #4682

Merged
merged 1 commit into from
May 14, 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
1 change: 1 addition & 0 deletions lib/wasix/src/syscalls/wasi/clock_time_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::syscalls::*;
/// - `Timestamp *time`
/// The value of the clock in nanoseconds
//#[instrument(level = "trace", skip_all, fields(?clock_id, %precision), ret)]
#[instrument(level = "trace", skip_all, ret)]
pub fn clock_time_get<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
clock_id: Snapshot0Clockid,
Expand Down
21 changes: 19 additions & 2 deletions lib/wasix/src/syscalls/wasi/poll_oneoff.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use serde::{Deserialize, Serialize};
use wasmer_wasix_types::wasi::{SubscriptionClock, Userdata};
use wasmer_wasix_types::wasi::{Subclockflags, SubscriptionClock, Userdata};

use super::*;
use crate::{
Expand Down Expand Up @@ -299,7 +299,24 @@ where
time_to_sleep = Duration::ZERO;
clock_subs.push((clock_info, s.userdata));
} else {
time_to_sleep = Duration::from_nanos(clock_info.timeout);
// if the timeout is specified as an absolute time in the future,
// we should calculate the duration we need to sleep
time_to_sleep = if clock_info
.flags
.contains(Subclockflags::SUBSCRIPTION_CLOCK_ABSTIME)
{
let now = wasi_try_ok!(platform_clock_time_get(
Snapshot0Clockid::Monotonic,
1
)) as u64;

Duration::from_nanos(clock_info.timeout)
- Duration::from_nanos(now as u64)
} else {
// if the timeout is not absolute, just use it as duration
Duration::from_nanos(clock_info.timeout)
};

clock_subs.push((clock_info, s.userdata));
}
continue;
Expand Down
Loading