From bdc9508bb6e227979045c5ba3937151635a32ec0 Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Wed, 9 Feb 2022 14:34:27 +0900 Subject: [PATCH 1/2] kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation --- library/std/src/sys/itron/condvar.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/library/std/src/sys/itron/condvar.rs b/library/std/src/sys/itron/condvar.rs index dac4b8abfc47f..84b0f4c866ab2 100644 --- a/library/std/src/sys/itron/condvar.rs +++ b/library/std/src/sys/itron/condvar.rs @@ -15,10 +15,12 @@ unsafe impl Sync for Condvar {} pub type MovableCondvar = Condvar; impl Condvar { + #[inline] pub const fn new() -> Condvar { Condvar { waiters: SpinMutex::new(waiter_queue::WaiterQueue::new()) } } + #[inline] pub unsafe fn init(&mut self) {} pub unsafe fn notify_one(&self) { @@ -206,7 +208,7 @@ mod waiter_queue { if let Some(mut insert_after) = insert_after { // Insert `waiter` after `insert_after` - let insert_before = insert_after.as_ref().prev; + let insert_before = insert_after.as_ref().next; waiter.prev = Some(insert_after); insert_after.as_mut().next = Some(waiter_ptr); @@ -214,6 +216,8 @@ mod waiter_queue { waiter.next = insert_before; if let Some(mut insert_before) = insert_before { insert_before.as_mut().prev = Some(waiter_ptr); + } else { + head.last = waiter_ptr; } } else { // Insert `waiter` to the front @@ -240,11 +244,11 @@ mod waiter_queue { match (waiter.prev, waiter.next) { (Some(mut prev), Some(mut next)) => { prev.as_mut().next = Some(next); - next.as_mut().next = Some(prev); + next.as_mut().prev = Some(prev); } (None, Some(mut next)) => { head.first = next; - next.as_mut().next = None; + next.as_mut().prev = None; } (Some(mut prev), None) => { prev.as_mut().next = None; @@ -271,6 +275,7 @@ mod waiter_queue { unsafe { waiter.as_ref().task != 0 } } + #[inline] pub fn pop_front(&mut self) -> Option { unsafe { let head = self.head.as_mut()?; From 1d180caf1a14b3316652fa856499e44abec393b2 Mon Sep 17 00:00:00 2001 From: Tomoaki Kawada Date: Thu, 10 Feb 2022 11:26:46 +0900 Subject: [PATCH 2/2] kmc-solid: Wait queue should be sorted in the descending order of task priorities In ITRON, lower priority values mean higher priorities. --- library/std/src/sys/itron/condvar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/itron/condvar.rs b/library/std/src/sys/itron/condvar.rs index 84b0f4c866ab2..2992a6a542901 100644 --- a/library/std/src/sys/itron/condvar.rs +++ b/library/std/src/sys/itron/condvar.rs @@ -192,7 +192,7 @@ mod waiter_queue { let insert_after = { let mut cursor = head.last; loop { - if waiter.priority <= cursor.as_ref().priority { + if waiter.priority >= cursor.as_ref().priority { // `cursor` and all previous waiters have the same or higher // priority than `current_task_priority`. Insert the new // waiter right after `cursor`.