mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-08-20 01:58:32 -04:00
Add trace macros into the event groups implementation.
Add a task pre-delete hook to allow the insertion of any port specific clean up when a task is deleted. Increase use of 'const' qualifiers. Add vPortCloseRunningThread() into the Win32 port layer to attempt to allow Windows threads to be closed more gracefully when a task deletes itself.
This commit is contained in:
parent
0416289066
commit
6b3393b4b6
6 changed files with 129 additions and 16 deletions
|
@ -244,6 +244,7 @@ char *pcTopOfStack = ( char * ) pxTopOfStack;
|
|||
|
||||
/* Create the thread itself. */
|
||||
pxThreadState->pvThread = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED, NULL );
|
||||
configASSERT( pxThreadState->pvThread );
|
||||
SetThreadAffinityMask( pxThreadState->pvThread, 0x01 );
|
||||
SetThreadPriorityBoost( pxThreadState->pvThread, TRUE );
|
||||
SetThreadPriority( pxThreadState->pvThread, THREAD_PRIORITY_IDLE );
|
||||
|
@ -418,13 +419,51 @@ void vPortDeleteThread( void *pvTaskToDelete )
|
|||
{
|
||||
xThreadState *pxThreadState;
|
||||
|
||||
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
|
||||
/* Find the handle of the thread being deleted. */
|
||||
pxThreadState = ( xThreadState * ) ( *( unsigned long *) pvTaskToDelete );
|
||||
|
||||
/* Check that the thread is still valid, it might have been closed by
|
||||
vPortCloseRunningThread() - which will be the case if the task associated
|
||||
with the thread originally deleted itself rather than being deleted by a
|
||||
different task. */
|
||||
if( pxThreadState->pvThread != NULL )
|
||||
{
|
||||
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
|
||||
|
||||
CloseHandle( pxThreadState->pvThread );
|
||||
TerminateThread( pxThreadState->pvThread, 0 );
|
||||
|
||||
ReleaseMutex( pvInterruptEventMutex );
|
||||
}
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vPortCloseRunningThread( void *pvTaskToDelete, volatile portBASE_TYPE *pxPendYield )
|
||||
{
|
||||
xThreadState *pxThreadState;
|
||||
void *pvThread;
|
||||
|
||||
/* Find the handle of the thread being deleted. */
|
||||
pxThreadState = ( xThreadState * ) ( *( unsigned long *) pvTaskToDelete );
|
||||
TerminateThread( pxThreadState->pvThread, 0 );
|
||||
pvThread = pxThreadState->pvThread;
|
||||
|
||||
ReleaseMutex( pvInterruptEventMutex );
|
||||
/* Raise the Windows priority of the thread to ensure the FreeRTOS scheduler
|
||||
does not run and swap it out before it is closed. If that were to happen
|
||||
the thread would never run again and effectively be a thread handle and
|
||||
memory leak. */
|
||||
SetThreadPriority( pvThread, THREAD_PRIORITY_ABOVE_NORMAL );
|
||||
|
||||
/* This function will not return, therefore a yield is set as pending to
|
||||
ensure a context switch occurs away from this thread on the next tick. */
|
||||
*pxPendYield = pdTRUE;
|
||||
|
||||
/* Mark the thread associated with this task as invalid so
|
||||
vPortDeleteThread() does not try to terminate it. */
|
||||
pxThreadState->pvThread = NULL;
|
||||
|
||||
/* Close the thread. */
|
||||
CloseHandle( pvThread );
|
||||
ExitThread( 0 );
|
||||
}
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue