xStreamBufferReset and Mutex is buggy

seagull_kamome wrote on Friday, June 15, 2018:

I guess that my previous post got filtered. So, this is second post.

Hi FreeRTOS developer team.

I’m currently testing FreeRTOS kernel for our project. And, found
something weird.

xStreamBufferReset doesn’t save a STATICALLY_ALLOCATED flag in ucFlags. So,
it will crashes our system at vStreamBufferDelete by calling free().

xSemaphoreGet with Mutex doesn’t give priority back to that mutex holder
when timed out

Sorry. I can’t explain well in english so I’ll show the unit test code.


static SemaphoreHandle_t mx1;

static unsigned int volatile test_counter;

static TaskHandle_t test_task;

static void test_task_main_1(void* args __unused) {

xSemaphoreTake(mx1, 10); // will be fail.


ulTaskNotifyTake(0, portMAX_DELAY);


xSemaphoreTake(mx1, portMAX_DELAY);


ulTaskNotifyTake(0, portMAX_DELAY);





and test task. This task has priority (tskIDLE_PRIORITY + 2).

should_eq(xTaskGetCurrentTaskHandle(), xSemaphoreGetMutexHolder(mx1)); //
precondition check

should_eq(tskIDLE_PRIORITY + 2, uxTaskPriorityGet(NULL)); // precondition

test_counter = 0;

should_eq(pdTRUE, xTaskCreate(test_task_main_1, “TSK”,
configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY + 3, &test_task));

should_eq(tskIDLE_PRIORITY + 3, uxTaskPriorityGet(NULL)); // OK. the
priority is inherited.

should_eq(0, test_counter); // OK. the task still waiting.


should_eq(1, test_counter); // OK. the task already timed out

// All tests is OK until here.

// BUG? FreeRTOS never descent priority into base when the waiting task
got timeout.

should_eq(tskIDLE_PRIORITY + 2, uxTaskPriorityGet(NULL)); // Fail: actual

xTaskNotifyGive(test_task); // elevate again. the task will preempt control.

taskYIELD(); // but actually not.

should_eq(2, test_counter); // OK. the task waiting again.

should_eq(tskIDLE_PRIORITY + 3, uxTaskPriorityGet(NULL)); // OK

should_eq(pdTRUE, xSemaphoreGive(mx1)); // OK

should_eq(3, test_counter); // OK

should_eq(test_task, xSemaphoreGetMutexHolder(mx1)); // OK

should_eq(tskIDLE_PRIORITY + 2, uxTaskPriorityGet(NULL)); // Fail:! I’m
still in tskIDLE_PRIORITY + 3!!!


seagull_kamome wrote on Monday, June 18, 2018:

Finally. I found this comment .

            /* Only disinherit if no other mutexes are held.  This is a
			simplification in the priority inheritance implementation.  If
			the task that holds the mutex is also holding other mutexes then
			the other mutexes may have caused the priority inheritance. */