mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 18:03:25 +00:00
Rename cond()
to try_op()
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
50773de35f
commit
efd49a96e3
@ -247,28 +247,28 @@ pub trait Pollable {
|
|||||||
|
|
||||||
/// Waits for events and performs event-based operations.
|
/// Waits for events and performs event-based operations.
|
||||||
///
|
///
|
||||||
/// If a call to `cond()` succeeds or fails with an error code other than `EAGAIN`, the method
|
/// If a call to `try_op()` succeeds or fails with an error code other than `EAGAIN`, the
|
||||||
/// will return whatever the call to `cond()` returns. Otherwise, the method will wait for some
|
/// method will return whatever the call to `try_op()` returns. Otherwise, the method will wait
|
||||||
/// interesting events specified in `mask` to happen and try again.
|
/// for some interesting events specified in `mask` to happen and try again.
|
||||||
///
|
///
|
||||||
/// This method will fail with `ETIME` if the timeout is specified and the event does not occur
|
/// This method will fail with `ETIME` if the timeout is specified and the event does not occur
|
||||||
/// before the timeout expires.
|
/// before the timeout expires.
|
||||||
///
|
///
|
||||||
/// The user must ensure that a call to `cond()` does not fail with `EAGAIN` when the
|
/// The user must ensure that a call to `try_op()` does not fail with `EAGAIN` when the
|
||||||
/// interesting events occur. However, it is allowed to have spurious `EAGAIN` failures due to
|
/// interesting events occur. However, it is allowed to have spurious `EAGAIN` failures due to
|
||||||
/// race conditions where the events are consumed by another thread.
|
/// race opitions where the events are consumed by another thread.
|
||||||
fn wait_events<F, R>(
|
fn wait_events<F, R>(
|
||||||
&self,
|
&self,
|
||||||
mask: IoEvents,
|
mask: IoEvents,
|
||||||
timeout: Option<&Duration>,
|
timeout: Option<&Duration>,
|
||||||
mut cond: F,
|
mut try_op: F,
|
||||||
) -> Result<R>
|
) -> Result<R>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
F: FnMut() -> Result<R>,
|
F: FnMut() -> Result<R>,
|
||||||
{
|
{
|
||||||
// Fast path: Return immediately if the operation gives a result.
|
// Fast path: Return immediately if the operation gives a result.
|
||||||
match cond() {
|
match try_op() {
|
||||||
Err(err) if err.error() == Errno::EAGAIN => (),
|
Err(err) if err.error() == Errno::EAGAIN => (),
|
||||||
result => return result,
|
result => return result,
|
||||||
}
|
}
|
||||||
@ -286,7 +286,7 @@ pub trait Pollable {
|
|||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Try again after the event happens.
|
// Try again after the event happens.
|
||||||
match cond() {
|
match try_op() {
|
||||||
Err(err) if err.error() == Errno::EAGAIN => (),
|
Err(err) if err.error() == Errno::EAGAIN => (),
|
||||||
result => return result,
|
result => return result,
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user