diff options
Diffstat (limited to 'nuttx/arch/z80/src/common/up_blocktask.c')
-rw-r--r-- | nuttx/arch/z80/src/common/up_blocktask.c | 115 |
1 files changed, 55 insertions, 60 deletions
diff --git a/nuttx/arch/z80/src/common/up_blocktask.c b/nuttx/arch/z80/src/common/up_blocktask.c index 6a9f050aa..875c0602c 100644 --- a/nuttx/arch/z80/src/common/up_blocktask.c +++ b/nuttx/arch/z80/src/common/up_blocktask.c @@ -1,7 +1,7 @@ /**************************************************************************** * arch/z80/src/common/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 @@ -87,88 +87,83 @@ void up_block_task(FAR struct tcb_s *tcb, tstate_t task_state) { + FAR struct tcb_s *rtcb = (FAR 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 - { - FAR struct tcb_s *rtcb = (FAR struct tcb_s*)g_readytorun.head; - bool switch_needed; + ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) && + (tcb->task_state <= LAST_READY_TO_RUN_STATE)); - /* dbg("Blocking TCB=%p\n", tcb); */ + /* dbg("Blocking TCB=%p\n", 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. - */ + /* 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. + */ - switch_needed = sched_removereadytorun(tcb); + switch_needed = sched_removereadytorun(tcb); - /* Add the task to the specified blocked task list */ + /* Add the task to the specified blocked task list */ - sched_addblocked(tcb, (tstate_t)task_state); + sched_addblocked(tcb, (tstate_t)task_state); - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ + /* If there are any pending tasks, then add them to the g_readytorun + * task list now + */ - if (g_pendingtasks.head) - { - switch_needed |= sched_mergepending(); - } + 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) + { + /* Are we in an interrupt handler? */ + + if (IN_INTERRUPT()) { - /* Are we in an interrupt handler? */ + /* Yes, then we have to do things differently. + * Just copy the current registers into the OLD rtcb. + */ - if (IN_INTERRUPT()) - { - /* Yes, then we have to do things differently. - * Just copy the current registers into the OLD rtcb. - */ + SAVE_IRQCONTEXT(rtcb); - SAVE_IRQCONTEXT(rtcb); + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. + */ - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ + rtcb = (FAR struct tcb_s*)g_readytorun.head; + /* dbg("New Active Task TCB=%p\n", rtcb); */ - rtcb = (FAR struct tcb_s*)g_readytorun.head; - /* dbg("New Active Task TCB=%p\n", rtcb); */ + /* Then setup so that the context will be performed on exit + * from the interrupt. + */ - /* Then setup so that the context will be performed on exit - * from the interrupt. - */ + SET_IRQCONTEXT(rtcb); + } - SET_IRQCONTEXT(rtcb); - } + /* Copy the user C context into the TCB at the (old) head of the + * g_readytorun Task list. if SAVE_USERCONTEXT returns a non-zero + * value, then this is really the previously running task restarting! + */ - /* Copy the user C context into the TCB at the (old) head of the - * g_readytorun Task list. if SAVE_USERCONTEXT returns a non-zero - * value, then this is really the previously running task restarting! + else if (!SAVE_USERCONTEXT(rtcb)) + { + /* Restore the exception context of the rtcb at the (new) head + * of the g_readytorun task list. */ - else if (!SAVE_USERCONTEXT(rtcb)) - { - /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. - */ - - rtcb = (FAR struct tcb_s*)g_readytorun.head; - /* dbg("New Active Task TCB=%p\n", rtcb); */ + rtcb = (FAR struct tcb_s*)g_readytorun.head; + /* dbg("New Active Task TCB=%p\n", rtcb); */ - /* Then switch contexts */ + /* Then switch contexts */ - RESTORE_USERCONTEXT(rtcb); - } + RESTORE_USERCONTEXT(rtcb); } } } |