Skip to content

Commit a9e59e6

Browse files
committed
Protect shared kcb->ticks with spinlock
Since kcb->ticks is shared and updated by all cores, add a spinlock to protect its increment operation in the dispatcher, ensuring atomicity and preventing race conditions in SMP environments.
1 parent 005eed5 commit a9e59e6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/task.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,11 @@ static int32_t noop_rtsched(void)
463463
/* The main entry point from the system tick interrupt. */
464464
void dispatcher(void)
465465
{
466+
uint32_t flag = 0;
467+
468+
spin_lock_irqsave(&kcb->kcb_lock, &flag);
466469
kcb->ticks++;
470+
spin_unlock_irqrestore(&kcb->kcb_lock, flag);
467471

468472
/* Handle time slice for current task */
469473
sched_tick_current_task();

0 commit comments

Comments
 (0)