\
/* listGET_OWNER_OF_NEXT_ENTRY indexes through the list, so the tasks of \
the same priority get an equal share of the processor time. */ \
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB[ xPortGetCoreID() ], &( pxReadyTasksLists[ uxTopReadyPriority ] ) ); \
+ listGET_OWNER_OF_NEXT_ENTRY( xTaskGetCurrentTaskHandle(), &( pxReadyTasksLists[ uxTopReadyPriority ] ) ); \
} /* taskSELECT_HIGHEST_PRIORITY_TASK */
/*-----------------------------------------------------------*/
/* Find the highest priority queue that contains ready tasks. */ \
portGET_HIGHEST_PRIORITY( uxTopPriority, uxTopReadyPriority ); \
configASSERT( listCURRENT_LIST_LENGTH( &( pxReadyTasksLists[ uxTopPriority ] ) ) > 0 ); \
- listGET_OWNER_OF_NEXT_ENTRY( pxCurrentTCB[ xPortGetCoreID() ], &( pxReadyTasksLists[ uxTopPriority ] ) ); \
+ listGET_OWNER_OF_NEXT_ENTRY( xTaskGetCurrentTaskHandle(), &( pxReadyTasksLists[ uxTopPriority ] ) ); \
} /* taskSELECT_HIGHEST_PRIORITY_TASK() */
/*-----------------------------------------------------------*/
* see if the parameter is NULL and returns a pointer to the appropriate TCB.
*/
/* ToDo: See if this still works for multicore. */
-#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( TCB_t * ) pxCurrentTCB[ xPortGetCoreID() ] : ( TCB_t * ) ( pxHandle ) )
+#define prvGetTCBFromHandle( pxHandle ) ( ( ( pxHandle ) == NULL ) ? ( TCB_t * ) xTaskGetCurrentTaskHandle() : ( TCB_t * ) ( pxHandle ) )
/* The item value of the event list item is normally used to hold the priority
of the task to which it belongs (coded to allow it to be held in reverse
*/
void taskYIELD_OTHER_CORE( BaseType_t xCoreID, UBaseType_t uxPriority )
{
+ TCB_t *curTCB = xTaskGetCurrentTaskHandle();
BaseType_t i;
+
if (xCoreID != tskNO_AFFINITY) {
- if ( pxCurrentTCB[ xCoreID ]->uxPriority < uxPriority ) {
+ if ( curTCB->uxPriority < uxPriority ) {
vPortYieldOtherCore( xCoreID );
}
}
static void prvAddNewTaskToReadyList( TCB_t *pxNewTCB, TaskFunction_t pxTaskCode, const BaseType_t xCoreID )
{
+ TCB_t *curTCB;
BaseType_t i;
/* Ensure interrupts don't access the task lists while the lists are being
portSETUP_TCB( pxNewTCB );
}
+ curTCB = pxCurrentTCB[ xPortGetCoreID() ];
taskEXIT_CRITICAL(&xTaskQueueMutex);
if( xSchedulerRunning != pdFALSE )
the other processor will keep running the task it's working on, and only switch to the newer
task on a timer interrupt. */
//No mux here, uxPriority is mostly atomic and there's not really any harm if this check misfires.
- if( pxCurrentTCB[ xPortGetCoreID() ]->uxPriority < pxNewTCB->uxPriority )
+ if( curTCB->uxPriority < pxNewTCB->uxPriority )
{
/* Scheduler is running. If the created task is of a higher priority than an executing task
then it should run now.
No mux here, uxPriority is mostly atomic and there's not really any harm if this check misfires.
*/
- if( tskCAN_RUN_HERE( xCoreID ) && pxCurrentTCB[ xPortGetCoreID() ]->uxPriority < pxNewTCB->uxPriority )
+ if( tskCAN_RUN_HERE( xCoreID ) && curTCB->uxPriority < pxNewTCB->uxPriority )
{
taskYIELD_IF_USING_PREEMPTION();
}
- else if( xCoreID != xPortGetCoreID() ) {
+ else if( xCoreID != xPortGetCoreID() ) {//TODO
taskYIELD_OTHER_CORE(xCoreID, pxNewTCB->uxPriority);
}
else
eTaskState eReturn;
List_t *pxStateList;
const TCB_t * const pxTCB = ( TCB_t * ) xTask;
+ TCB_t * curTCB = xTaskGetCurrentTaskHandle();
UNTESTED_FUNCTION();
configASSERT( pxTCB );
- if( pxTCB == pxCurrentTCB[ xPortGetCoreID() ] )
+ if( pxTCB == curTCB )
{
/* The task calling this function is querying its own state. */
eReturn = eRunning;
void vTaskSuspend( TaskHandle_t xTaskToSuspend )
{
TCB_t *pxTCB;
+ TCB_t *curTCB;
UNTESTED_FUNCTION();
taskENTER_CRITICAL(&xTaskQueueMutex);
}
vListInsertEnd( &xSuspendedTaskList, &( pxTCB->xGenericListItem ) );
+ curTCB = pxCurrentTCB[ xPortGetCoreID() ];
}
taskEXIT_CRITICAL(&xTaskQueueMutex);
- if( pxTCB == pxCurrentTCB[ xPortGetCoreID() ] )
+ if( pxTCB == curTCB )
{
if( xSchedulerRunning != pdFALSE )
{
//Return global reent struct if FreeRTOS isn't running,
struct _reent* __getreent() {
//No lock needed because if this changes, we won't be running anymore.
- TCB_t *currTask=pxCurrentTCB[ xPortGetCoreID() ];
+ TCB_t *currTask=xTaskGetCurrentTaskHandle();
if (currTask==NULL) {
//No task running. Return global struct.
return _GLOBAL_REENT;
BaseType_t. Please read Richard Barry's reply in the following link to a
post in the FreeRTOS support forum before reporting this as a bug! -
http://goo.gl/wu4acr */
+ unsigned state;
+
+ state = portDisableINT();
++uxSchedulerSuspended[ xPortGetCoreID() ];
+ portEnableINT(state);
}
/*----------------------------------------------------------*/
/* If xTask is NULL then we are setting our own task hook. */
if( xTask == NULL )
{
- xTCB = ( TCB_t * ) pxCurrentTCB[ xPortGetCoreID() ];
+ xTCB = ( TCB_t * ) xTaskGetCurrentTaskHandle();
}
else
{
/* If xTask is NULL then we are calling our own task hook. */
if( xTask == NULL )
{
- xTCB = ( TCB_t * ) pxCurrentTCB[ xPortGetCoreID() ];
+ xTCB = ( TCB_t * ) xTaskGetCurrentTaskHandle();
}
else
{
if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )
{
- pxTCB = prvGetTCBFromHandle( xTaskToSet );
taskENTER_CRITICAL(&xTaskQueueMutex);
+ pxTCB = prvGetTCBFromHandle( xTaskToSet );
pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;
pxTCB->pvThreadLocalStoragePointersDelCallback[ xIndex ] = xDelCallback;
taskEXIT_CRITICAL(&xTaskQueueMutex);
if( xIndex < configNUM_THREAD_LOCAL_STORAGE_POINTERS )
{
+ taskENTER_CRITICAL(&xTaskQueueMutex);
pxTCB = prvGetTCBFromHandle( xTaskToSet );
pxTCB->pvThreadLocalStoragePointers[ xIndex ] = pvValue;
+ taskEXIT_CRITICAL(&xTaskQueueMutex);
}
}
#endif /* configTHREAD_LOCAL_STORAGE_DELETE_CALLBACKS */
TaskHandle_t xTaskGetCurrentTaskHandle( void )
{
TaskHandle_t xReturn;
+ unsigned state;
- vPortCPUAcquireMutex(&xTaskQueueMutex);
+ state = portDisableINT();
xReturn = pxCurrentTCB[ xPortGetCoreID() ];
- vPortCPUReleaseMutex(&xTaskQueueMutex);
+ portEnableINT(state);
return xReturn;
}
BaseType_t xTaskGetSchedulerState( void )
{
BaseType_t xReturn;
+ unsigned state;
+ state = portDisableINT();
if( xSchedulerRunning == pdFALSE )
{
xReturn = taskSCHEDULER_NOT_STARTED;
xReturn = taskSCHEDULER_SUSPENDED;
}
}
+ portEnableINT(state);
return xReturn;
}
void *pvTaskIncrementMutexHeldCount( void )
{
+ TCB_t *curTCB;
+
/* If xSemaphoreCreateMutex() is called before any tasks have been created
- then pxCurrentTCB will be NULL. */
+ then xTaskGetCurrentTaskHandle() will be NULL. */
taskENTER_CRITICAL(&xTaskQueueMutex);
if( pxCurrentTCB[ xPortGetCoreID() ] != NULL )
{
( pxCurrentTCB[ xPortGetCoreID() ]->uxMutexesHeld )++;
}
+ curTCB = pxCurrentTCB[ xPortGetCoreID() ];
taskEXIT_CRITICAL(&xTaskQueueMutex);
- return pxCurrentTCB[ xPortGetCoreID() ];
+ return curTCB;
}
#endif /* configUSE_MUTEXES */