Skip to content

Commit

Permalink
[refactor] rename ax_wait_queue_wait_cond to ax_wait_queue_wait
Browse files Browse the repository at this point in the history
  • Loading branch information
hky1999 committed Oct 16, 2024
1 parent e6997d1 commit b0ca613
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
17 changes: 13 additions & 4 deletions api/arceos_api/src/imp/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,20 @@ cfg_task! {
}
}

pub fn ax_wait_queue_wait(wq: &AxWaitQueueHandle) {
wq.0.wait()
pub fn ax_wait_queue_wait(wq: &AxWaitQueueHandle, timeout: Option<Duration>) -> bool {
#[cfg(feature = "irq")]
if let Some(dur) = timeout {
return wq.0.wait_timeout(dur);
}

if timeout.is_some() {
axlog::warn!("ax_wait_queue_wait: the `timeout` argument is ignored without the `irq` feature");
}
wq.0.wait();
false
}

pub fn ax_wait_queue_wait_cond(
pub fn ax_wait_queue_wait_until(
wq: &AxWaitQueueHandle,
until_condition: impl Fn() -> bool,
timeout: Option<Duration>,
Expand All @@ -111,7 +120,7 @@ cfg_task! {
}

if timeout.is_some() {
axlog::warn!("ax_wait_queue_wait_cond: the `timeout` argument is ignored without the `irq` feature");
axlog::warn!("ax_wait_queue_wait_until: the `timeout` argument is ignored without the `irq` feature");
}
wq.0.wait_until(until_condition);
false
Expand Down
7 changes: 4 additions & 3 deletions api/arceos_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ pub mod task {
/// Sets the cpu affinity of the current task.
pub fn ax_set_current_affinity(cpumask: AxCpuMask) -> crate::AxResult;
/// Blocks the current task and put it into the wait queue, until
/// other tasks notify the wait queue.
pub fn ax_wait_queue_wait(wq: &AxWaitQueueHandle);
/// other tasks notify the wait queue, or the the given duration has
/// elapsed (if specified).
pub fn ax_wait_queue_wait(wq: &AxWaitQueueHandle, timeout: Option<core::time::Duration>) -> bool;
/// Blocks the current task and put it into the wait queue, until the
/// given condition becomes true, or the the given duration has elapsed
/// (if specified).
pub fn ax_wait_queue_wait_cond(
pub fn ax_wait_queue_wait_until(
wq: &AxWaitQueueHandle,
until_condition: impl Fn() -> bool,
timeout: Option<core::time::Duration>,
Expand Down
2 changes: 1 addition & 1 deletion ulib/axstd/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<T: ?Sized> Mutex<T> {
current_id,
);
// Wait until the lock looks unlocked before retrying
api::ax_wait_queue_wait_cond(&self.wq, || !self.is_locked(), None);
api::ax_wait_queue_wait_until(&self.wq, || !self.is_locked(), None);
}
}
}
Expand Down

0 comments on commit b0ca613

Please sign in to comment.