From 2bd464fded8a98a9f967c37eb0d62311e9b7a97f Mon Sep 17 00:00:00 2001 From: Rafal Mielniczuk Date: Sun, 22 Sep 2024 22:30:37 +0100 Subject: [PATCH] Some locking fixes --- cykusz-rs/src/kernel/sched/round_robin.rs | 1 - cykusz-rs/src/kernel/sync/spin_rw_lock.rs | 8 ++++---- cykusz-rs/src/kernel/utils/wait_queue.rs | 14 +++++++++++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cykusz-rs/src/kernel/sched/round_robin.rs b/cykusz-rs/src/kernel/sched/round_robin.rs index faf9b88e..0550b3d8 100644 --- a/cykusz-rs/src/kernel/sched/round_robin.rs +++ b/cykusz-rs/src/kernel/sched/round_robin.rs @@ -1,5 +1,4 @@ use alloc::sync::Arc; -use core::ptr::{addr_of, addr_of_mut}; use intrusive_collections::LinkedList; use crate::arch::int; diff --git a/cykusz-rs/src/kernel/sync/spin_rw_lock.rs b/cykusz-rs/src/kernel/sync/spin_rw_lock.rs index 9153f953..36c58657 100644 --- a/cykusz-rs/src/kernel/sync/spin_rw_lock.rs +++ b/cykusz-rs/src/kernel/sync/spin_rw_lock.rs @@ -108,7 +108,7 @@ impl RwSpin { } pub fn read(&self) -> RwSpinReadGuard { - let notify = self.maybe_preempt_disable(); + let notify = self.notify && self.maybe_preempt_disable(); RwSpinReadGuard { g: Some(self.l.read()), @@ -128,7 +128,7 @@ impl RwSpin { } pub fn read_upgradeable(&self) -> RwSpinUpgradeableGuard { - let notify = self.maybe_preempt_disable(); + let notify = self.notify && self.maybe_preempt_disable(); RwSpinUpgradeableGuard { g: Some(self.l.upgradeable_read()), irq: false, @@ -147,7 +147,7 @@ impl RwSpin { } pub fn try_read(&self) -> Option> { - let notify = self.maybe_preempt_disable(); + let notify = self.notify && self.maybe_preempt_disable(); let lock = match self.l.try_read() { Some(l) => Some(l), @@ -196,7 +196,7 @@ impl RwSpin { } pub fn try_read_upgradeable(&self) -> Option> { - let notify = self.maybe_preempt_disable(); + let notify = self.notify && self.maybe_preempt_disable(); let lock = match self.l.try_upgradeable_read() { Some(l) => Some(l), diff --git a/cykusz-rs/src/kernel/utils/wait_queue.rs b/cykusz-rs/src/kernel/utils/wait_queue.rs index abc97afa..193089f6 100644 --- a/cykusz-rs/src/kernel/utils/wait_queue.rs +++ b/cykusz-rs/src/kernel/utils/wait_queue.rs @@ -111,7 +111,11 @@ impl WaitQueue { } pub fn wait(&self, flags: WaitQueueFlags) -> SignalResult<()> { - let _irq = IrqGuard::maybe_new(flags.contains(WaitQueueFlags::IRQ_DISABLE)); + let _irq = if flags.contains(WaitQueueFlags::IRQ_DISABLE) { + Some(IrqGuard::new()) + } else { + None + }; let task = current_task(); @@ -155,12 +159,16 @@ impl WaitQueue { flags: WaitQueueFlags, mut cond: F, ) -> SignalResult> { - let _irq = IrqGuard::maybe_new(flags.contains(WaitQueueFlags::IRQ_DISABLE)); - if !cond() && flags.contains(WaitQueueFlags::NO_HANG) { return Ok(None); } + let _irq = if flags.contains(WaitQueueFlags::IRQ_DISABLE) { + Some(IrqGuard::new()) + } else { + None + }; + let task = current_task(); let _guard = WaitQueueGuard::new(self, &task);