@@ -423,9 +423,6 @@ void __rt_entry (void) {
423
423
mbed_start_main ();
424
424
}
425
425
426
- typedef void * mutex ;
427
- mutex _static_mutexes [OS_MUTEX_NUM ] = {NULL };
428
-
429
426
/* ARM toolchain requires dynamically created mutexes to enforce thread safety. There's
430
427
up to 8 static mutexes, protecting atexit, signalinit, stdin, stdout, stderr, stream_list,
431
428
fp_trap_init and the heap. Additionally for each call to fopen one extra mutex will be
@@ -436,6 +433,12 @@ mutex _static_mutexes[OS_MUTEX_NUM] = {NULL};
436
433
worry about freeing the allocated memory as library mutexes are only freed when the
437
434
application finishes executing.
438
435
*/
436
+
437
+ typedef void * mutex ;
438
+ #define OS_MUTEX_STATIC_NUM 8
439
+ mutex _static_mutexes [OS_MUTEX_STATIC_NUM ] = {NULL };
440
+ mbed_rtos_storage_mutex_t _static_mutexes_mem [OS_MUTEX_STATIC_NUM ] = {NULL };
441
+
439
442
int _mutex_initialize (mutex * m )
440
443
{
441
444
osMutexAttr_t attr ;
@@ -445,10 +448,13 @@ int _mutex_initialize(mutex *m)
445
448
446
449
mutex * slot = NULL ;
447
450
core_util_critical_section_enter ();
448
- for (int i = 0 ; i < OS_MUTEX_NUM ; i ++ ) {
451
+ for (int i = 0 ; i < OS_MUTEX_STATIC_NUM ; i ++ ) {
449
452
if (_static_mutexes [i ] == NULL ) {
450
453
_static_mutexes [i ] = (mutex )- 1 ; // dummy value to reserve slot
451
454
slot = & _static_mutexes [i ];
455
+ //Use the static attrs
456
+ attr .cb_size = sizeof (mbed_rtos_storage_mutex_t );
457
+ attr .cb_mem = & _static_mutexes_mem [i ];
452
458
break ;
453
459
}
454
460
}
@@ -482,7 +488,7 @@ int _mutex_initialize(mutex *m)
482
488
void _mutex_free (mutex * m ) {
483
489
mutex * slot = NULL ;
484
490
core_util_critical_section_enter ();
485
- for (int i = 0 ; i < OS_MUTEX_NUM ; i ++ ) {
491
+ for (int i = 0 ; i < OS_MUTEX_STATIC_NUM ; i ++ ) {
486
492
if (_static_mutexes [i ] == * m ) {
487
493
slot = & _static_mutexes [i ];
488
494
break ;
0 commit comments