/* Change Logs: Date Author Notes  flybreak the first version.  */
static int check_create(volatile __ARM_TPL_mutex_t *__vm, bool recursive=false)
/* Change Logs: Date Author Notes  flybreak the first version.  */
static int check_create(volatile __ARM_TPL_mutex_t *__vm, bool recursive=false)
{
    if (__vm->data == 0)
    {
        uintptr_t mut_null = 0;
        arm_tpl_mutex_struct *mutex_p = (arm_tpl_mutex_struct *)rt_malloc(sizeof(arm_tpl_mutex_struct));
        if (mutex_p == nullptr) return -1;
        if (recursive)
            mutex_p->mutex = rt_mutex_create("mutexx", RT_IPC_FLAG_PRIO);
        else
            mutex_p->mutex = rt_mutex_create("mutexx", RT_IPC_FLAG_PRIO);
        if (mutex_p->mutex == nullptr)
        {
            rt_free(mutex_p);
            return -1;
        }
        mutex_p->type = recursive ? RECURSIVE : NORMAL;
        uintptr_t mut_new = reinterpret_cast<uintptr_t>(mutex_p);
        if (!atomic_compare_exchange_strong(&__vm->data, &mut_null, mut_new))
        {
            rt_mutex_delete(mutex_p->mutex);
            rt_free(mutex_p);
        }
    }
    return 0;
}