]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Source/portable/MSVC-MingW/port.c
Updates to support FreeRTOS MPU in FreeRTOS V9.0.0 - including a GCC project that...
[freertos] / FreeRTOS / Source / portable / MSVC-MingW / port.c
index 347523755224662abee62a5ba13b09943b847a95..99892bb73748477c917cc2f137a622b71193aac8 100644 (file)
@@ -262,6 +262,7 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
 {\r
 xThreadState *pxThreadState = NULL;\r
 int8_t *pcTopOfStack = ( int8_t * ) pxTopOfStack;\r
+const SIZE_T xStackSize = 1024; /* Set the size to a small number which will get rounded up to the minimum possible. */\r
 \r
        #ifdef portSOAK_TEST\r
        {\r
@@ -282,8 +283,8 @@ int8_t *pcTopOfStack = ( int8_t * ) pxTopOfStack;
        pxThreadState = ( xThreadState * ) ( pcTopOfStack - sizeof( xThreadState ) );\r
 \r
        /* Create the thread itself. */\r
-       pxThreadState->pvThread = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED, NULL );\r
-       configASSERT( pxThreadState->pvThread );\r
+       pxThreadState->pvThread = CreateThread( NULL, xStackSize, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED | STACK_SIZE_PARAM_IS_A_RESERVATION, NULL );\r
+       configASSERT( pxThreadState->pvThread ); /* See comment where TerminateThread() is called. */\r
        SetThreadAffinityMask( pxThreadState->pvThread, 0x01 );\r
        SetThreadPriorityBoost( pxThreadState->pvThread, TRUE );\r
        SetThreadPriority( pxThreadState->pvThread, portTASK_THREAD_PRIORITY );\r
@@ -490,6 +491,10 @@ uint32_t ulErrorCode;
        {\r
                WaitForSingleObject( pvInterruptEventMutex, INFINITE );\r
 \r
+               /* !!! This is not a nice way to terminate a thread, and will eventually\r
+               result in resources being depleted if tasks frequently delete other\r
+               tasks (rather than deleting themselves) as the task stacks will not be\r
+               freed. */\r
                ulErrorCode = TerminateThread( pxThreadState->pvThread, 0 );\r
                configASSERT( ulErrorCode );\r
 \r
@@ -532,6 +537,10 @@ uint32_t ulErrorCode;
        ulErrorCode = CloseHandle( pvThread );\r
        configASSERT( ulErrorCode );\r
 \r
+       /* This is called from a critical section, which must be exited before the\r
+       thread stops. */\r
+       taskEXIT_CRITICAL();\r
+\r
        ExitThread( 0 );\r
 }\r
 /*-----------------------------------------------------------*/\r