Skip to content

Commit ec19bf1

Browse files
committed
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.
1 parent 2f8e679 commit ec19bf1

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

platform/SingletonPtr.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ extern osMutexId_t singleton_mutex_id;
4343
inline static void singleton_lock(void)
4444
{
4545
#ifdef MBED_CONF_RTOS_PRESENT
46+
if (!singleton_mutex_id) {
47+
// RTOS has not booted yet so no mutex is needed
48+
return;
49+
}
4650
osMutexAcquire(singleton_mutex_id, osWaitForever);
4751
#endif
4852
}
@@ -56,6 +60,10 @@ inline static void singleton_lock(void)
5660
inline static void singleton_unlock(void)
5761
{
5862
#ifdef MBED_CONF_RTOS_PRESENT
63+
if (!singleton_mutex_id) {
64+
// RTOS has not booted yet so no mutex is needed
65+
return;
66+
}
5967
osMutexRelease(singleton_mutex_id);
6068
#endif
6169
}

0 commit comments

Comments
 (0)