Allow early use of singleton lock

Allow singleton_lock and singleton_unlock to be called before the
RTOS has been started by checking for a valid mutex before locking
and unlocking it.
pull/7794/head
Russ Butler 2018-08-13 10:34:08 -05:00 committed by Russ Butler
parent 2f8e679183
commit ec19bf1de4
1 changed files with 8 additions and 0 deletions

View File

@ -43,6 +43,10 @@ extern osMutexId_t singleton_mutex_id;
inline static void singleton_lock(void)
{
#ifdef MBED_CONF_RTOS_PRESENT
if (!singleton_mutex_id) {
// RTOS has not booted yet so no mutex is needed
return;
}
osMutexAcquire(singleton_mutex_id, osWaitForever);
#endif
}
@ -56,6 +60,10 @@ inline static void singleton_lock(void)
inline static void singleton_unlock(void)
{
#ifdef MBED_CONF_RTOS_PRESENT
if (!singleton_mutex_id) {
// RTOS has not booted yet so no mutex is needed
return;
}
osMutexRelease(singleton_mutex_id);
#endif
}