various fixes to the design of Poll

This commit is contained in:
Pat Hickey
2021-04-30 15:36:56 -07:00
parent b7efcbe80f
commit 7f34ccb909
5 changed files with 11 additions and 11 deletions

View File

@@ -22,7 +22,7 @@ impl SyncSched {
#[wiggle::async_trait] #[wiggle::async_trait]
impl WasiSched for SyncSched { impl WasiSched for SyncSched {
async fn poll_oneoff<'a>(&self, poll: &'a Poll<'a>) -> Result<(), Error> { async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error> {
if poll.is_empty() { if poll.is_empty() {
return Ok(()); return Ok(());
} }

View File

@@ -9,7 +9,7 @@ use subscription::{MonotonicClockSubscription, RwSubscription, Subscription, Sub
#[wiggle::async_trait] #[wiggle::async_trait]
pub trait WasiSched { pub trait WasiSched {
async fn poll_oneoff<'a>(&self, poll: &'a Poll<'a>) -> Result<(), Error>; async fn poll_oneoff<'a>(&self, poll: &mut Poll<'a>) -> Result<(), Error>;
async fn sched_yield(&self) -> Result<(), Error>; async fn sched_yield(&self) -> Result<(), Error>;
async fn sleep(&self, duration: Duration) -> Result<(), Error>; async fn sleep(&self, duration: Duration) -> Result<(), Error>;
} }
@@ -62,16 +62,16 @@ impl<'a> Poll<'a> {
self.subs self.subs
.push((Subscription::Write(RwSubscription::new(file)), ud)); .push((Subscription::Write(RwSubscription::new(file)), ud));
} }
pub fn results(&self) -> Vec<(SubscriptionResult, Userdata)> { pub fn results(self) -> Vec<(SubscriptionResult, Userdata)> {
self.subs self.subs
.iter() .into_iter()
.filter_map(|(s, ud)| SubscriptionResult::from_subscription(s).map(|r| (r, *ud))) .filter_map(|(s, ud)| SubscriptionResult::from_subscription(s).map(|r| (r, ud)))
.collect() .collect()
} }
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.subs.is_empty() self.subs.is_empty()
} }
pub fn earliest_clock_deadline(&'a self) -> Option<&MonotonicClockSubscription<'a>> { pub fn earliest_clock_deadline(&self) -> Option<&MonotonicClockSubscription<'a>> {
self.subs self.subs
.iter() .iter()
.filter_map(|(s, _ud)| match s { .filter_map(|(s, _ud)| match s {
@@ -80,8 +80,8 @@ impl<'a> Poll<'a> {
}) })
.min_by(|a, b| a.deadline.cmp(&b.deadline)) .min_by(|a, b| a.deadline.cmp(&b.deadline))
} }
pub fn rw_subscriptions(&'a self) -> impl Iterator<Item = &Subscription<'a>> { pub fn rw_subscriptions<'b>(&'b mut self) -> impl Iterator<Item = &'b mut Subscription<'a>> {
self.subs.iter().filter_map(|(s, _ud)| match s { self.subs.iter_mut().filter_map(|(s, _ud)| match s {
Subscription::Read { .. } | Subscription::Write { .. } => Some(s), Subscription::Read { .. } | Subscription::Write { .. } => Some(s),
_ => None, _ => None,
}) })

View File

@@ -69,7 +69,7 @@ pub enum SubscriptionResult {
} }
impl SubscriptionResult { impl SubscriptionResult {
pub fn from_subscription(s: &Subscription) -> Option<SubscriptionResult> { pub fn from_subscription(s: Subscription) -> Option<SubscriptionResult> {
match s { match s {
Subscription::Read(s) => s.result().map(SubscriptionResult::Read), Subscription::Read(s) => s.result().map(SubscriptionResult::Read),
Subscription::Write(s) => s.result().map(SubscriptionResult::Write), Subscription::Write(s) => s.result().map(SubscriptionResult::Write),

View File

@@ -849,7 +849,7 @@ impl wasi_unstable::WasiUnstable for WasiCtx {
} }
} }
self.sched.poll_oneoff(&poll).await?; self.sched.poll_oneoff(&mut poll).await?;
let results = poll.results(); let results = poll.results();
let num_results = results.len(); let num_results = results.len();

View File

@@ -1047,7 +1047,7 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
poll.subscribe_write(f.deref_mut(), *ud); poll.subscribe_write(f.deref_mut(), *ud);
} }
self.sched.poll_oneoff(&poll).await?; self.sched.poll_oneoff(&mut poll).await?;
let results = poll.results(); let results = poll.results();
let num_results = results.len(); let num_results = results.len();