Skip to content

Commit 6820e49

Browse files
committed
OS/ThreadX: Fix ready-thread handling around stack switch idle processing
- Do not use the local `rdy_thread` result while `PortThreadSwitch` is running on the interrupt stack after stack swap. - Reload the selected thread only after the task stack has been restored, so the scheduling flow matches the stack switching order. Signed-off-by: Huaqi Fang <578567190@qq.com>
1 parent d95ab0e commit 6820e49

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • OS/ThreadX/ports_smp/nuclei

OS/ThreadX/ports_smp/nuclei/port.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,13 @@ void PortThreadSwitch(void)
133133
rv_csr_t msubm = __RV_CSR_READ(CSR_MSUBM);
134134
__enable_irq();
135135
__RWMB();
136-
rdy_thread = _tx_find_ready_thread(TX_FALSE);
136+
/*
137+
* Do not touch the local rdy_thread result here.
138+
* After switching to the interrupt stack, let the scheduler helper
139+
* finish updating the execute pointer for this core, then reload the
140+
* chosen thread after the task stack is restored.
141+
*/
142+
_tx_find_ready_thread(TX_FALSE);
137143
/* disable interrupt to avoid interrupt nesting since new task handle found */
138144
__disable_irq();
139145
__RWMB();
@@ -148,6 +154,9 @@ void PortThreadSwitch(void)
148154
ECLIC_SetLevelIRQ(SysTimer_IRQn, KERNEL_INTERRUPT_PRIORITY);
149155
__RWMB();
150156
}
157+
__RWMB();
158+
/* Now the task stack is restored, so it is safe to reload rdy_thread. */
159+
rdy_thread = _tx_thread_execute_ptr[coreid];
151160
} else {
152161
rdy_thread = _tx_find_ready_thread(TX_FALSE);
153162
}

0 commit comments

Comments
 (0)