diff options
Diffstat (limited to 'nuttx/arch/arm/src/armv6-m/up_blocktask.c')
-rw-r--r-- | nuttx/arch/arm/src/armv6-m/up_blocktask.c | 111 |
1 files changed, 53 insertions, 58 deletions
diff --git a/nuttx/arch/arm/src/armv6-m/up_blocktask.c b/nuttx/arch/arm/src/armv6-m/up_blocktask.c index a332cbefd..57db2b4aa 100644 --- a/nuttx/arch/arm/src/armv6-m/up_blocktask.c +++ b/nuttx/arch/arm/src/armv6-m/up_blocktask.c @@ -85,82 +85,77 @@ void up_block_task(struct tcb_s *tcb, tstate_t task_state) { - /* Verify that the context switch can be performed */ - - if ((tcb->task_state < FIRST_READY_TO_RUN_STATE) || - (tcb->task_state > LAST_READY_TO_RUN_STATE)) - { - PANIC(OSERR_BADBLOCKSTATE); - } - else - { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; - bool switch_needed; + struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + bool switch_needed; - /* Remove the tcb task from the ready-to-run list. If we - * are blocking the task at the head of the task list (the - * most likely case), then a context switch to the next - * ready-to-run task is needed. In this case, it should - * also be true that rtcb == tcb. - */ + /* Verify that the context switch can be performed */ - switch_needed = sched_removereadytorun(tcb); + ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) && + (tcb->task_state <= LAST_READY_TO_RUN_STATE)); - /* Add the task to the specified blocked task list */ + /* Remove the tcb task from the ready-to-run list. If we + * are blocking the task at the head of the task list (the + * most likely case), then a context switch to the next + * ready-to-run task is needed. In this case, it should + * also be true that rtcb == tcb. + */ - sched_addblocked(tcb, (tstate_t)task_state); + switch_needed = sched_removereadytorun(tcb); - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ + /* Add the task to the specified blocked task list */ - if (g_pendingtasks.head) - { - switch_needed |= sched_mergepending(); - } + sched_addblocked(tcb, (tstate_t)task_state); - /* Now, perform the context switch if one is needed */ + /* If there are any pending tasks, then add them to the g_readytorun + * task list now + */ - if (switch_needed) - { - /* Are we in an interrupt handler? */ + if (g_pendingtasks.head) + { + switch_needed |= sched_mergepending(); + } - if (current_regs) - { - /* Yes, then we have to do things differently. - * Just copy the current_regs into the OLD rtcb. - */ + /* Now, perform the context switch if one is needed */ - up_savestate(rtcb->xcp.regs); + if (switch_needed) + { + /* Are we in an interrupt handler? */ - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ + if (current_regs) + { + /* Yes, then we have to do things differently. + * Just copy the current_regs into the OLD rtcb. + */ - rtcb = (struct tcb_s*)g_readytorun.head; + up_savestate(rtcb->xcp.regs); - /* Then switch contexts */ + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ - up_restorestate(rtcb->xcp.regs); - } + rtcb = (struct tcb_s*)g_readytorun.head; - /* No, then we will need to perform the user context switch */ + /* Then switch contexts */ - else - { - /* Switch context to the context of the task at the head of the - * ready to run list. - */ + up_restorestate(rtcb->xcp.regs); + } - struct tcb_s *nexttcb = (struct tcb_s*)g_readytorun.head; - up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs); + /* No, then we will need to perform the user context switch */ - /* up_switchcontext forces a context switch to the task at the - * head of the ready-to-run list. It does not 'return' in the - * normal sense. When it does return, it is because the blocked - * task is again ready to run and has execution priority. - */ - } + else + { + /* Switch context to the context of the task at the head of the + * ready to run list. + */ + + struct tcb_s *nexttcb = (struct tcb_s*)g_readytorun.head; + up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs); + + /* up_switchcontext forces a context switch to the task at the + * head of the ready-to-run list. It does not 'return' in the + * normal sense. When it does return, it is because the blocked + * task is again ready to run and has execution priority. + */ } } } |