base: add clear() to WaitContext as a platform specific extension

BUG=b:213153157
TEST=presubmit

Change-Id: I9f7c958834e9727acaba860600aecfbdc98fcdc0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3631414
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Vikram Auradkar 2022-05-06 22:02:14 +00:00 committed by Chromeos LUCI
parent 78a12954cf
commit c57fcc8ef2
2 changed files with 13 additions and 2 deletions

View file

@ -20,12 +20,23 @@ use winapi::{
use super::{errno_result, Error, Event, EventTrigger, PollToken, Result, TriggeredEvent};
use crate::descriptor::{AsRawDescriptor, Descriptor};
use crate::{error, EventType, RawDescriptor};
use crate::{error, EventToken, EventType, RawDescriptor, WaitContext};
// MAXIMUM_WAIT_OBJECTS = 64
pub const MAXIMUM_WAIT_OBJECTS: usize = winapi::um::winnt::MAXIMUM_WAIT_OBJECTS as usize;
// TODO(145170451) rizhang: implement round robin if event size is greater than 64
pub trait WaitContextExt {
/// Removes all handles registered in the WaitContext.
fn clear(&self) -> Result<()>;
}
impl<T: EventToken> WaitContextExt for WaitContext<T> {
fn clear(&self) -> Result<()> {
self.0.clear()
}
}
struct RegisteredHandles<T: PollToken> {
triggers: HashMap<Descriptor, T>,
raw_handles: Vec<Descriptor>,

View file

@ -87,7 +87,7 @@ pub enum EventType {
/// let _ = another_evt.read()?;
/// # Ok::<(), base::Error>(())
/// ```
pub struct WaitContext<T: EventToken>(EventContext<T>);
pub struct WaitContext<T: EventToken>(pub(crate) EventContext<T>);
impl<T: EventToken> WaitContext<T> {
/// Creates a new WaitContext.