diff --git a/base/src/lib.rs b/base/src/lib.rs index 1c98145d79..9a7a717d89 100644 --- a/base/src/lib.rs +++ b/base/src/lib.rs @@ -10,6 +10,7 @@ pub mod external_mapping; mod notifiers; pub mod scoped_event_macro; pub mod syslog; +mod timer; mod tube; pub mod sys; @@ -20,6 +21,7 @@ pub use errno::{errno_result, Error, Result}; pub use external_mapping::{Error as ExternalMappingError, Result as ExternalMappingResult, *}; pub use notifiers::*; pub use scoped_event_macro::*; +pub use timer::{FakeTimer, Timer}; pub use tube::{Error as TubeError, RecvTube, Result as TubeResult, SendTube, Tube}; cfg_if::cfg_if! { @@ -28,7 +30,6 @@ cfg_if::cfg_if! { mod ioctl; mod mmap; mod shm; - mod timer; mod wait_context; pub use sys::unix; @@ -44,7 +45,6 @@ cfg_if::cfg_if! { MemoryMapping, MemoryMappingBuilder, MemoryMappingBuilderUnix, Unix as MemoryMappingUnix, }; pub use shm::{SharedMemory, Unix as SharedMemoryUnix}; - pub use timer::{FakeTimer, Timer}; pub use wait_context::{EventToken, EventType, TriggeredEvent, WaitContext}; } else if #[cfg(windows)] { pub use tube::{deserialize_and_recv, serialize_and_send, set_duplicate_handle_tube, set_alias_pid, DuplicateHandleTube}; diff --git a/base/src/sys/windows/mod.rs b/base/src/sys/windows/mod.rs index 3f91f93fd9..d7541eb10d 100644 --- a/base/src/sys/windows/mod.rs +++ b/base/src/sys/windows/mod.rs @@ -36,6 +36,7 @@ mod priority; mod sched; mod shm; mod stream_channel; +mod timer; pub mod thread; @@ -61,6 +62,7 @@ pub use priority::*; pub use sched::*; pub use shm::*; pub use stream_channel::*; +pub use timer::*; pub use win::*; pub use file_traits::{ diff --git a/base/src/sys/windows/win/timer.rs b/base/src/sys/windows/timer.rs similarity index 92% rename from base/src/sys/windows/win/timer.rs rename to base/src/sys/windows/timer.rs index 6d9e5a0363..e8efad098f 100644 --- a/base/src/sys/windows/win/timer.rs +++ b/base/src/sys/windows/timer.rs @@ -17,11 +17,11 @@ use winapi::{ }, }; -use super::{ - super::{errno_result, win::nt_query_timer_resolution, Result}, - Timer, WaitResult, +use super::{errno_result, win::nt_query_timer_resolution, Result}; +use crate::{ + descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor}, + timer::{Timer, WaitResult}, }; -use crate::descriptor::{AsRawDescriptor, FromRawDescriptor, SafeDescriptor}; impl AsRawHandle for Timer { fn as_raw_handle(&self) -> RawHandle { @@ -110,7 +110,7 @@ impl Timer { /// /// If timeout is not None, block for a maximum of the given `timeout` duration. /// If a timeout occurs, return WaitResult::Timeout. - pub fn wait(&mut self, timeout: Option) -> Result { + pub fn wait_for(&mut self, timeout: Option) -> Result { let timeout = match timeout { None => INFINITE, Some(dur) => dur.as_millis() as u32, @@ -128,6 +128,12 @@ impl Timer { } } + /// Block for a maximum of the given `timeout` duration. + /// If a timeout occurs, return WaitResult::Timeout. + pub fn wait(&mut self) -> Result { + self.wait_for(None) + } + /// After a timer is triggered from an EventContext, mark the timer as having been waited for. /// If a timer is not marked waited, it will immediately trigger the event context again. This /// does not need to be called after calling Timer::wait.