#include "FreeRTOS.h" #include "semphr.h" SemaphoreHandle_t malloc_mutex = NULL; void __malloc_lock(struct _reent *r) { // if the mutex is not initialized yet, no task have been started either if (malloc_mutex != NULL) { xSemaphoreTakeRecursive(malloc_mutex, portMAX_DELAY); } } void __malloc_unlock(struct _reent *r) { // if the mutex is not initialized yet, no task have been started either if (malloc_mutex != NULL) { xSemaphoreGiveRecursive(malloc_mutex); } }