Skip to content

Commit

Permalink
Some locking fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmiel committed Sep 22, 2024
1 parent aee1e51 commit 2bd464f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
1 change: 0 additions & 1 deletion cykusz-rs/src/kernel/sched/round_robin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use alloc::sync::Arc;
use core::ptr::{addr_of, addr_of_mut};
use intrusive_collections::LinkedList;

use crate::arch::int;
Expand Down
8 changes: 4 additions & 4 deletions cykusz-rs/src/kernel/sync/spin_rw_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<T> RwSpin<T> {
}

pub fn read(&self) -> RwSpinReadGuard<T> {
let notify = self.maybe_preempt_disable();
let notify = self.notify && self.maybe_preempt_disable();

RwSpinReadGuard {
g: Some(self.l.read()),
Expand All @@ -128,7 +128,7 @@ impl<T> RwSpin<T> {
}

pub fn read_upgradeable(&self) -> RwSpinUpgradeableGuard<T> {
let notify = self.maybe_preempt_disable();
let notify = self.notify && self.maybe_preempt_disable();
RwSpinUpgradeableGuard {
g: Some(self.l.upgradeable_read()),
irq: false,
Expand All @@ -147,7 +147,7 @@ impl<T> RwSpin<T> {
}

pub fn try_read(&self) -> Option<RwSpinReadGuard<T>> {
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),
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<T> RwSpin<T> {
}

pub fn try_read_upgradeable(&self) -> Option<RwSpinUpgradeableGuard<T>> {
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),
Expand Down
14 changes: 11 additions & 3 deletions cykusz-rs/src/kernel/utils/wait_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -155,12 +159,16 @@ impl WaitQueue {
flags: WaitQueueFlags,
mut cond: F,
) -> SignalResult<Option<()>> {
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);
Expand Down

0 comments on commit 2bd464f

Please sign in to comment.