From d3f288373684cc37aeb79f5fa7c8303dc71311c6 Mon Sep 17 00:00:00 2001 From: Senthil Ramakrishnan Date: Mon, 11 Dec 2017 11:41:47 -0600 Subject: [PATCH] Statically allocate ARMCC required mutex objects --- rtos/TARGET_CORTEX/mbed_boot.c | 16 +++++++++++----- rtos/TARGET_CORTEX/mbed_rtx_conf.h | 6 ------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rtos/TARGET_CORTEX/mbed_boot.c b/rtos/TARGET_CORTEX/mbed_boot.c index 46bc1f1b11..4198b53225 100644 --- a/rtos/TARGET_CORTEX/mbed_boot.c +++ b/rtos/TARGET_CORTEX/mbed_boot.c @@ -423,9 +423,6 @@ void __rt_entry (void) { mbed_start_main(); } -typedef void *mutex; -mutex _static_mutexes[OS_MUTEX_NUM] = {NULL}; - /* ARM toolchain requires dynamically created mutexes to enforce thread safety. There's up to 8 static mutexes, protecting atexit, signalinit, stdin, stdout, stderr, stream_list, 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}; worry about freeing the allocated memory as library mutexes are only freed when the application finishes executing. */ + +typedef void *mutex; +#define OS_MUTEX_STATIC_NUM 8 +mutex _static_mutexes[OS_MUTEX_STATIC_NUM] = {NULL}; +mbed_rtos_storage_mutex_t _static_mutexes_mem[OS_MUTEX_STATIC_NUM] = {NULL}; + int _mutex_initialize(mutex *m) { osMutexAttr_t attr; @@ -445,10 +448,13 @@ int _mutex_initialize(mutex *m) mutex *slot = NULL; core_util_critical_section_enter(); - for (int i = 0; i < OS_MUTEX_NUM; i++) { + for (int i = 0; i < OS_MUTEX_STATIC_NUM; i++) { if (_static_mutexes[i] == NULL) { _static_mutexes[i] = (mutex)-1; // dummy value to reserve slot slot = &_static_mutexes[i]; + //Use the static attrs + attr.cb_size = sizeof(mbed_rtos_storage_mutex_t); + attr.cb_mem = &_static_mutexes_mem[i]; break; } } @@ -482,7 +488,7 @@ int _mutex_initialize(mutex *m) void _mutex_free(mutex *m) { mutex *slot = NULL; core_util_critical_section_enter(); - for (int i = 0; i < OS_MUTEX_NUM; i++) { + for (int i = 0; i < OS_MUTEX_STATIC_NUM; i++) { if (_static_mutexes[i] == *m) { slot = &_static_mutexes[i]; break; diff --git a/rtos/TARGET_CORTEX/mbed_rtx_conf.h b/rtos/TARGET_CORTEX/mbed_rtx_conf.h index a6cd655d9f..dfc26c3087 100644 --- a/rtos/TARGET_CORTEX/mbed_rtx_conf.h +++ b/rtos/TARGET_CORTEX/mbed_rtx_conf.h @@ -45,12 +45,6 @@ #error "OS Tickrate must be 1000 for system timing" #endif -#if defined (__CC_ARM) || (defined (__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)) -/* ARM toolchain uses up to 8 static mutexes, any further mutexes will be allocated on the heap. */ -#define OS_MUTEX_OBJ_MEM 1 -#define OS_MUTEX_NUM 8 -#endif - #if !defined(OS_STACK_WATERMARK) && (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED) #define OS_STACK_WATERMARK 1 #endif