mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5687 from SenRamakri/sen_MutexErrorFix
Statically allocate ARMCC required mutex objectspull/5723/head
commit
a762e7a622
|
|
@ -423,9 +423,6 @@ void __rt_entry (void) {
|
||||||
mbed_start_main();
|
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
|
/* 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,
|
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
|
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
|
worry about freeing the allocated memory as library mutexes are only freed when the
|
||||||
application finishes executing.
|
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)
|
int _mutex_initialize(mutex *m)
|
||||||
{
|
{
|
||||||
osMutexAttr_t attr;
|
osMutexAttr_t attr;
|
||||||
|
|
@ -445,10 +448,13 @@ int _mutex_initialize(mutex *m)
|
||||||
|
|
||||||
mutex *slot = NULL;
|
mutex *slot = NULL;
|
||||||
core_util_critical_section_enter();
|
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) {
|
if (_static_mutexes[i] == NULL) {
|
||||||
_static_mutexes[i] = (mutex)-1; // dummy value to reserve slot
|
_static_mutexes[i] = (mutex)-1; // dummy value to reserve slot
|
||||||
slot = &_static_mutexes[i];
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -482,7 +488,7 @@ int _mutex_initialize(mutex *m)
|
||||||
void _mutex_free(mutex *m) {
|
void _mutex_free(mutex *m) {
|
||||||
mutex *slot = NULL;
|
mutex *slot = NULL;
|
||||||
core_util_critical_section_enter();
|
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) {
|
if (_static_mutexes[i] == *m) {
|
||||||
slot = &_static_mutexes[i];
|
slot = &_static_mutexes[i];
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,6 @@
|
||||||
#error "OS Tickrate must be 1000 for system timing"
|
#error "OS Tickrate must be 1000 for system timing"
|
||||||
#endif
|
#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)
|
#if !defined(OS_STACK_WATERMARK) && (defined(MBED_STACK_STATS_ENABLED) && MBED_STACK_STATS_ENABLED)
|
||||||
#define OS_STACK_WATERMARK 1
|
#define OS_STACK_WATERMARK 1
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue