Skip to content

Commit

Permalink
spinlock: add sched_lock to spin_lock_irqsave_wo_note
Browse files Browse the repository at this point in the history
reason:
We aim to replace big locks with smaller ones. So we will use spin_lock_irqsave extensively to
replace enter_critical_section in the subsequent process. We imitate the implementation of Linux
by adding sched_lock to spin_lock_irqsave in order to address scenarios where sem_post occurs
within spin_lock_irqsave, which can lead to spinlock failures and deadlocks.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Nov 4, 2024
1 parent a14fe67 commit 4cf1649
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/nuttx/spinlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ irqstate_t spin_lock_irqsave_wo_note(FAR volatile spinlock_t *lock)
while (!spin_trylock_irqsave_wo_note(lock, ret));
}

sched_lock_wo_note();
return ret;
}
#else
Expand Down Expand Up @@ -721,6 +722,7 @@ void spin_unlock_irqrestore_wo_note(FAR volatile spinlock_t *lock,
}

up_irq_restore(flags);
sched_unlock_wo_note();
}
#else
# define spin_unlock_irqrestore_wo_note(l, f) ((void)(l), up_irq_restore(f))
Expand Down

0 comments on commit 4cf1649

Please sign in to comment.