Hi,
I’m writing a module for conditional variables/monitor and I noticed that two calls and an explicit yield all request a context switch:
void CWait( SemaphoreHandle_t& mutex )
{
taskENTER_CRITICAL();
{
TaskHandle_t self = xTaskGetCurrentTaskHandle();
vTaskSuspend( self ); //// here ...
xSemaphoreGive( mutex ); //// here ...
configASSERT( this->len < this->max );
this->queue[ this->tail++ ] = self;
if( this->tail == this->max ) this->tail = 0;
++this->len;
} taskEXIT_CRITICAL();
taskYIELD(); //// and here
xSemaphoreTake( mutex, portMAX_DELAY );
}
Although interrupts are disabled because of the critical section, I wonder if the way that vTaskSuspend()
context switch request interferes or nullifies the context switch of xSemaphoreGive()
when exiting the CS. Even more, in such case, does the call to taskYield make any sense since a context switch request was already made?
Thank you !!!