Skip to content

Commit 1a1a209

Browse files
committed
OS: Fix task switch in task context
The task switch function in task context rt_hw_context_switch might not be switched due to higher level interrupt happened before software interrupt to switch context, in the higher level interrupt if it triggered switch interrupt in interrupt context, the task context will be messed up. want to switch TA -> TB : interrupt entered | In TA context now Interrupt triggered, want to switch to TC | Still in TA context, but it assumed in TB context software interrupt switch task, task switch TB -> TC, but actually it is still in TA context so TA's context is actually saved to TB's stack, which is not right. So we changed task switch here to use interrupt switch flow: want to switch TA -> TB, interrupt entered | in TA context now Interrupt triggered, want to switch to TC | still in TA context, but now it will do TA -> TC software interrupt switch tasl, now do TA -> TC, which is correct now In this case, it want to do two task switch, A->B, B->C, but accuatually only 1 task switch is done, A->C due to higher interrupt handler entered before software interrupt, and in higher interrupt handler, it also triggered task switch Signed-off-by: Huaqi Fang <[email protected]>
1 parent 94996b0 commit 1a1a209

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

OS/RTThread/libcpu/risc-v/nuclei/cpuport.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to)
122122

123123
void rt_hw_context_switch(rt_ubase_t from, rt_ubase_t to)
124124
{
125-
rt_interrupt_from_thread = from;
126-
rt_interrupt_to_thread = to;
127-
portYIELD();
125+
rt_hw_context_switch_interrupt(from, to);
128126
}
129127

130128
/** shutdown CPU */

0 commit comments

Comments
 (0)