1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 #ifndef __OAL_MUTEX_H__
19 #define __OAL_MUTEX_H__
20
21 /* ****************************************************************************
22 1 其他头文件包含
23 **************************************************************************** */
24 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
25 #include <linux/mutex.h>
26 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
27 #include <pthread.h>
28 #endif
29 #include "hi_types_base.h"
30
31 #ifdef __cplusplus
32 #if __cplusplus
33 extern "C" {
34 #endif
35 #endif
36
37 /* ****************************************************************************
38 2 STRUCT定义
39 **************************************************************************** */
40 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
41 typedef struct mutex oal_mutex_stru;
42 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
43 typedef pthread_mutex_t oal_mutex_stru;
44 #endif
45
46 /* ****************************************************************************
47 3 枚举定义
48 **************************************************************************** */
49 /* ****************************************************************************
50 4 全局变量声明
51 **************************************************************************** */
52 /* ****************************************************************************
53 5 消息头定义
54 **************************************************************************** */
55 /* ****************************************************************************
56 6 消息定义
57 **************************************************************************** */
58 /* ****************************************************************************
59 7 宏定义
60 **************************************************************************** */
61 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
62 #define OAL_MUTEX_INIT(mutex) mutex_init(mutex)
63 #define OAL_MUTEX_DESTROY(mutex) mutex_destroy(mutex)
64 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
65 #define OAL_MUTEX_INIT(mutex) pthread_mutex_init(mutex, NULL)
66 #define OAL_MUTEX_DESTROY(mutex) pthread_mutex_destroy(mutex)
67 #endif
68
69 /* ****************************************************************************
70 8 UNION定义
71 **************************************************************************** */
72 /* ****************************************************************************
73 9 OTHERS定义
74 **************************************************************************** */
75 /* ****************************************************************************
76 10 函数声明
77 **************************************************************************** */
78 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
oal_mutex_lock(oal_mutex_stru * lock)79 static inline hi_void oal_mutex_lock(oal_mutex_stru *lock)
80 {
81 mutex_lock(lock);
82 }
83
oal_mutex_trylock(oal_mutex_stru * lock)84 static inline hi_s32 oal_mutex_trylock(oal_mutex_stru *lock)
85 {
86 return mutex_trylock(lock);
87 }
88
oal_mutex_unlock(oal_mutex_stru * lock)89 static inline hi_void oal_mutex_unlock(oal_mutex_stru *lock)
90 {
91 mutex_unlock(lock);
92 }
93 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
oal_mutex_lock(oal_mutex_stru * lock)94 static inline hi_void oal_mutex_lock(oal_mutex_stru *lock)
95 {
96 hi_s32 ret;
97 ret = pthread_mutex_lock(lock);
98 if (ret != ENOERR) {
99 }
100 }
101
oal_mutex_trylock(oal_mutex_stru * lock)102 static inline hi_s32 oal_mutex_trylock(oal_mutex_stru *lock)
103 {
104 return pthread_mutex_trylock(lock);
105 }
106
oal_mutex_unlock(oal_mutex_stru * lock)107 static inline hi_void oal_mutex_unlock(oal_mutex_stru *lock)
108 {
109 hi_s32 ret;
110 ret = pthread_mutex_unlock(lock);
111 if (ret != ENOERR) {
112 }
113 }
114 #endif
115
116 #ifdef __cplusplus
117 #if __cplusplus
118 }
119 #endif
120 #endif
121
122 #endif /* end of oal_mutex.h */
123