| 14 | #include "tpl.h" |
| 15 | |
| 16 | static int check_create(volatile __ARM_TPL_mutex_t *__vm, bool recursive = false) |
| 17 | { |
| 18 | if (__vm->data == 0) |
| 19 | { |
| 20 | uintptr_t mut_null = 0; |
| 21 | arm_tpl_mutex_struct *mutex_p = (arm_tpl_mutex_struct *)rt_malloc(sizeof(arm_tpl_mutex_struct)); |
| 22 | if (mutex_p == nullptr) return -1; |
| 23 | |
| 24 | if (recursive) |
| 25 | mutex_p->mutex = rt_mutex_create("mutexx", RT_IPC_FLAG_PRIO); |
| 26 | else |
| 27 | mutex_p->mutex = rt_mutex_create("mutexx", RT_IPC_FLAG_PRIO); |
| 28 | |
| 29 | if (mutex_p->mutex == nullptr) |
| 30 | { |
| 31 | rt_free(mutex_p); |
| 32 | return -1; |
| 33 | } |
| 34 | mutex_p->type = recursive ? RECURSIVE : NORMAL; |
| 35 | uintptr_t mut_new = reinterpret_cast<uintptr_t>(mutex_p); |
| 36 | if (!atomic_compare_exchange_strong(&__vm->data, &mut_null, mut_new)) |
| 37 | { |
| 38 | rt_mutex_delete(mutex_p->mutex); |
| 39 | rt_free(mutex_p); |
| 40 | } |
| 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static int mutexLock(arm_tpl_mutex_struct *mutex_p, rt_tick_t timeOut) |
| 46 | { |
no test coverage detected