Explorar el Código

[lwp] fix pmutex lock error when pmutex not init

jasonhu hace 4 años
padre
commit
526b181b93
Se han modificado 2 ficheros con 11 adiciones y 2 borrados
  1. 1 1
      components/lwp/arch/risc-v/rv64/lwp_arch.c
  2. 10 1
      components/lwp/lwp_pmutex.c

+ 1 - 1
components/lwp/arch/risc-v/rv64/lwp_arch.c

@@ -134,7 +134,7 @@ void arch_user_space_vtable_free(struct rt_lwp *lwp)
     }
 }
 
-extern long _sys_clone(void *arg[]);
+long _sys_clone(void *arg[]);
 long sys_clone(void *arg[])
 {
     return _sys_clone(arg);

+ 10 - 1
components/lwp/lwp_pmutex.c

@@ -189,7 +189,7 @@ static int _pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
     {
         rt_mutex_release(&_pmutex_lock);
         rt_set_errno(EINVAL);
-        return -RT_EINVAL;
+        return -RT_ENOMEM;  /* umutex not recored in kernel */
     }
 
     rt_mutex_release(&_pmutex_lock);
@@ -273,6 +273,15 @@ int sys_pmutex(void *umutex, int op, void *arg)
             break;
         case PMUTEX_LOCK:
             ret = _pthread_mutex_lock_timeout(umutex, (struct timespec*)arg);
+            if (ret == -RT_ENOMEM)
+            {
+                /* lock not init, try init it and lock again. */
+                ret = _pthread_mutex_init(umutex);
+                if (ret == RT_EOK)
+                {
+                    ret = _pthread_mutex_lock_timeout(umutex, (struct timespec*)arg);
+                }
+            }
             break;
         case PMUTEX_UNLOCK:
             ret = _pthread_mutex_unlock(umutex);