summaryrefslogtreecommitdiff
path: root/nuttx/arch/x86/src/common/up_blocktask.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/arch/x86/src/common/up_blocktask.c')
-rw-r--r--nuttx/arch/x86/src/common/up_blocktask.c107
1 files changed, 51 insertions, 56 deletions
diff --git a/nuttx/arch/x86/src/common/up_blocktask.c b/nuttx/arch/x86/src/common/up_blocktask.c
index b1653f1e4..dba388cb0 100644
--- a/nuttx/arch/x86/src/common/up_blocktask.c
+++ b/nuttx/arch/x86/src/common/up_blocktask.c
@@ -1,7 +1,7 @@
/****************************************************************************
* arch/x86/src/common/up_blocktask.c
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -85,82 +85,77 @@
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;
-
- /* 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.
- */
+ ASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) &&
+ (tcb->task_state <= LAST_READY_TO_RUN_STATE));
- 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
+ */
- /* Now, perform the context switch if one is needed */
+ if (g_pendingtasks.head)
+ {
+ switch_needed |= sched_mergepending();
+ }
- if (switch_needed)
+ /* Now, perform the context switch if one is needed */
+
+ if (switch_needed)
+ {
+ /* Are we in an interrupt handler? */
+
+ if (current_regs)
{
- /* Are we in an interrupt handler? */
+ /* Yes, then we have to do things differently.
+ * Just copy the current_regs into the OLD rtcb.
+ */
- if (current_regs)
- {
- /* Yes, then we have to do things differently.
- * Just copy the current_regs into the OLD rtcb.
- */
+ up_savestate(rtcb->xcp.regs);
- up_savestate(rtcb->xcp.regs);
+ /* 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 = (struct tcb_s*)g_readytorun.head;
- rtcb = (struct tcb_s*)g_readytorun.head;
+ /* Then switch contexts */
- /* Then switch contexts */
+ up_restorestate(rtcb->xcp.regs);
+ }
- up_restorestate(rtcb->xcp.regs);
- }
+ /* Copy the user C context into the TCB at the (old) head of the
+ * g_readytorun Task list. if up_saveusercontext 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 up_saveusercontext returns a non-zero
- * value, then this is really the previously running task restarting!
+ else if (!up_saveusercontext(rtcb->xcp.regs))
+ {
+ /* Restore the exception context of the rtcb at the (new) head
+ * of the g_readytorun task list.
*/
- else if (!up_saveusercontext(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;
+ rtcb = (struct tcb_s*)g_readytorun.head;
- /* Then switch contexts */
+ /* Then switch contexts */
- up_fullcontextrestore(rtcb->xcp.regs);
- }
+ up_fullcontextrestore(rtcb->xcp.regs);
}
}
}