]> git.sur5r.net Git - freertos/commitdiff
Fix definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE
authorgaurav-aws <gaurav-aws@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 17 Feb 2019 01:24:58 +0000 (01:24 +0000)
committergaurav-aws <gaurav-aws@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Sun, 17 Feb 2019 01:24:58 +0000 (01:24 +0000)
tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE was not correctly defined resulting in
dynamically allocated TCB not being freed when MPU was enabled. This commit fixes
the definition to ensure that dynamically allocated RAM (Stack and TCB) is freed
always.

git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2632 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

FreeRTOS/Source/include/FreeRTOS.h
FreeRTOS/Source/tasks.c

index e599b013b141c34141821b7bec24e53047607845..ac4f3f01fab2840bd8093ae33db1b76d0bef57bb 100644 (file)
@@ -954,6 +954,51 @@ point support. */
        #define configUSE_TASK_FPU_SUPPORT 1\r
 #endif\r
 \r
+/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using\r
+ * dynamically allocated RAM, in which case when any task is deleted it is known\r
+ * that both the task's stack and TCB need to be freed.  Sometimes the\r
+ * FreeRTOSConfig.h settings only allow a task to be created using statically\r
+ * allocated RAM, in which case when any task is deleted it is known that neither\r
+ * the task's stack or TCB should be freed.  Sometimes the FreeRTOSConfig.h\r
+ * settings allow a task to be created using either statically or dynamically\r
+ * allocated RAM, in which case a member of the TCB is used to record whether the\r
+ * stack and/or TCB were allocated statically or dynamically, so when a task is\r
+ * deleted the RAM that was allocated dynamically is freed again and no attempt is\r
+ * made to free the RAM that was allocated statically.\r
+ * tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a\r
+ * task to be created using either statically or dynamically allocated RAM.  Note\r
+ * that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with\r
+ * a statically allocated stack and a dynamically allocated TCB.\r
+ *\r
+ * The following table lists various combinations of portUSING_MPU_WRAPPERS,\r
+ * configSUPPORT_DYNAMIC_ALLOCATION and configSUPPORT_STATIC_ALLOCATION and\r
+ * when it is possible to have both static and dynamic allocation:\r
+ *  +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+\r
+ * | MPU | Dynamic | Static |     Available Functions     |       Possible Allocations        | Both Dynamic and | Need Free |\r
+ * |     |         |        |                             |                                   | Static Possible  |           |\r
+ * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+\r
+ * | 0   | 0       | 1      | xTaskCreateStatic           | TCB - Static, Stack - Static      | No               | No        |\r
+ * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|\r
+ * | 0   | 1       | 0      | xTaskCreate                 | TCB - Dynamic, Stack - Dynamic    | No               | Yes       |\r
+ * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|\r
+ * | 0   | 1       | 1      | xTaskCreate,                | 1. TCB - Dynamic, Stack - Dynamic | Yes              | Yes       |\r
+ * |     |         |        | xTaskCreateStatic           | 2. TCB - Static, Stack - Static   |                  |           |\r
+ * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|\r
+ * | 1   | 0       | 1      | xTaskCreateStatic,          | TCB - Static, Stack - Static      | No               | No        |\r
+ * |     |         |        | xTaskCreateRestrictedStatic |                                   |                  |           |\r
+ * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|\r
+ * | 1   | 1       | 0      | xTaskCreate,                | 1. TCB - Dynamic, Stack - Dynamic | Yes              | Yes       |\r
+ * |     |         |        | xTaskCreateRestricted       | 2. TCB - Dynamic, Stack - Static  |                  |           |\r
+ * +-----|---------|--------|-----------------------------|-----------------------------------|------------------|-----------|\r
+ * | 1   | 1       | 1      | xTaskCreate,                | 1. TCB - Dynamic, Stack - Dynamic | Yes              | Yes       |\r
+ * |     |         |        | xTaskCreateStatic,          | 2. TCB - Dynamic, Stack - Static  |                  |           |\r
+ * |     |         |        | xTaskCreateRestricted,      | 3. TCB - Static, Stack - Static   |                  |           |\r
+ * |     |         |        | xTaskCreateRestrictedStatic |                                   |                  |           |\r
+ * +-----+---------+--------+-----------------------------+-----------------------------------+------------------+-----------+\r
+ */\r
+#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE      ( ( ( portUSING_MPU_WRAPPERS == 0 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) && ( configSUPPORT_STATIC_ALLOCATION == 1 ) ) || \\r
+                                                                                                         ( ( portUSING_MPU_WRAPPERS == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) ) )\r
+\r
 /*\r
  * In line with software engineering best practice, FreeRTOS implements a strict\r
  * data hiding policy, so the real structures used by FreeRTOS to maintain the\r
@@ -1038,7 +1083,7 @@ typedef struct xSTATIC_TCB
                uint32_t                ulDummy18;\r
                uint8_t                 ucDummy19;\r
        #endif\r
-       #if( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
+       #if ( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\r
                uint8_t                 uxDummy20;\r
        #endif\r
 \r
index 2842d9e7bdfde1005e76cbbbb2e8db6e1184ab96..5a61f9804f9cc5da081f80b7c7dadbaed5b1b6a3 100644 (file)
@@ -75,24 +75,6 @@ functions but without including stdio.h here. */
  */\r
 #define tskSTACK_FILL_BYTE     ( 0xa5U )\r
 \r
