Merge pull request #5687 from SenRamakri/sen_MutexErrorFix

Statically allocate ARMCC required mutex objects
pull/5723/head
Martin Kojtal 2017-12-20 14:36:48 +00:00 committed by GitHub
commit a762e7a622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -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;

View File

@ -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