mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-11 04:26:38 +00:00
base: move windows timer
Move and use windows timer. With this, windows base should export/test Timer/FakeTimer functionality. A series of patches move unix specific code into src/sys/unix/timer.rs, retain platform independent code in src/timer.rs and then introduces windows timer.rs. BUG=b:213153157 TEST=presubmit Change-Id: Icbd48756c270184395f0b324e9e1f49d564a929a Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3600761 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Dennis Kempin <denniskempin@google.com> Commit-Queue: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
parent
093fb570a9
commit
f0b1a5d112
3 changed files with 15 additions and 7 deletions
|
@ -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};
|
||||
|
|
|
@ -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::{
|
||||
|
|
|
@ -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<Duration>) -> Result<WaitResult> {
|
||||
pub fn wait_for(&mut self, timeout: Option<Duration>) -> Result<WaitResult> {
|
||||
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<WaitResult> {
|
||||
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.
|
Loading…
Reference in a new issue