Fix auto_init_recursive_mutex definition for C++ (#875)

Co-authored-by: Graham Sanderson <graham.sanderson@gmail.com>
This commit is contained in:
Earle F. Philhower, III 2022-06-20 10:47:46 -07:00 committed by GitHub
parent 33818dd0bd
commit 4c49427bf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -289,7 +289,7 @@ static inline bool recursive_mutex_is_initialized(recursive_mutex_t *mtx) {
* *
* But the initialization of the mutex is performed automatically during runtime initialization * But the initialization of the mutex is performed automatically during runtime initialization
*/ */
#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 */ } #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 */ }, .owner = 0, .enter_count = 0 }
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -110,6 +110,9 @@ __force_inline int something_inlined(int x) {
return x * 2; return x * 2;
} }
auto_init_mutex(mutex);
auto_init_recursive_mutex(recursive_mutex);
int main(void) { int main(void) {
spiggle(); spiggle();
@ -118,6 +121,12 @@ int main(void) {
printf("HI %d\n", something_inlined((int)time_us_32())); printf("HI %d\n", something_inlined((int)time_us_32()));
puts("Hello Everything!"); puts("Hello Everything!");
puts("Hello Everything2!"); puts("Hello Everything2!");
hard_assert(mutex_try_enter(&mutex, NULL));
hard_assert(!mutex_try_enter(&mutex, NULL));
hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL));
hard_assert(recursive_mutex_try_enter(&recursive_mutex, NULL));
// this should compile as we are Cortex M0+ // this should compile as we are Cortex M0+
__asm volatile("SVC #3"); __asm volatile("SVC #3");
} }