sched/signal: Optimize code logic

Adjust the up_schedule_sigaction function to facilitate subsequent spinlock optimization work.

Signed-off-by: wangzhi16 <wangzhi16@xiaomi.com>
This commit is contained in:
wangzhi16
2025-03-17 17:49:43 +08:00
committed by Xiang Xiao
parent 5775037da6
commit 364a633ec3
31 changed files with 436 additions and 1120 deletions
+13 -40
View File
@@ -83,53 +83,26 @@ void up_schedule_sigaction(struct tcb_s *tcb)
if (tcb == this_task())
{
/* CASE 1: We are not in an interrupt handler and a task is
* signalling itself for some reason.
/* Save the return lr and cpsr and one scratch register. These
* will be restored by the signal trampoline after the signals
* have been delivered.
*/
if (!up_current_regs())
{
/* In this case just deliver the signal now. */
tcb->xcp.saved_eip = up_current_regs()[REG_EIP];
tcb->xcp.saved_eflags = up_current_regs()[REG_EFLAGS];
(tcb->sigdeliver)(tcb);
tcb->sigdeliver = NULL;
}
/* CASE 2: We are in an interrupt handler AND the interrupted task
* is the same as the one that must receive the signal, then we
* will have to modify the return state as well as the state in the
* TCB.
*
* Hmmm... there looks like a latent bug here: The following logic
* would fail in the strange case where we are in an interrupt
* handler, the thread is signalling itself, but a context switch
* to another task has occurred so that g_current_regs does not
* refer to the thread of this_task()!
/* Then set up to vector to the trampoline with interrupts
* disabled
*/
else
{
/* Save the return lr and cpsr and one scratch register. These
* will be restored by the signal trampoline after the signals
* have been delivered.
*/
up_current_regs()[REG_EIP] = (uint32_t)x86_sigdeliver;
up_current_regs()[REG_EFLAGS] = 0;
tcb->xcp.saved_eip = up_current_regs()[REG_EIP];
tcb->xcp.saved_eflags = up_current_regs()[REG_EFLAGS];
/* And make sure that the saved context in the TCB
* is the same as the interrupt return context.
*/
/* Then set up to vector to the trampoline with interrupts
* disabled
*/
up_current_regs()[REG_EIP] = (uint32_t)x86_sigdeliver;
up_current_regs()[REG_EFLAGS] = 0;
/* And make sure that the saved context in the TCB
* is the same as the interrupt return context.
*/
x86_savestate(tcb->xcp.regs);
}
x86_savestate(tcb->xcp.regs);
}
/* Otherwise, we are (1) signaling a task is not running