diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-01-30 18:49:31 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-01-30 18:49:31 +0000 |
commit | 013eef130f1bc2cab1e3f4022d8498fb98bb29bf (patch) | |
tree | a6455ca9fb6a1aaab3f305b1bf5e937bff704f59 | |
parent | 802ee953dd39863a9b296d8ffbfcc428f2d6fc4f (diff) | |
download | nuttx-013eef130f1bc2cab1e3f4022d8498fb98bb29bf.tar.gz nuttx-013eef130f1bc2cab1e3f4022d8498fb98bb29bf.tar.bz2 nuttx-013eef130f1bc2cab1e3f4022d8498fb98bb29bf.zip |
errno was clobbered by mm_trysemaphore when task exists
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@591 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/ChangeLog | 4 | ||||
-rw-r--r-- | nuttx/Documentation/NuttX.html | 6 | ||||
-rw-r--r-- | nuttx/arch/arm/src/common/up_exit.c | 49 | ||||
-rw-r--r-- | nuttx/arch/c5471/src/up_exit.c | 92 | ||||
-rw-r--r-- | nuttx/arch/dm320/src/up_exit.c | 87 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/src/up_exit.c | 74 | ||||
-rw-r--r-- | nuttx/arch/sim/src/up_exit.c | 74 | ||||
-rw-r--r-- | nuttx/arch/z16/src/common/up_exit.c | 45 | ||||
-rw-r--r-- | nuttx/arch/z80/src/common/up_exit.c | 45 | ||||
-rw-r--r-- | nuttx/include/nuttx/arch.h | 20 | ||||
-rw-r--r-- | nuttx/include/nuttx/sched.h | 16 | ||||
-rw-r--r-- | nuttx/sched/Makefile | 2 | ||||
-rw-r--r-- | nuttx/sched/get_errno_ptr.c | 70 | ||||
-rw-r--r-- | nuttx/sched/os_internal.h | 33 | ||||
-rw-r--r-- | nuttx/sched/task_delete.c | 65 | ||||
-rw-r--r-- | nuttx/sched/task_deletecurrent.c | 141 |
16 files changed, 396 insertions, 427 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index c812bf773..ad31d3683 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -306,4 +306,6 @@ * Add support for Windows native toolchains that cannot follow Cygwin soft links * Modified serial driver interface to handle hardware with non-16550A-like interrupt architecture (like the Z16F) - * Added a "dumb" serial console driver to simply OS bringup + * Added a "dumb" serial console driver to simplify OS bringup + * Corrected a bug that caused the errno value of one task to be clobbered + when a different task exits. Effects all architectures. diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html index 2c7d6531a..0fdeffaee 100644 --- a/nuttx/Documentation/NuttX.html +++ b/nuttx/Documentation/NuttX.html @@ -8,7 +8,7 @@ <tr align="center" bgcolor="#e4e4e4"> <td> <h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1> - <p>Last Updated: January 9, 2008</p> + <p>Last Updated: January 30, 2008</p> </td> </tr> </table> @@ -984,7 +984,9 @@ Other memory: * Add support for Windows native toolchains that cannot follow Cygwin soft links * Modified serial driver interface to handle hardware with non-16550A-like interrupt architecture (like the Z16F) - * Added a "dumb" serial console driver to simply OS bringup + * Added a "dumb" serial console driver to simplify OS bringup + * Corrected a bug that caused the errno value of one task to be clobbered + when a different task exits. Effects all architectures. </pre></ul> <table width ="100%"> diff --git a/nuttx/arch/arm/src/common/up_exit.c b/nuttx/arch/arm/src/common/up_exit.c index e760b00cf..2660ed80b 100644 --- a/nuttx/arch/arm/src/common/up_exit.c +++ b/nuttx/arch/arm/src/common/up_exit.c @@ -58,17 +58,16 @@ ****************************************************************************/ /**************************************************************************** - * Private Funtions + * Private Functions ****************************************************************************/ /**************************************************************************** * Name: _up_dumponexit * * Description: - * Dump the state of all tasks whenever on task exits. This - * is debug instrumentation that was added to check file- - * related reference counting but could be useful again - * sometime in the future. + * Dump the state of all tasks whenever on task exits. This is debug + * instrumentation that was added to check file-related reference counting + * but could be useful again sometime in the future. * ****************************************************************************/ @@ -133,13 +132,15 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * ****************************************************************************/ void _exit(int status) { - _TCB* tcb = (_TCB*)g_readytorun.head; + _TCB* tcb; /* Disable interrupts. They will be restored when the next * task is started. @@ -150,41 +151,13 @@ void _exit(int status) lldbg("TCB=%p exitting\n", tcb); #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) - dbg("Other tasks:\n"); + lldbg("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/arch/c5471/src/up_exit.c b/nuttx/arch/c5471/src/up_exit.c index 2ef47bdfb..4d117fce4 100644 --- a/nuttx/arch/c5471/src/up_exit.c +++ b/nuttx/arch/c5471/src/up_exit.c @@ -1,7 +1,7 @@ -/************************************************************ +/**************************************************************************** * up_exit.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> @@ -49,28 +49,27 @@ #include <nuttx/fs.h> #endif -/************************************************************ +/**************************************************************************** * Private Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Private Funtions - ************************************************************/ +/**************************************************************************** + * Private Functions + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: _up_dumponexit * * Description: - * Dump the state of all tasks whenever on task exits. This - * is debug instrumentation that was added to check file- - * related reference counting but could be useful again - * sometime in the future. + * Dump the state of all tasks whenever on task exits. This is debug + * instrumentation that was added to check file-related reference counting + * but could be useful again sometime in the future. * - ************************************************************/ + ****************************************************************************/ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) @@ -113,23 +112,30 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) } #endif -/************************************************************ - * Public Funtions - ************************************************************/ +/**************************************************************************** + * Public Functions + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: _exit * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * - ************************************************************/ + ****************************************************************************/ void _exit(int status) { - _TCB* tcb = (_TCB*)g_readytorun.head; - irqstate_t flags = irqsave(); + _TCB* tcb; + + /* Disable interrupts. They will be restored when the next + * task is started. + */ + + (void)irqsave(); lldbg("TCB=%p exitting\n", tcb); @@ -138,37 +144,9 @@ void _exit(int status) sched_foreach(_up_dumponexit, NULL); #endif - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/arch/dm320/src/up_exit.c b/nuttx/arch/dm320/src/up_exit.c index bb05b1c53..a95b8855b 100644 --- a/nuttx/arch/dm320/src/up_exit.c +++ b/nuttx/arch/dm320/src/up_exit.c @@ -1,7 +1,7 @@ -/************************************************************ +/**************************************************************************** * up_exit.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> @@ -49,28 +49,27 @@ #include <nuttx/fs.h> #endif -/************************************************************ +/**************************************************************************** * Private Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Private Funtions - ************************************************************/ +/**************************************************************************** + * Private Functions + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: _up_dumponexit * * Description: - * Dump the state of all tasks whenever on task exits. This - * is debug instrumentation that was added to check file- - * related reference counting but could be useful again - * sometime in the future. + * Dump the state of all tasks whenever on task exits. This is debug + * instrumentation that was added to check file-related reference counting + * but could be useful again sometime in the future. * - ************************************************************/ + ****************************************************************************/ #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) @@ -112,22 +111,24 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) } #endif -/************************************************************ - * Public Funtions - ************************************************************/ +/**************************************************************************** + * Public Functions + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: _exit * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * - ************************************************************/ + ****************************************************************************/ void _exit(int status) { - _TCB* tcb = (_TCB*)g_readytorun.head; + _TCB* tcb; /* Disable interrupts. They will be restored when the next * task is started. @@ -138,41 +139,13 @@ void _exit(int status) lldbg("TCB=%p exitting\n", tcb); #if defined(CONFIG_DUMP_ON_EXIT) && defined(CONFIG_DEBUG) - dbg("Other tasks:\n"); + lldbg("Other tasks:\n"); sched_foreach(_up_dumponexit, NULL); #endif - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/arch/pjrc-8051/src/up_exit.c b/nuttx/arch/pjrc-8051/src/up_exit.c index b938d9304..227225596 100644 --- a/nuttx/arch/pjrc-8051/src/up_exit.c +++ b/nuttx/arch/pjrc-8051/src/up_exit.c @@ -1,7 +1,7 @@ -/************************************************************ +/**************************************************************************** * up_exit.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> @@ -46,34 +46,36 @@ #include "os_internal.h" #include "up_internal.h" -/************************************************************ +/**************************************************************************** * Private Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Private Funtions - ************************************************************/ +/**************************************************************************** + * Private Functions + ****************************************************************************/ -/************************************************************ - * Public Funtions - ************************************************************/ +/**************************************************************************** + * Public Functions + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: _exit * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * - ************************************************************/ + ****************************************************************************/ void _exit(int status) { - FAR _TCB* tcb = (FAR _TCB*)g_readytorun.head; + FAR _TCB* tcb; dbg("TCB=%p exitting\n", tcb); @@ -83,37 +85,9 @@ void _exit(int status) EA = 0; - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/arch/sim/src/up_exit.c b/nuttx/arch/sim/src/up_exit.c index 8ab8f92cf..5c2cd3dc4 100644 --- a/nuttx/arch/sim/src/up_exit.c +++ b/nuttx/arch/sim/src/up_exit.c @@ -1,7 +1,7 @@ -/************************************************************ +/**************************************************************************** * up_exit.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sys/types.h> @@ -45,68 +45,42 @@ #include "os_internal.h" #include "up_internal.h" -/************************************************************ +/**************************************************************************** * Private Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ + ****************************************************************************/ -/************************************************************ - * Private Funtions - ************************************************************/ +/**************************************************************************** + * Private Functions + ****************************************************************************/ -/************************************************************ - * Public Funtions - ************************************************************/ +/**************************************************************************** + * Public Functions + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: _exit * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * - ************************************************************/ + ****************************************************************************/ void _exit(int status) { - _TCB* tcb = (_TCB*)g_readytorun.head; + _TCB* tcb; sdbg("TCB=%p exitting\n", tcb); - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now. - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/arch/z16/src/common/up_exit.c b/nuttx/arch/z16/src/common/up_exit.c index 52a9b148b..b2e18e22b 100644 --- a/nuttx/arch/z16/src/common/up_exit.c +++ b/nuttx/arch/z16/src/common/up_exit.c @@ -69,10 +69,9 @@ * Name: _up_dumponexit * * Description: - * Dump the state of all tasks whenever on task exits. This - * is debug instrumentation that was added to check file- - * related reference counting but could be useful again - * sometime in the future. + * Dump the state of all tasks whenever on task exits. This is debug + * instrumentation that was added to check file-related reference counting + * but could be useful again sometime in the future. * ****************************************************************************/ @@ -137,13 +136,15 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * ****************************************************************************/ void _exit(int status) { - FAR _TCB* tcb = (FAR _TCB*)g_readytorun.head; + FAR _TCB* tcb; /* Disable interrupts. Interrupts will remain disabled until * the new task is resumed below. @@ -158,37 +159,9 @@ void _exit(int status) sched_foreach(_up_dumponexit, NULL); #endif - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/arch/z80/src/common/up_exit.c b/nuttx/arch/z80/src/common/up_exit.c index b7f5e6243..d8c94fece 100644 --- a/nuttx/arch/z80/src/common/up_exit.c +++ b/nuttx/arch/z80/src/common/up_exit.c @@ -69,10 +69,9 @@ * Name: _up_dumponexit * * Description: - * Dump the state of all tasks whenever on task exits. This - * is debug instrumentation that was added to check file- - * related reference counting but could be useful again - * sometime in the future. + * Dump the state of all tasks whenever on task exits. This is debug + * instrumentation that was added to check file-related reference counting + * but could be useful again sometime in the future. * ****************************************************************************/ @@ -137,13 +136,15 @@ static void _up_dumponexit(FAR _TCB *tcb, FAR void *arg) * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * ****************************************************************************/ void _exit(int status) { - FAR _TCB* tcb = (FAR _TCB*)g_readytorun.head; + FAR _TCB* tcb; /* Disable interrupts. Interrupts will remain disabled until * the new task is resumed below. @@ -158,37 +159,9 @@ void _exit(int status) sched_foreach(_up_dumponexit, NULL); #endif - /* Remove the tcb task from the ready-to-run list. We can - * ignore the return value because we know that a context - * switch is needed. - */ - - (void)sched_removereadytorun(tcb); - - /* We are not in a bad stack-- the head of the ready to run task list - * does not correspond to the thread that is running. Disabling pre- - * emption on this TCB should be enough to keep things stable. - */ - - sched_lock(); - - /* Move the TCB to the specified blocked task list and delete it */ - - sched_addblocked(tcb, TSTATE_TASK_INACTIVE); - task_delete(tcb->pid); - - /* If there are any pending tasks, then add them to the g_readytorun - * task list now - */ - - if (g_pendingtasks.head) - { - (void)sched_mergepending(); - } - - /* Now calling sched_unlock() should have no effect */ + /* Destroy the task at the head of the ready to run list. */ - sched_unlock(); + (void)task_deletecurrent(); /* Now, perform the context switch to the new ready-to-run task at the * head of the list. diff --git a/nuttx/include/nuttx/arch.h b/nuttx/include/nuttx/arch.h index 3eef7b15d..2c83f1f2a 100644 --- a/nuttx/include/nuttx/arch.h +++ b/nuttx/include/nuttx/arch.h @@ -1,5 +1,5 @@ /**************************************************************************** - * arch.h + * nuttx/arch.h * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> @@ -53,12 +53,12 @@ * Public Types ****************************************************************************/ +typedef CODE void (*sig_deliver_t)(FAR _TCB *tcb); + /**************************************************************************** * Public Variables ****************************************************************************/ -typedef CODE void (*sig_deliver_t)(FAR _TCB *tcb); - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -291,12 +291,13 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, ubyte priority); * * Description: * This function causes the currently executing task to cease - * to exist. This is a special case of task_delete(). + * to exist. This is a special case of task_delete() where the task to + * be deleted is the currently executing task. It is more complex because + * a context switch must be perform to the the next ready to run task. * - * Unlike other UP APIs, this function may be called - * directly from user programs in various states. The - * implementation of this function should diable interrupts - * before performing scheduling operations. + * Unlike other UP APIs, this function may be called directly from user + * programs in various states. The implementation of this function should + * disable interrupts before performing scheduling operations. * ****************************************************************************/ /* Prototype is in unistd.h */ @@ -448,8 +449,7 @@ EXTERN void up_mdelay(unsigned int milliseconds); EXTERN void up_udelay(unsigned int microseconds); /**************************************************************************** - * Debug interfaces exported by the architecture-specific - * logic + * Debug interfaces exported by the architecture-specific logic ****************************************************************************/ /**************************************************************************** diff --git a/nuttx/include/nuttx/sched.h b/nuttx/include/nuttx/sched.h index 7386979c8..4548b3365 100644 --- a/nuttx/include/nuttx/sched.h +++ b/nuttx/include/nuttx/sched.h @@ -1,5 +1,5 @@ /******************************************************************************** - * sched.h + * nuttx/sched.h * * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> @@ -83,22 +83,22 @@ enum tstate_e { - TSTATE_TASK_INVALID = 0, /* INVALID - TCB has not yet been initialized */ - + TSTATE_TASK_INVALID = 0, /* INVALID - The TCB is is not in a valid state + * (Uninitialized or between context switches) */ TSTATE_TASK_PENDING = 1, /* READY_TO_RUN - Pending preemption unlock */ TSTATE_TASK_READYTORUN = 2, /* READY-TO-RUN - But not running */ TSTATE_TASK_RUNNING = 3, /* READY_TO_RUN - And running */ - TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */ - TSTATE_WAIT_SEM = 5 /* BLOCKED - Waiting for a semaphore */ + TSTATE_TASK_INACTIVE = 4, /* BLOCKED - Initialized but not yet activated */ + TSTATE_WAIT_SEM = 5 /* BLOCKED - Waiting for a semaphore */ #ifndef CONFIG_DISABLE_SIGNALS , - TSTATE_WAIT_SIG = 6 /* BLOCKED - Waiting for a signal */ + TSTATE_WAIT_SIG = 6 /* BLOCKED - Waiting for a signal */ #endif #ifndef CONFIG_DISABLE_MQUEUE , - TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */ - TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */ + TSTATE_WAIT_MQNOTEMPTY, /* BLOCKED - Waiting for a MQ to become not empty. */ + TSTATE_WAIT_MQNOTFULL /* BLOCKED - Waiting for a MQ to become not full. */ #endif }; typedef enum tstate_e tstate_t; diff --git a/nuttx/sched/Makefile b/nuttx/sched/Makefile index f2ba461df..ad5286f01 100644 --- a/nuttx/sched/Makefile +++ b/nuttx/sched/Makefile @@ -43,7 +43,7 @@ MISC_SRCS = os_start.c get_errno_ptr.c \ sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \ sched_releasefiles.c TSK_SRCS = task_create.c task_init.c task_setup.c task_activate.c \ - task_start.c task_delete.c task_restart.c \ + task_start.c task_delete.c task_deletecurrent.c task_restart.c \ exit.c abort.c atexit.c getpid.c \ sched_addreadytorun.c sched_removereadytorun.c sched_addprioritized.c \ sched_mergepending.c sched_addblocked.c sched_removeblocked.c \ diff --git a/nuttx/sched/get_errno_ptr.c b/nuttx/sched/get_errno_ptr.c index 82eacb762..36598caae 100644 --- a/nuttx/sched/get_errno_ptr.c +++ b/nuttx/sched/get_errno_ptr.c @@ -1,7 +1,7 @@ -/************************************************************ +/**************************************************************************** * get_errno_ptr.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> #include <sched.h> @@ -45,17 +45,17 @@ #undef get_errno_ptr -/************************************************************ +/**************************************************************************** * Private Data - ************************************************************/ + ****************************************************************************/ static int g_irqerrno; -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Function: get_errno_ptr * * Description: @@ -69,36 +69,44 @@ static int g_irqerrno; * * Assumptions: * - ************************************************************/ + ****************************************************************************/ FAR int *get_errno_ptr(void) { - /* Check if this function was called from an interrupt - * handler. In that case, we have to do things a little - * differently. + /* Check if this function was called from an interrupt handler. In that + * case, we have to do things a little differently to prevent the interrupt + * handler from modifying the tasks errno value. */ - if (up_interrupt_context()) + if (!up_interrupt_context()) { - /* Yes, we were called from an interrupt handler. Do - * not permit access to the errno in the TCB of the - * interrupt task. Instead, use a separate errno just - * for interrupt handlers. Of course, this would have - * to change if we ever wanted to support nested - * interrupts. + /* We were called from the normal tasking context. Verify that the + * task at the head of the ready-to-run list is actually running. It + * may not be running during very brief times during context switching + * logic (see, for example, task_deletecurrent.c). */ - return &g_irqerrno; - } - else - { - /* We were called from the normal tasking context. Return - * a reference to the thread-private errno in the TCB. - */ + FAR _TCB *rtcb = (FAR _TCB*)g_readytorun.head; + if (rtcb->task_state == TSTATE_TASK_RUNNING) + { + /* Yes.. the task is running normally. Return a reference to the + * thread-private errno in the TCB of the running task. + */ - FAR _TCB *ptcb = (FAR _TCB*)g_readytorun.head; - return &ptcb->errno; + return &rtcb->errno; + } } + + /* We were called either from (1) an interrupt handler or (2) from normally + * code but in an unhealthy state. In either event, do not permit access to + * the errno in the TCB of the task at the head of the ready-to-run list. + * Instead, use a separate errno just for interrupt handlers. Of course, this + * would have to change if we ever wanted to support nested interrupts or if + * we really cared about the stability of the errno during those "unhealthy + * states." + */ + + return &g_irqerrno; } diff --git a/nuttx/sched/os_internal.h b/nuttx/sched/os_internal.h index f1ec07b56..e3dffb207 100644 --- a/nuttx/sched/os_internal.h +++ b/nuttx/sched/os_internal.h @@ -1,7 +1,7 @@ -/************************************************************ - * os_internal.h +/**************************************************************************** + * sched/os_internal.h * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,22 +31,22 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ #ifndef __OS_INTERNAL_H #define __OS_INTERNAL_H -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <queue.h> #include <sched.h> #include <nuttx/kmalloc.h> -/************************************************************ +/**************************************************************************** * Definitions - ************************************************************/ + ****************************************************************************/ /* OS CRASH CODES */ @@ -110,9 +110,9 @@ enum os_crash_codes_e #define _SET_TCB_ERRNO(t,e) \ { (t)->errno = (e); } -/************************************************************ +/**************************************************************************** * Public Type Definitions - ************************************************************/ + ****************************************************************************/ /* This structure defines the format of the hash table that * is used to (1) determine if a task ID is unique, and (2) @@ -138,11 +138,11 @@ struct tasklist_s }; typedef struct tasklist_s tasklist_t; -/************************************************************ +/**************************************************************************** * Global Variables - ************************************************************/ + ****************************************************************************/ -/* Declared in os_start.c ***********************************/ +/* Declared in os_start.c ***************************************************/ /* The state of a task is indicated both by the task_state field * of the TCB and by a series of task lists. All of these @@ -234,15 +234,16 @@ extern pidhash_t g_pidhash[CONFIG_MAX_TASKS]; extern const tasklist_t g_tasklisttable[NUM_TASK_STATES]; -/************************************************************ +/**************************************************************************** * Public Function Prototypes - ************************************************************/ + ****************************************************************************/ extern void task_start(void); extern STATUS task_schedsetup(FAR _TCB *tcb, int priority, start_t start, main_t main); extern STATUS task_argsetup(FAR _TCB *tcb, const char *name, const char *argv[]); +extern STATUS task_deletecurrent(void); extern boolean sched_addreadytorun(FAR _TCB *rtrtcb); extern boolean sched_removereadytorun(FAR _TCB *rtrtcb); diff --git a/nuttx/sched/task_delete.c b/nuttx/sched/task_delete.c index 691b7c57e..369f601ed 100644 --- a/nuttx/sched/task_delete.c +++ b/nuttx/sched/task_delete.c @@ -1,7 +1,7 @@ -/************************************************************ - * task_delete.c +/**************************************************************************** + * sched/task_delete.c * - * Copyright (C) 2007 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <spudmonkey@racsa.co.cr> * * Redistribution and use in source and binary forms, with or without @@ -14,7 +14,7 @@ * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * 3. Neither the name Gregory Nutt nor the names of its contributors may be + * 3. Neither the name NuttX nor the names of its contributors may be * used to endorse or promote products derived from this software * without specific prior written permission. * @@ -31,11 +31,11 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Included Files - ************************************************************/ + ****************************************************************************/ #include <nuttx/config.h> @@ -46,41 +46,40 @@ # include "sig_internal.h" #endif -/************************************************************ +/**************************************************************************** * Definitions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Type Declarations - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Global Variables - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Variables - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Function Prototypes - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Private Functions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Public Functions - ************************************************************/ + ****************************************************************************/ -/************************************************************ +/**************************************************************************** * Name: task_delete * * Description: - * This function causes a specified task to cease to exist. - * Its stack and TCB will be deallocated. This function - * is the companion to task_create(). + * This function causes a specified task to cease to exist. Its stack and + * TCB will be deallocated. This function is the companion to task_create(). * * Inputs: * pid - The task ID of the task to delete. A pid of zero @@ -89,10 +88,10 @@ * Return Value: * OK on success; or ERROR on failure * - * This function can fail if the provided pid does not - * correspond to a task (errno is not set) + * This function can fail if the provided pid does not correspond to a + * task (errno is not set) * - ************************************************************/ + ****************************************************************************/ STATUS task_delete(pid_t pid) { @@ -106,17 +105,15 @@ STATUS task_delete(pid_t pid) rtcb = (FAR _TCB*)g_readytorun.head; if (pid == 0 || pid == rtcb->pid) { - /* If it is, then what we really wanted to do was exit. - * Note that we don't bother to unlock the TCB since - * it will be going away. + /* If it is, then what we really wanted to do was exit. Note that we + * don't bother to unlock the TCB since it will be going away. */ exit(EXIT_SUCCESS); } - /* Make sure the task does not become ready-to-run while - * we are futzing with its TCB by locking ourselves as the - * executing task. + /* Make sure the task does not become ready-to-run while we are futzing with + * its TCB by locking ourselves as the executing task. */ sched_lock(); diff --git a/nuttx/sched/task_deletecurrent.c b/nuttx/sched/task_deletecurrent.c new file mode 100644 index 000000000..8246bb471 --- /dev/null +++ b/nuttx/sched/task_deletecurrent.c @@ -0,0 +1,141 @@ +/**************************************************************************** + * sched/task_deletecurrent.c + * + * Copyright (C) 2008 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <spudmonkey@racsa.co.cr> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <sys/types.h> +#include <sched.h> +#include "os_internal.h" +#ifndef CONFIG_DISABLE_SIGNALS +# include "sig_internal.h" +#endif + +/**************************************************************************** + * Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Global Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Variables + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: task_delete + * + * Description: + * This function causes the currently running task (i.e., the task at the + * head of the ready-to-run list) to cease to exist. This is a part of + * the logic used to implement _exit(). The full implementation of _exit() + * is architecture-dependent. This function should never be called from + * normal user code, but only from the architecture-specific implementation + * of exit. + * + * Inputs: + * None + * + * Return Value: + * OK on success; or ERROR on failure + * + ****************************************************************************/ + +STATUS task_deletecurrent(void) +{ + FAR _TCB *dtcb = (FAR _TCB*)g_readytorun.head; + FAR _TCB *rtcb; + + /* Remove the TCB of the current task from the ready-to-run list. A context + * switch will definitely be necessary -- that must be done by the + * architecture-specific logic. + * + * sched_removereadytorun will mark the task at the head of the ready-to-run + * with state == TSTATE_TASK_RUNNING + */ + + (void)sched_removereadytorun(dtcb); + rtcb = (FAR _TCB*)g_readytorun.head; + + /* We are not in a bad state -- the head of the ready to run task list + * does not correspond to the thread that is running. Disabling pre- + * emption on this TCB and marking the new ready-to-run task as not + * running (see, for example, get_errno_ptr()). + */ + + sched_lock(); + rtcb->task_state = TSTATE_TASK_READYTORUN; + + /* Move the TCB to the specified blocked task list and delete it */ + + sched_addblocked(dtcb, TSTATE_TASK_INACTIVE); + task_delete(dtcb->pid); + rtcb->task_state = TSTATE_TASK_RUNNING; + + /* If there are any pending tasks, then add them to the ready-to-run + * task list now + */ + + if (g_pendingtasks.head) + { + (void)sched_mergepending(); + } + + /* Now calling sched_unlock() should have no effect */ + + sched_unlock(); + return OK; +} + |