Просмотр исходного кода

合并phread mutex 系统调用为单个入口

shaojinchun 5 лет назад
Родитель
Сommit
8cebc31310
3 измененных файлов с 37 добавлено и 13 удалено
  1. 6 0
      components/lwp/lwp.h
  2. 29 4
      components/lwp/lwp_pmutex.c
  3. 2 9
      components/lwp/lwp_syscall.c

+ 6 - 0
components/lwp/lwp.h

@@ -174,6 +174,12 @@ struct __pthread {
 #define FUTEX_WAIT  0
 #define FUTEX_WAIT  0
 #define FUTEX_WAKE  1
 #define FUTEX_WAKE  1
 
 
+/* for pmutex op */
+#define PMUTEX_INIT    0
+#define PMUTEX_LOCK    1
+#define PMUTEX_UNLOCK  2
+#define PMUTEX_DESTROY 3
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 29 - 4
components/lwp/lwp_pmutex.c

@@ -103,7 +103,7 @@ static struct rt_pmutex* pmutex_get(void *umutex, struct rt_lwp *lwp)
     return pmutex;
     return pmutex;
 }
 }
 
 
-int sys_pthread_mutex_init(void *umutex)
+static int _pthread_mutex_init(void *umutex)
 {
 {
     struct rt_lwp *lwp = RT_NULL;
     struct rt_lwp *lwp = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
@@ -153,7 +153,7 @@ int sys_pthread_mutex_init(void *umutex)
     return 0;
     return 0;
 }
 }
 
 
-int sys_pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
+static int _pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
 {
 {
     struct rt_lwp *lwp = RT_NULL;
     struct rt_lwp *lwp = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
@@ -196,7 +196,7 @@ int sys_pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout)
     return lock_ret;
     return lock_ret;
 }
 }
 
 
-int sys_pthread_mutex_unlock(void *umutex)
+static int _pthread_mutex_unlock(void *umutex)
 {
 {
     struct rt_lwp *lwp = RT_NULL;
     struct rt_lwp *lwp = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
@@ -228,7 +228,7 @@ int sys_pthread_mutex_unlock(void *umutex)
     return lock_ret;
     return lock_ret;
 }
 }
 
 
-int sys_pthread_mutex_destroy(void *umutex)
+static int _pthread_mutex_destroy(void *umutex)
 {
 {
     struct rt_lwp *lwp = RT_NULL;
     struct rt_lwp *lwp = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
     struct rt_pmutex *pmutex = RT_NULL;
@@ -259,3 +259,28 @@ int sys_pthread_mutex_destroy(void *umutex)
 
 
     return RT_EOK;
     return RT_EOK;
 }
 }
+
+int sys_pmutex(void *umutex, int op, void *arg)
+{
+    int ret = -RT_EINVAL;
+
+    switch (op)
+    {
+        case PMUTEX_INIT:
+            ret = _pthread_mutex_init(umutex);
+            break;
+        case PMUTEX_LOCK:
+            ret = _pthread_mutex_lock_timeout(umutex, (struct timespec*)arg);
+            break;
+        case PMUTEX_UNLOCK:
+            ret = _pthread_mutex_unlock(umutex);
+            break;
+        case PMUTEX_DESTROY:
+            ret = _pthread_mutex_destroy(umutex);
+            break;
+        default:
+            rt_set_errno(EINVAL);
+            break;
+    }
+    return ret;
+}

+ 2 - 9
components/lwp/lwp_syscall.c

@@ -2518,11 +2518,7 @@ int sys_clock_getres(clockid_t clk, struct timespec *ts)
 }
 }
 
 
 int sys_futex(int *uaddr, int op, int val, void *timeout, void *uaddr2, int val3);
 int sys_futex(int *uaddr, int op, int val, void *timeout, void *uaddr2, int val3);
-
-int sys_pthread_mutex_init(void *umutex);
-int sys_pthread_mutex_lock_timeout(void *umutex, struct timespec *timeout);
-int sys_pthread_mutex_unlock(void *umutex);
-int sys_pthread_mutex_destroy(void *umutex);
+int sys_pmutex(void *umutex, int op, void *arg);
 
 
 const static void* func_table[] =
 const static void* func_table[] =
 {
 {
@@ -2673,10 +2669,7 @@ const static void* func_table[] =
     (void *)sys_clock_getres,
     (void *)sys_clock_getres,
     (void *)sys_clone,           /* 130 */
     (void *)sys_clone,           /* 130 */
     (void *)sys_futex,
     (void *)sys_futex,
-    (void *)sys_pthread_mutex_init,
-    (void *)sys_pthread_mutex_lock_timeout,
-    (void *)sys_pthread_mutex_unlock,
-    (void *)sys_pthread_mutex_destroy, /* 135 */
+    (void *)sys_pmutex,
 };
 };
 
 
 const void *lwp_get_sys_api(rt_uint32_t number)
 const void *lwp_get_sys_api(rt_uint32_t number)