From b0bcd82ba7372be652e31cfd1c0103ec3980d8bd Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 6 Feb 2016 17:10:44 -0600 Subject: [PATCH] x86: Replace explict references to g_readytorun with indirect references via the this_task() macro --- arch/x86/src/common/up_assert.c | 12 ++++-------- arch/x86/src/common/up_blocktask.c | 14 +++++++------- arch/x86/src/common/up_exit.c | 4 ++-- arch/x86/src/common/up_releasepending.c | 12 ++++++------ arch/x86/src/common/up_reprioritizertr.c | 12 ++++++------ arch/x86/src/common/up_unblocktask.c | 12 ++++++------ arch/x86/src/i486/up_schedulesigaction.c | 6 +++--- arch/x86/src/i486/up_sigdeliver.c | 2 +- 8 files changed, 35 insertions(+), 39 deletions(-) diff --git a/arch/x86/src/common/up_assert.c b/arch/x86/src/common/up_assert.c index 0e4761c2bc2..83026e4f07f 100644 --- a/arch/x86/src/common/up_assert.c +++ b/arch/x86/src/common/up_assert.c @@ -89,10 +89,6 @@ # define CONFIG_PRINT_TASKNAME 1 #endif -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -150,7 +146,7 @@ static int assert_tracecallback(FAR struct usbtrace_s *trace, FAR void *arg) #ifdef CONFIG_ARCH_STACKDUMP static void up_dumpstate(void) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); uint32_t sp = up_getsp(); uint32_t ustackbase; uint32_t ustacksize; @@ -255,7 +251,7 @@ static void _up_assert(int errorcode) { /* Are we in an interrupt handler or the idle task? */ - if (current_regs || ((struct tcb_s*)g_readytorun.head)->pid == 0) + if (current_regs || (this_task())->pid == 0) { (void)irqsave(); for (;;) @@ -285,7 +281,7 @@ static void _up_assert(int errorcode) void up_assert(const uint8_t *filename, int lineno) { #ifdef CONFIG_PRINT_TASKNAME - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); #endif board_autoled_on(LED_ASSERTION); @@ -301,7 +297,7 @@ void up_assert(const uint8_t *filename, int lineno) up_dumpstate(); #ifdef CONFIG_BOARD_CRASHDUMP - board_crashdump(up_getsp(), g_readytorun.head, filename, lineno); + board_crashdump(up_getsp(), this_task(), filename, lineno); #endif _up_assert(EXIT_FAILURE); diff --git a/arch/x86/src/common/up_blocktask.c b/arch/x86/src/common/up_blocktask.c index 16d4f03557f..86163650c68 100644 --- a/arch/x86/src/common/up_blocktask.c +++ b/arch/x86/src/common/up_blocktask.c @@ -75,7 +75,7 @@ void up_block_task(struct tcb_s *tcb, tstate_t task_state) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); bool switch_needed; /* Verify that the context switch can be performed */ @@ -96,7 +96,7 @@ void up_block_task(struct tcb_s *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 + /* If there are any pending tasks, then add them to the ready-to-run * task list now */ @@ -124,10 +124,10 @@ void up_block_task(struct tcb_s *tcb, tstate_t task_state) up_savestate(rtcb->xcp.regs); /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); /* Reset scheduler parameters */ @@ -141,17 +141,17 @@ void up_block_task(struct tcb_s *tcb, tstate_t task_state) } /* 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 + * ready-to-run 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. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously diff --git a/arch/x86/src/common/up_exit.c b/arch/x86/src/common/up_exit.c index 7c7af45a56f..cac16ba84f0 100644 --- a/arch/x86/src/common/up_exit.c +++ b/arch/x86/src/common/up_exit.c @@ -146,7 +146,7 @@ void _exit(int status) (void)irqsave(); - slldbg("TCB=%p exiting\n", g_readytorun.head); + slldbg("TCB=%p exiting\n", this_task()); #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) slldbg("Other tasks:\n"); @@ -161,7 +161,7 @@ void _exit(int status) * head of the list. */ - tcb = (struct tcb_s*)g_readytorun.head; + tcb = this_task(); #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously running diff --git a/arch/x86/src/common/up_releasepending.c b/arch/x86/src/common/up_releasepending.c index 1df0a61a9bd..aa824c0fc93 100644 --- a/arch/x86/src/common/up_releasepending.c +++ b/arch/x86/src/common/up_releasepending.c @@ -65,11 +65,11 @@ void up_release_pending(void) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); slldbg("From TCB=%p\n", rtcb); - /* Merge the g_pendingtasks list into the g_readytorun task list */ + /* Merge the g_pendingtasks list into the ready-to-run task list */ /* sched_lock(); */ if (sched_mergepending()) @@ -93,10 +93,10 @@ void up_release_pending(void) up_savestate(rtcb->xcp.regs); /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); /* Update scheduler parameters */ @@ -118,10 +118,10 @@ void up_release_pending(void) else if (!up_saveusercontext(rtcb->xcp.regs)) { /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously diff --git a/arch/x86/src/common/up_reprioritizertr.c b/arch/x86/src/common/up_reprioritizertr.c index 21748fdca28..652254a9806 100644 --- a/arch/x86/src/common/up_reprioritizertr.c +++ b/arch/x86/src/common/up_reprioritizertr.c @@ -92,7 +92,7 @@ void up_reprioritize_rtr(struct tcb_s *tcb, uint8_t priority) } else { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); bool switch_needed; slldbg("TCB=%p PRI=%d\n", tcb, priority); @@ -147,10 +147,10 @@ void up_reprioritize_rtr(struct tcb_s *tcb, uint8_t priority) up_savestate(rtcb->xcp.regs); /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); /* Update scheduler parameters */ @@ -164,17 +164,17 @@ void up_reprioritize_rtr(struct tcb_s *tcb, uint8_t priority) } /* Copy the exception context into the TCB at the (old) head of the - * g_readytorun Task list. if up_saveusercontext returns a non-zero + * ready-to-run 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. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously diff --git a/arch/x86/src/common/up_unblocktask.c b/arch/x86/src/common/up_unblocktask.c index fab5bbe11f1..1effafdd0e3 100644 --- a/arch/x86/src/common/up_unblocktask.c +++ b/arch/x86/src/common/up_unblocktask.c @@ -70,7 +70,7 @@ void up_unblock_task(struct tcb_s *tcb) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); /* Verify that the context switch can be performed */ @@ -82,7 +82,7 @@ void up_unblock_task(struct tcb_s *tcb) sched_removeblocked(tcb); /* Add the task in the correct location in the prioritized - * g_readytorun task list + * ready-to-run task list */ if (sched_addreadytorun(tcb)) @@ -106,10 +106,10 @@ void up_unblock_task(struct tcb_s *tcb) up_savestate(rtcb->xcp.regs); /* Restore the exception context of the rtcb at the (new) head - * of the g_readytorun task list. + * of the ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); /* Update scheduler parameters */ @@ -132,10 +132,10 @@ void up_unblock_task(struct tcb_s *tcb) { /* Restore the exception context of the new task that is ready to * run (probably tcb). This is the new rtcb at the head of the - * g_readytorun task list. + * ready-to-run task list. */ - rtcb = (struct tcb_s*)g_readytorun.head; + rtcb = this_task(); #ifdef CONFIG_ARCH_ADDRENV /* Make sure that the address environment for the previously diff --git a/arch/x86/src/i486/up_schedulesigaction.c b/arch/x86/src/i486/up_schedulesigaction.c index 8d6b03213f0..f4732a4daf2 100644 --- a/arch/x86/src/i486/up_schedulesigaction.c +++ b/arch/x86/src/i486/up_schedulesigaction.c @@ -114,9 +114,9 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * to the currently executing task. */ - sdbg("rtcb=0x%p current_regs=0x%p\n", g_readytorun.head, current_regs); + sdbg("rtcb=0x%p current_regs=0x%p\n", this_task(), current_regs); - if (tcb == (struct tcb_s*)g_readytorun.head) + if (tcb == this_task()) { /* CASE 1: We are not in an interrupt handler and a task is * signalling itself for some reason. @@ -137,7 +137,7 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver) * 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 current_regs does not refer to - * the thread at g_readytorun.head! + * the thread of this_task()! */ else diff --git a/arch/x86/src/i486/up_sigdeliver.c b/arch/x86/src/i486/up_sigdeliver.c index ddc87e08d85..b909c2e4525 100644 --- a/arch/x86/src/i486/up_sigdeliver.c +++ b/arch/x86/src/i486/up_sigdeliver.c @@ -82,7 +82,7 @@ void up_sigdeliver(void) { - struct tcb_s *rtcb = (struct tcb_s*)g_readytorun.head; + struct tcb_s *rtcb = this_task(); uint32_t regs[XCPTCONTEXT_REGS]; sig_deliver_t sigdeliver;