]> git.sur5r.net Git - freertos/commitdiff
Add vTaskEnterCritical() and vTaskExitCritical() functions.
authorrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 25 Feb 2008 18:54:28 +0000 (18:54 +0000)
committerrichardbarry <richardbarry@1d2547de-c912-0410-9cb9-b8ca96c0e9e2>
Mon, 25 Feb 2008 18:54:28 +0000 (18:54 +0000)
git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@221 1d2547de-c912-0410-9cb9-b8ca96c0e9e2

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

index ee963a4fa7015c6d07037436d682d6e9b32bffec..f9139ffca8ddc44c6fd7077e0a464fa21e717ecd 100644 (file)
        #define configUSE_ALTERNATIVE_API 0\r
 #endif\r
 \r
+#ifndef portCRITICAL_NESTING_IN_TCB\r
+       #define portCRITICAL_NESTING_IN_TCB 0\r
+#endif\r
+\r
 #if ( configUSE_MUTEXES == 1 )\r
        /* xTaskGetCurrentTaskHandle is used by the priority inheritance mechanism\r
        within the mutex implementation so must be available if mutexes are used. */\r
index cc43e7e5b92136fbb049e87761605cf0fa814216..1c1013a1c0503978710a3051d192e123424e82bf 100644 (file)
@@ -266,6 +266,10 @@ typedef struct tskTaskControlBlock
        portSTACK_TYPE                  *pxStack;                       /*< Points to the start of the stack. */\r
        signed portCHAR                 pcTaskName[ configMAX_TASK_NAME_LEN ];/*< Descriptive name given to the task when created.  Facilitates debugging only. */\r
 \r
+       #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+               unsigned portBASE_TYPE uxCriticalNesting;\r
+       #endif\r
+\r
        #if ( configUSE_TRACE_FACILITY == 1 )\r
                unsigned portBASE_TYPE  uxTCBNumber;            /*< This is used for tracing the scheduler and making debugging easier only. */\r
        #endif  \r
@@ -1755,6 +1759,12 @@ static void prvInitialiseTCBVariables( tskTCB *pxTCB, const signed portCHAR * co
        strncpy( ( char * ) pxTCB->pcTaskName, ( const char * ) pcName, ( unsigned portSHORT ) configMAX_TASK_NAME_LEN );\r
        pxTCB->pcTaskName[ ( unsigned portSHORT ) configMAX_TASK_NAME_LEN - ( unsigned portSHORT ) 1 ] = '\0';\r
 \r
+       #if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+       {\r
+               pxTCB->uxCriticalNesting = ( unsigned portBASE_TYPE ) 0;\r
+       }\r
+       #endif\r
+\r
        /* This is used as an array index so must ensure it's not too large. */\r
        if( uxPriority >= configMAX_PRIORITIES )\r
        {\r
@@ -1983,6 +1993,7 @@ tskTCB *pxNewTCB;
        }\r
 \r
 #endif\r
+/*-----------------------------------------------------------*/\r
 \r
 #if ( configUSE_MUTEXES == 1 )\r
        \r
@@ -2014,6 +2025,7 @@ tskTCB *pxNewTCB;
        }\r
 \r
 #endif\r
+/*-----------------------------------------------------------*/\r
 \r
 #if ( configUSE_MUTEXES == 1 ) \r
 \r
@@ -2039,8 +2051,44 @@ tskTCB *pxNewTCB;
        }\r
 \r
 #endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+\r
+       void vTaskEnterCritical( void )\r
+       {\r
+               portDISABLE_INTERRUPTS();\r
+\r
+               if( xSchedulerRunning != pdFALSE )\r
+               {\r
+                       pxCurrentTCB->uxCriticalNesting++;\r
+               }\r
+       }\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
+\r
+#if ( portCRITICAL_NESTING_IN_TCB == 1 )\r
+\r
+void vTaskExitCritical( void )\r
+{\r
+       if( xSchedulerRunning != pdFALSE )\r
+       {\r
+               if( pxCurrentTCB->uxCriticalNesting > 0 )\r
+               {\r
+                       pxCurrentTCB->uxCriticalNesting--;\r
+\r
+                       if( pxCurrentTCB->uxCriticalNesting == 0 )\r
+                       {\r
+                               portENABLE_INTERRUPTS();\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+#endif\r
+/*-----------------------------------------------------------*/\r
 \r
-       \r
 \r
        \r
 \r