Skip to content

Commit a762e7a

Browse files
authored
Merge pull request #5687 from SenRamakri/sen_MutexErrorFix
Statically allocate ARMCC required mutex objects
2 parents a7aaee3 + d3f2883 commit a762e7a

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

rtos/TARGET_CORTEX/mbed_boot.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,6 @@ void __rt_entry (void) {
423423
mbed_start_main();
424424
}
425425

426-
typedef void *mutex;
427-
mutex _static_mutexes[OS_MUTEX_NUM] = {NULL};
428-
429426
/* ARM toolchain requires dynamically created mutexes to enforce thread safety. There's
430427
up to 8 static mutexes, protecting atexit, signalinit, stdin, stdout, stderr, stream_list,
431428
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};
436433
worry about freeing the allocated memory as library mutexes are only freed when the
437434
application finishes executing.
438435
*/
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+
439442
int _mutex_initialize(mutex *m)
440443
{
441444
osMutexAttr_t attr;
@@ -445,10 +448,13 @@ int _mutex_initialize(mutex *m)
445448

446449
mutex *slot = NULL;
447450
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++) {
449452
if (_static_mutexes[i] == NULL) {
450453
_static_mutexes[i] = (mutex)-1; // dummy value to reserve slot
451454
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];
452458
break;
453459
}
454460
}
@@ -482,7 +488,7 @@ int _mutex_initialize(mutex *m)
482488
void _mutex_free(mutex *m) {
483489
mutex *slot = NULL;
484490
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++) {
486492
if (_static_mutexes[i] == *m) {
487493
slot = &_static_mutexes[i];
488494
break;

rtos/TARGET_CORTEX/mbed_rtx_conf.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@
4545
#error "OS Tickrate must be 1000 for system timing"
4646
#endif
4747

48-
#if defined (__CC_ARM) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
49-
/* ARM toolchain uses up to 8 static mutexes, any further mutexes will be allocated on the heap. */
50-
#define OS_MUTEX_OBJ_MEM 1
51-
#define OS_MUTEX_NUM 8
52-
#endif
53-
5448
#if !defined(OS_STACK_WATERMARK) && (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED)
5549
#define OS_STACK_WATERMARK 1
5650
#endif

0 commit comments

Comments
 (0)