diff --git a/api/arceos_api/src/imp/task.rs b/api/arceos_api/src/imp/task.rs index d34d6dbad9..9764bb1c00 100644 --- a/api/arceos_api/src/imp/task.rs +++ b/api/arceos_api/src/imp/task.rs @@ -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) -> 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, @@ -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 diff --git a/api/arceos_api/src/lib.rs b/api/arceos_api/src/lib.rs index 7263e0ba02..bf770028da 100644 --- a/api/arceos_api/src/lib.rs +++ b/api/arceos_api/src/lib.rs @@ -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) -> 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, diff --git a/ulib/axstd/src/sync/mutex.rs b/ulib/axstd/src/sync/mutex.rs index 140230a266..7ff0e32599 100644 --- a/ulib/axstd/src/sync/mutex.rs +++ b/ulib/axstd/src/sync/mutex.rs @@ -87,7 +87,7 @@ impl Mutex { 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); } } }