From a251de548216a4616b62688135fcc4db660d8ef1 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Sun, 21 Nov 2010 14:06:23 +0000 Subject: [PATCH] Changed vPortCheckCorrectThreadIsRunning() in the Win32 port layer to use the Win32 thread ID rather than its handle. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1151 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Source/portable/MSVC-MingW/port.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Source/portable/MSVC-MingW/port.c b/Source/portable/MSVC-MingW/port.c index f89b2d081..5446325c9 100644 --- a/Source/portable/MSVC-MingW/port.c +++ b/Source/portable/MSVC-MingW/port.c @@ -88,7 +88,12 @@ typedef struct long lWaitingInterruptAck; /* Handle of the thread that executes the task. */ - void * pvThread; + void *pvThread; + + /* Used to check that the thread that is supposed to be running in indeed + the thread that is running. */ + unsigned long ulThreadId; + } xThreadState; /* Pseudo interrupts waiting to be processed. This is a bit mask where each @@ -181,7 +186,7 @@ xThreadState *pxThreadState = NULL; pxThreadState = ( xThreadState * ) ( pxTopOfStack - sizeof( xThreadState ) ); /* Create the thread itself. */ - pxThreadState->pvThread = ( void * ) CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED, NULL ); + pxThreadState->pvThread = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED, &( pxThreadState->ulThreadId ) ); SetThreadPriorityBoost( pxThreadState->pvThread, TRUE ); pxThreadState->lWaitingInterruptAck = pdFALSE; SetThreadPriority( pxThreadState->pvThread, THREAD_PRIORITY_IDLE ); @@ -536,15 +541,20 @@ long lMutexNeedsReleasing; void vPortCheckCorrectThreadIsRunning( void ) { -xThreadState *pxThreadState = ( xThreadState * ) *( ( unsigned long * ) pxCurrentTCB ); +xThreadState *pxThreadState; /* When switching threads, Windows does not always seem to run the selected thread immediately. This function can be called to check if the thread that is currently running is the thread that is responsible for executing the task selected by the real time scheduler. */ - if( GetCurrentThread() != pxThreadState->pvThread ) + if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED ) { - SwitchToThread(); + pxThreadState = ( xThreadState * ) *( ( unsigned long * ) pxCurrentTCB ); + + if( GetCurrentThreadId() != pxThreadState->ulThreadId ) + { + SwitchToThread(); + } } } -- 2.39.5