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:
Richard Barry 2013-12-12 10:19:07 +00:00
parent 0416289066
commit 6b3393b4b6
6 changed files with 129 additions and 16 deletions

View file

@ -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 );
}
/*-----------------------------------------------------------*/

View file

@ -139,7 +139,7 @@ void vPortExitCritical( void );
#define portINTERRUPT_YIELD ( 0UL )
#define portINTERRUPT_TICK ( 1UL )
/*
/*
* Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
* Each bit can be used to represent an individual interrupt - with the first
* two bits being used for the Yield and Tick interrupts respectively.
@ -147,13 +147,13 @@ void vPortExitCritical( void );
void vPortGenerateSimulatedInterrupt( unsigned long ulInterruptNumber );
/*
* Install an interrupt handler to be called by the simulated interrupt handler
* Install an interrupt handler to be called by the simulated interrupt handler
* thread. The interrupt number must be above any used by the kernel itself
* (at the time of writing the kernel was using interrupt numbers 0, 1, and 2
* as defined above). The number must also be lower than 32.
* as defined above). The number must also be lower than 32.
*
* Interrupt handler functions must return a non-zero value if executing the
* handler resulted in a task switch being required.
* handler resulted in a task switch being required.
*/
void vPortSetInterruptHandler( unsigned long ulInterruptNumber, unsigned long (*pvHandler)( void ) );