void vPortYield( void ) { pthread_t xTaskToSuspend; pthread_t xTaskToResume; if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) { xTaskToSuspend = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); vTaskSwitchContext(); xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); if ( xTaskToSuspend != xTaskToResume ) { /* Remember and switch the critical nesting. */ prvSetTaskCriticalNesting( xTaskToSuspend, uxCriticalNesting ); uxCriticalNesting = prvGetTaskCriticalNesting( xTaskToResume ); /* Switch tasks. */ prvResumeThread( xTaskToResume ); prvSuspendThread( xTaskToSuspend ); } else { /* Yielding to self */ (void)pthread_mutex_unlock( &xSingleThreadMutex ); } } }
void vPortSystemTickHandler( int sig ) { pthread_t xTaskToSuspend; pthread_t xTaskToResume; (void)(sig); if ( ( pdTRUE == xInterruptsEnabled ) && ( pdTRUE != xServicingTick ) ) { if ( 0 == pthread_mutex_trylock( &xSingleThreadMutex ) ) { xServicingTick = pdTRUE; xTaskToSuspend = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); /* Tick Increment. */ xTaskIncrementTick(); /* Select Next Task. */ #if ( configUSE_PREEMPTION == 1 ) vTaskSwitchContext(); #endif xTaskToResume = prvGetThreadHandle( xTaskGetCurrentTaskHandle() ); /* The only thread that can process this tick is the running thread. */ if ( xTaskToSuspend != xTaskToResume ) { /* Remember and switch the critical nesting. */ prvSetTaskCriticalNesting( xTaskToSuspend, uxCriticalNesting ); uxCriticalNesting = prvGetTaskCriticalNesting( xTaskToResume ); /* Resume next task. */ prvResumeThread( xTaskToResume ); /* Suspend the current task. */ prvSuspendThread( xTaskToSuspend ); } else { /* Release the lock as we are Resuming. */ (void)pthread_mutex_unlock( &xSingleThreadMutex ); } xServicingTick = pdFALSE; } else { xPendYield = pdTRUE; } } else { xPendYield = pdTRUE; } }
void *prvWaitForStart( void * pvParams ) { xParams * pxParams = ( xParams * )pvParams; pdTASK_CODE pvCode = pxParams->pxCode; void * pParams = pxParams->pvParams; vPortFree( pvParams ); pthread_cleanup_push( prvDeleteThread, (void *)pthread_self() ); if ( 0 == pthread_mutex_lock( &xSingleThreadMutex ) ) { prvSuspendThread( pthread_self() ); } pvCode( pParams ); pthread_cleanup_pop( 1 ); return (void *)NULL; }