From 09eac48792417206230798528de54a7d1c349f1d Mon Sep 17 00:00:00 2001
From: patacongo
Date: Mon, 23 Apr 2012 13:59:31 +0000
Subject: [PATCH] Fix atexit() function being called twice
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4644 7fd9a85b-ad96-42d3-883c-3090e2eb8679
---
nuttx/Documentation/NuttX.html | 17 ++++++++--
nuttx/Documentation/NuttxUserGuide.html | 6 ++++
nuttx/arch/arm/src/stm32/Kconfig | 42 +++++++++++++++++++++++++
nuttx/configs/README.txt | 3 --
nuttx/configs/pic32mx7mmb/README.txt | 2 +-
nuttx/sched/task_delete.c | 18 +++++++++++
nuttx/sched/task_exithook.c | 18 +++++++++++
7 files changed, 99 insertions(+), 7 deletions(-)
diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
index 0b85fcb65e..85b5134694 100644
--- a/nuttx/Documentation/NuttX.html
+++ b/nuttx/Documentation/NuttX.html
@@ -8,7 +8,7 @@
NuttX RTOS
- Last Updated: April 14, 2012
+ Last Updated: April 23, 2012
|
@@ -2228,10 +2228,13 @@
PIC32MX795F512L.
- This port uses the Microchip PIC32 Ethernet Starter Kit (DM320004) with the Expansion I/O board.
- See the Microchip website for further information.
+ There one two board ports using this chip:
+ - Microchip PIC32 Ethernet Starter Kit.
+ This port uses the Microchip PIC32 Ethernet Starter Kit (DM320004) with the Expansion I/O board.
+ See the Microchip website for further information.
+
STATUS:
This port was started and then shelved for some time until I received the Expansion I/O board.
@@ -2243,6 +2246,14 @@
Also included are a a verified Ethernet driver, a partially verified USB device controller driver, and an unverifed SPI driver.
Stay tuned for updates.
+ - Mikroelektronika PIC32MX7 Mulitmedia Board (MMB).
+ A port has begun for the Mikroelektronika PIC32MX7 Multimedia Board (MMB).
+ See http://www.mikroe.com/ for further information.
+
+
+ STATUS:
+ A configuration exists for this board, but has not been verfied as of this writing.
+
|
diff --git a/nuttx/Documentation/NuttxUserGuide.html b/nuttx/Documentation/NuttxUserGuide.html
index dec4fca028..9d3af1c270 100644
--- a/nuttx/Documentation/NuttxUserGuide.html
+++ b/nuttx/Documentation/NuttxUserGuide.html
@@ -522,6 +522,12 @@ And the UNIX interface:
The task is first terminated and then reinitialized with same
ID, priority, original entry point, stack size, and parameters
it had when it was first started.
+
+
+NOTE: The normal task exit clean up is not performed.
+For example, file descriptors are not closed;
+any files opened prior to the restart will remain opened after the task is restarted.
+
Input Parameters:
diff --git a/nuttx/arch/arm/src/stm32/Kconfig b/nuttx/arch/arm/src/stm32/Kconfig
index ae92d8cfb2..2dbc4b468f 100644
--- a/nuttx/arch/arm/src/stm32/Kconfig
+++ b/nuttx/arch/arm/src/stm32/Kconfig
@@ -1467,6 +1467,13 @@ config USART1_2STOP
---help---
Two stop bits
+config USART1_RXDMA
+ bool "USART1 Rx DMA"
+ default n
+ depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA2
+ ---help---
+ In high data rate usage, Rx DMA may eliminate Rx overrun errors
+
endmenu
menu "USART2 Configuration"
@@ -1516,6 +1523,13 @@ config USART2_2STOP
---help---
Two stop bits
+config USART2_RXDMA
+ bool "USART2 Rx DMA"
+ default n
+ depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1
+ ---help---
+ In high data rate usage, Rx DMA may eliminate Rx overrun errors
+
endmenu
menu "USART3 Configuration"
@@ -1565,6 +1579,13 @@ config USART3_2STOP
---help---
Two stop bits
+config USART3_RXDMA
+ bool "USART3 Rx DMA"
+ default n
+ depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1
+ ---help---
+ In high data rate usage, Rx DMA may eliminate Rx overrun errors
+
endmenu
menu "UART4 Configuration"
@@ -1614,6 +1635,13 @@ config USART4_2STOP
---help---
Two stop bits
+config USART4_RXDMA
+ bool "USART4 Rx DMA"
+ default n
+ depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1
+ ---help---
+ In high data rate usage, Rx DMA may eliminate Rx overrun errors
+
endmenu
menu "UART5 Configuration"
@@ -1663,6 +1691,13 @@ config USART5_2STOP
---help---
Two stop bits
+config USART5_RXDMA
+ bool "USART5 Rx DMA"
+ default n
+ depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA1
+ ---help---
+ In high data rate usage, Rx DMA may eliminate Rx overrun errors
+
endmenu
menu "USART6 Configuration"
@@ -1712,6 +1747,13 @@ config USART6_2STOP
---help---
Two stop bits
+config USART6_RXDMA
+ bool "USART6 Rx DMA"
+ default n
+ depends on STM32_STM32F40XX && ARCH_DMA && STM32_DMA2
+ ---help---
+ In high data rate usage, Rx DMA may eliminate Rx overrun errors
+
endmenu
menu "SPI Configuration"
diff --git a/nuttx/configs/README.txt b/nuttx/configs/README.txt
index e4e5248225..2d0e6e5af2 100644
--- a/nuttx/configs/README.txt
+++ b/nuttx/configs/README.txt
@@ -1495,9 +1495,6 @@ configs/pic32mx7mmb
This directory will (eventually) contain the port of NuttX to the
Mikroelektronika PIC32MX7 Multimedia Board (MMB). See
http://www.mikroe.com/ for further information.
-
- On initial check-in, this directory is just a clone of the PIC32 starter
- kit port with the appropriate naming changes. More to come.
configs/pjrc-8051
8051 Microcontroller. This port uses the PJRC 87C52 development system
diff --git a/nuttx/configs/pic32mx7mmb/README.txt b/nuttx/configs/pic32mx7mmb/README.txt
index 9ee125f7b3..d24b99430c 100644
--- a/nuttx/configs/pic32mx7mmb/README.txt
+++ b/nuttx/configs/pic32mx7mmb/README.txt
@@ -2,7 +2,7 @@ configs/pic32mx7mmb README
===============================
This README file discusses the port of NuttX to the Mikroelektronika PIC32MX7
-Multimedia Board (MMB)
+Multimedia Board (MMB). See http://www.mikroe.com/ for further information.
Contents
========
diff --git a/nuttx/sched/task_delete.c b/nuttx/sched/task_delete.c
index 4cd2b3ba7a..e5244a0b8e 100644
--- a/nuttx/sched/task_delete.c
+++ b/nuttx/sched/task_delete.c
@@ -83,6 +83,21 @@
* 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().
*
+ * The logic in this function only deletes non-running tasks. If the 'pid'
+ * parameter refers to to the currently runing task, then processing is
+ * redirected to exit().
+ *
+ * Control will still be returned to task_delete() after the exit() logic
+ * finishes. In fact, this function is the final function called all task
+ * termination sequences. Here are all possible exit scenarios:
+ *
+ * - pthread_exit(). Calls exit()
+ * - exit(). Calls _exit()
+ * - _exit(). Calls task_deletecurrent() making the currently running task
+ * non-running then calls task_delete() to terminate the non-running
+ * task.
+ * - task_delete()
+ *
* Inputs:
* pid - The task ID of the task to delete. A pid of zero
* signifies the calling task.
@@ -145,6 +160,9 @@ int task_delete(pid_t pid)
* this as early as possible so that higher level clean-up logic
* can run in a healthy tasking environment.
*
+ * In the case where the task exits via exit(), task_exithook()
+ * may be called twice.
+ *
* I suppose EXIT_SUCCESS is an appropriate return value???
*/
diff --git a/nuttx/sched/task_exithook.c b/nuttx/sched/task_exithook.c
index 44073165a8..e160a1cb30 100644
--- a/nuttx/sched/task_exithook.c
+++ b/nuttx/sched/task_exithook.c
@@ -114,14 +114,32 @@ void task_exithook(FAR _TCB *tcb, int status)
#ifdef CONFIG_SCHED_ATEXIT
if (tcb->atexitfunc)
{
+ /* Call the atexit function */
+
(*tcb->atexitfunc)();
+
+ /* Nullify the atexit function. task_exithook may be called more then
+ * once in most task exit scenarios. Nullifying the atext function
+ * pointer will assure that the callback is performed only once.
+ */
+
+ tcb->atexitfunc = NULL;
}
#endif
#ifdef CONFIG_SCHED_ONEXIT
if (tcb->onexitfunc)
{
+ /* Call the on_exit function */
+
(*tcb->onexitfunc)(status, tcb->onexitarg);
+
+ /* Nullify the on_exit function. task_exithook may be called more then
+ * once in most task exit scenarios. Nullifying the on_exit function
+ * pointer will assure that the callback is performed only once.
+ */
+
+ tcb->onexitfunc = NULL;
}
#endif