Skip to content
Snippets Groups Projects
Commit d06ebe16 authored by graham sanderson's avatar graham sanderson
Browse files

fix auto_init_recursive_mutex in c++

parent 33818dd0
No related tags found
No related merge requests found
......@@ -289,7 +289,11 @@ static inline bool recursive_mutex_is_initialized(recursive_mutex_t *mtx) {
*
* But the initialization of the mutex is performed automatically during runtime initialization
*/
#ifdef __cplusplus
#define auto_init_recursive_mutex(name) static __attribute__((section(".mutex_array"))) recursive_mutex_t name = { (spin_lock_t *)1 };
#else
#define auto_init_recursive_mutex(name) static __attribute__((section(".mutex_array"))) recursive_mutex_t name = { .core.spin_lock = (spin_lock_t *)1 /* marker for runtime_init */ }
#endif
#ifdef __cplusplus
}
......
......@@ -110,6 +110,9 @@ __force_inline int something_inlined(int x) {
return x * 2;
}
auto_init_mutex(mutex);
auto_init_recursive_mutex(recursive_mutex);
int main(void) {
spiggle();
......@@ -118,6 +121,12 @@ int main(void) {
printf("HI %d\n", something_inlined((int)time_us_32()));
puts("Hello Everything!");
puts("Hello Everything2!");
assert(mutex_try_enter(&mutex, NULL));
assert(!mutex_try_enter(&mutex, NULL));
assert(recursive_mutex_try_enter(&recursive_mutex, NULL));
assert(recursive_mutex_try_enter(&recursive_mutex, NULL));
// this should compile as we are Cortex M0+
__asm volatile("SVC #3");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment