long lWaitingInterruptAck; \r
\r
/* Handle of the thread that executes the task. */\r
- void * pvThread; \r
+ void *pvThread;\r
+\r
+ /* Used to check that the thread that is supposed to be running in indeed\r
+ the thread that is running. */\r
+ unsigned long ulThreadId;\r
+\r
} xThreadState;\r
\r
/* Pseudo interrupts waiting to be processed. This is a bit mask where each\r
pxThreadState = ( xThreadState * ) ( pxTopOfStack - sizeof( xThreadState ) );\r
\r
/* Create the thread itself. */\r
- pxThreadState->pvThread = ( void * ) CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED, NULL );\r
+ pxThreadState->pvThread = CreateThread( NULL, 0, ( LPTHREAD_START_ROUTINE ) pxCode, pvParameters, CREATE_SUSPENDED, &( pxThreadState->ulThreadId ) );\r
SetThreadPriorityBoost( pxThreadState->pvThread, TRUE );\r
pxThreadState->lWaitingInterruptAck = pdFALSE;\r
SetThreadPriority( pxThreadState->pvThread, THREAD_PRIORITY_IDLE );\r
\r
void vPortCheckCorrectThreadIsRunning( void )\r
{\r
-xThreadState *pxThreadState = ( xThreadState * ) *( ( unsigned long * ) pxCurrentTCB );\r
+xThreadState *pxThreadState;\r
\r
/* When switching threads, Windows does not always seem to run the selected\r
thread immediately. This function can be called to check if the thread\r
that is currently running is the thread that is responsible for executing\r
the task selected by the real time scheduler. */\r
- if( GetCurrentThread() != pxThreadState->pvThread )\r
+ if( xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED )\r
{\r
- SwitchToThread();\r
+ pxThreadState = ( xThreadState * ) *( ( unsigned long * ) pxCurrentTCB );\r
+\r
+ if( GetCurrentThreadId() != pxThreadState->ulThreadId )\r
+ {\r
+ SwitchToThread();\r
+ }\r
}\r
}\r
\r