-/* Sometimes the FreeRTOSConfig.h settings only allow a task to be created using\r
-dynamically allocated RAM, in which case when any task is deleted it is known\r
-that both the task's stack and TCB need to be freed.  Sometimes the\r
-FreeRTOSConfig.h settings only allow a task to be created using statically\r
-allocated RAM, in which case when any task is deleted it is known that neither\r
-the task's stack or TCB should be freed.  Sometimes the FreeRTOSConfig.h\r
-settings allow a task to be created using either statically or dynamically\r
-allocated RAM, in which case a member of the TCB is used to record whether the\r
-stack and/or TCB were allocated statically or dynamically, so when a task is\r
-deleted the RAM that was allocated dynamically is freed again and no attempt is\r
-made to free the RAM that was allocated statically.\r
-tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is only true if it is possible for a\r
-task to be created using either statically or dynamically allocated RAM.  Note\r
-that if portUSING_MPU_WRAPPERS is 1 then a protected task can be created with\r
-a statically allocated stack and a dynamically allocated TCB.\r
-!!!NOTE!!! If the definition of tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE is\r
-changed then the definition of StaticTask_t must also be updated. */\r
-#define tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE      ( ( configSUPPORT_STATIC_ALLOCATION == 1 ) && ( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) )\r
 #define tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB                 ( ( uint8_t ) 0 )\r
 #define tskSTATICALLY_ALLOCATED_STACK_ONLY                     ( ( uint8_t ) 1 )\r
 #define tskSTATICALLY_ALLOCATED_STACK_AND_TCB          ( ( uint8_t ) 2 )\r
@@ -326,7 +308,7 @@ typedef struct tskTaskControlBlock                  /* The old naming convention is used to pr
                volatile uint8_t ucNotifyState;\r
        #endif\r
 \r
-       /* See the comments above the definition of\r
+       /* See the comments in FreeRTOS.h with the definition of\r
        tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE. */\r
        #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 ) /*lint !e731 !e9029 Macro has been consolidated for readability reasons. */\r
                uint8_t ucStaticallyAllocated;          /*< Set to pdTRUE if the task is a statically allocated to ensure no attempt is made to free the memory. */\r
@@ -631,7 +613,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                task was created statically in case the task is later deleted. */\r
                                pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
-                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+                       #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                        prvInitialiseNewTask( pxTaskCode, pcName, ulStackDepth, pvParameters, uxPriority, &xReturn, pxNewTCB, NULL );\r
                        prvAddNewTaskToReadyList( pxNewTCB );\r
@@ -673,7 +655,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                task was created statically in case the task is later deleted. */\r
                                pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
-                       #endif /* configSUPPORT_DYNAMIC_ALLOCATION */\r
+                       #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                        prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                        pxTaskDefinition->pcName,\r
@@ -714,14 +696,14 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                /* Store the stack location in the TCB. */\r
                                pxNewTCB->pxStack = pxTaskDefinition->puxStackBuffer;\r
 \r
-                               #if( configSUPPORT_STATIC_ALLOCATION == 1 )\r
+                               #if( tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE != 0 )\r
                                {\r
                                        /* Tasks can be created statically or dynamically, so note\r
                                        this task had a statically allocated stack in case it is\r
                                        later deleted.  The TCB was allocated dynamically. */\r
                                        pxNewTCB->ucStaticallyAllocated = tskSTATICALLY_ALLOCATED_STACK_ONLY;\r
                                }\r
-                               #endif\r
+                               #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                                prvInitialiseNewTask(   pxTaskDefinition->pvTaskCode,\r
                                                                                pxTaskDefinition->pcName,\r
@@ -818,7 +800,7 @@ static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB ) PRIVILEGED_FUNCTION;
                                task was created dynamically in case it is later deleted. */\r
                                pxNewTCB->ucStaticallyAllocated = tskDYNAMICALLY_ALLOCATED_STACK_AND_TCB;\r
                        }\r
-                       #endif /* configSUPPORT_STATIC_ALLOCATION */\r
+                       #endif /* tskSTATIC_AND_DYNAMIC_ALLOCATION_POSSIBLE */\r
 \r
                        prvInitialiseNewTask( pxTaskCode, pcName, ( uint32_t ) usStackDepth, pvParameters, uxPriority, pxCreatedTask, pxNewTCB, NULL );\r
                        prvAddNewTaskToReadyList( pxNewTCB );\r