mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-30 13:23:56 +00:00
Update spin lock users to lock_irq_disabled()
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
ba4121cd6a
commit
78de1af348
@ -35,7 +35,7 @@ impl RcuMonitor {
|
||||
// on the current CPU. If GP is complete, take the callbacks of the current
|
||||
// GP.
|
||||
let callbacks = {
|
||||
let mut state = self.state.lock();
|
||||
let mut state = self.state.lock_irq_disabled();
|
||||
if state.current_gp.is_complete() {
|
||||
return;
|
||||
}
|
||||
@ -69,7 +69,7 @@ impl RcuMonitor {
|
||||
where
|
||||
F: FnOnce() -> () + Send + 'static,
|
||||
{
|
||||
let mut state = self.state.lock();
|
||||
let mut state = self.state.lock_irq_disabled();
|
||||
|
||||
state.next_callbacks.push_back(Box::new(f));
|
||||
|
||||
|
@ -52,8 +52,8 @@ impl<T> SpinLock<T> {
|
||||
|
||||
/// Acquire the spin lock without disabling local IRQs.
|
||||
///
|
||||
/// This method is twice as fast as the `lock_irq_disable` method.
|
||||
/// So prefer using this method over the `lock_irq_disable` method
|
||||
/// This method is twice as fast as the `lock_irq_disabled` method.
|
||||
/// So prefer using this method over the `lock_irq_disabled` method
|
||||
/// when IRQ handlers are allowed to get executed while
|
||||
/// holding this lock. For example, if a lock is never used
|
||||
/// in the interrupt context, then it is ok to use this method
|
||||
@ -137,7 +137,7 @@ impl<'a, T: fmt::Debug> fmt::Debug for SpinLockIrqDisabledGuard<'a, T> {
|
||||
impl<'a, T> !Send for SpinLockIrqDisabledGuard<'a, T> {}
|
||||
|
||||
// Safety. `SpinLockIrqDisabledGuard` can be shared between tasks/threads in same CPU.
|
||||
// As `lock_irq_disable()` disables interrupts to prevent race conditions caused by interrupts.
|
||||
// As `lock_irq_disabled()` disables interrupts to prevent race conditions caused by interrupts.
|
||||
unsafe impl<T: Sync> Sync for SpinLockIrqDisabledGuard<'_, T> {}
|
||||
|
||||
pub struct SpinLockGuard<'a, T> {
|
||||
|
@ -53,14 +53,14 @@ impl WaitQueue {
|
||||
|
||||
/// Wake one waiter thread, if there is one.
|
||||
pub fn wake_one(&self) {
|
||||
if let Some(waiter) = self.waiters.lock().front() {
|
||||
if let Some(waiter) = self.waiters.lock_irq_disabled().front() {
|
||||
waiter.wake_up();
|
||||
}
|
||||
}
|
||||
|
||||
/// Wake all not-exclusive waiter threads and at most one exclusive waiter.
|
||||
pub fn wake_all(&self) {
|
||||
for waiter in self.waiters.lock().iter() {
|
||||
for waiter in self.waiters.lock_irq_disabled().iter() {
|
||||
waiter.wake_up();
|
||||
if waiter.is_exclusive() {
|
||||
break;
|
||||
@ -72,15 +72,15 @@ impl WaitQueue {
|
||||
// Otherwise, add to the front of waitqueue
|
||||
fn enqueue(&self, waiter: &Arc<Waiter>) {
|
||||
if waiter.is_exclusive() {
|
||||
self.waiters.lock().push_back(waiter.clone())
|
||||
self.waiters.lock_irq_disabled().push_back(waiter.clone())
|
||||
} else {
|
||||
self.waiters.lock().push_front(waiter.clone());
|
||||
self.waiters.lock_irq_disabled().push_front(waiter.clone());
|
||||
}
|
||||
}
|
||||
|
||||
/// removes all waiters that have finished wait
|
||||
fn finish_wait(&self) {
|
||||
self.waiters.lock().retain(|waiter| !waiter.is_finished())
|
||||
self.waiters.lock_irq_disabled().retain(|waiter| !waiter.is_finished())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user