Skip to content
Snippets Groups Projects
Commit fc41d13d authored by schneider's avatar schneider
Browse files

fix(mutex): Ignore mutex handling until FreeRTOS is running

This allows to execute code which uses mutexes before the scheduler is
started. E.g. during early hardware init.
parent 1b03aacd
Branches
No related tags found
1 merge request!428Environmental Sensing Service
......@@ -23,6 +23,9 @@ void _mutex_create(struct mutex *m, const char *name)
void mutex_lock(struct mutex *m)
{
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
return;
}
int ret = xSemaphoreTake(m->_rtos_mutex, portMAX_DELAY);
/* Ensure locking was actually successful */
......@@ -31,12 +34,18 @@ void mutex_lock(struct mutex *m)
bool mutex_trylock(struct mutex *m)
{
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
return true;
}
int ret = xSemaphoreTake(m->_rtos_mutex, 0);
return ret == pdTRUE;
}
void mutex_unlock(struct mutex *m)
{
if (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) {
return;
}
/* Ensure that only the owner can unlock a mutex */
assert(mutex_get_owner(m) == xTaskGetCurrentTaskHandle());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment