diff options
Diffstat (limited to 'nuttx/arch/sim/src/up_blocktask.c')
-rw-r--r-- | nuttx/arch/sim/src/up_blocktask.c | 102 |
1 files changed, 49 insertions, 53 deletions
diff --git a/nuttx/arch/sim/src/up_blocktask.c b/nuttx/arch/sim/src/up_blocktask.c index 46598b442..db9701434 100644 --- a/nuttx/arch/sim/src/up_blocktask.c +++ b/nuttx/arch/sim/src/up_blocktask.c @@ -1,7 +1,7 @@ /**************************************************************************** * up_blocktask.c * - * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2013 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -86,75 +86,71 @@ void up_block_task(struct tcb_s *tcb, tstate_t task_state) { + struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + bool switch_needed; + /* 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; - sdbg("Blocking TCB=%p\n", tcb); + ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) && + (tcb->task_state <= LAST_READY_TO_RUN_STATE)); - /* 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. - */ + sdbg("Blocking TCB=%p\n", tcb); - switch_needed = sched_removereadytorun(tcb); + /* 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. + */ - /* Add the task to the specified blocked task list */ + switch_needed = sched_removereadytorun(tcb); - sched_addblocked(tcb, (tstate_t)task_state); + /* Add the task to the specified blocked task list */ - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ + sched_addblocked(tcb, (tstate_t)task_state); - if (g_pendingtasks.head) - { - switch_needed |= sched_mergepending(); - } + /* If there are any pending tasks, then add them to the g_readytorun + * task list now + */ + + if (g_pendingtasks.head) + { + switch_needed |= sched_mergepending(); + } - /* Now, perform the context switch if one is needed */ + /* Now, perform the context switch if one is needed */ - if (switch_needed) + if (switch_needed) + { + /* Copy the exception context into the TCB at the (old) head of the + * g_readytorun Task list. if up_setjmp returns a non-zero + * value, then this is really the previously running task restarting! + */ + + if (!up_setjmp(rtcb->xcp.regs)) { - /* Copy the exception context into the TCB at the (old) head of the - * g_readytorun Task list. if up_setjmp returns a non-zero - * value, then this is really the previously running task restarting! + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. */ - if (!up_setjmp(rtcb->xcp.regs)) - { - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (struct tcb_s*)g_readytorun.head; - sdbg("New Active Task TCB=%p\n", rtcb); + rtcb = (struct tcb_s*)g_readytorun.head; + sdbg("New Active Task TCB=%p\n", rtcb); - /* The way that we handle signals in the simulation is kind of - * a kludge. This would be unsafe in a truly multi-threaded, interrupt - * driven environment. - */ + /* The way that we handle signals in the simulation is kind of + * a kludge. This would be unsafe in a truly multi-threaded, interrupt + * driven environment. + */ - if (rtcb->xcp.sigdeliver) - { - sdbg("Delivering signals TCB=%p\n", rtcb); - ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb); - rtcb->xcp.sigdeliver = NULL; - } + if (rtcb->xcp.sigdeliver) + { + sdbg("Delivering signals TCB=%p\n", rtcb); + ((sig_deliver_t)rtcb->xcp.sigdeliver)(rtcb); + rtcb->xcp.sigdeliver = NULL; + } - /* Then switch contexts */ + /* Then switch contexts */ - up_longjmp(rtcb->xcp.regs, 1); - } + up_longjmp(rtcb->xcp.regs, 1); } } } |