Skip to content

Commit 967b595

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 2c92431 commit 967b595

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
@@ -289,7 +289,11 @@ static int32_t noop_rtsched(void)
289289
/* The main entry point from the system tick interrupt. */
290290
void dispatcher(void)
291291
{
292+
uint32_t flag = 0;
293+
294+
spin_lock_irqsave(&kcb->kcb_lock, &flag);
292295
kcb->ticks++;
296+
spin_unlock_irqrestore(&kcb->kcb_lock, flag);
293297
_timer_tick_handler();
294298
_dispatch();
295299
}

0 commit comments

Comments
 (0)