• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "wifi_hal_util.h"
17 #include "hdf_base.h"
18 #include "hdf_log.h"
19 #include "osal.h"
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif
26 
27 OSAL_DECLARE_MUTEX(g_mutex);
28 static bool g_isInitMutex = false;
29 
HalMutexInit()30 int32_t HalMutexInit()
31 {
32     int32_t ret = HDF_SUCCESS;
33     if (!g_isInitMutex) {
34         ret = OsalMutexInit(&g_mutex);
35         if (ret != HDF_SUCCESS) {
36             HDF_LOGE("%s: OsalMutexInit failed, line: %d, error no: %d", __FUNCTION__, __LINE__, ret);
37             return ret;
38         }
39         g_isInitMutex = true;
40     }
41     return ret;
42 }
43 
HalMutexDestroy()44 int32_t HalMutexDestroy()
45 {
46     int32_t ret = HDF_SUCCESS;
47     if (g_isInitMutex) {
48         ret = OsalMutexDestroy(&g_mutex);
49         if (ret != HDF_SUCCESS) {
50             HDF_LOGE("%s: OsalMutexDestroy failed, line: %d, error no: %d", __FUNCTION__, __LINE__, ret);
51             return ret;
52         }
53         g_isInitMutex = false;
54     }
55     return ret;
56 }
57 
HalMutexLock()58 void HalMutexLock()
59 {
60     if (OsalMutexLock(&g_mutex) != HDF_SUCCESS) {
61         HDF_LOGE("%s: OsalMutexLock failed, line: %d\n", __FUNCTION__, __LINE__);
62     }
63 }
64 
HalMutexUnlock()65 void HalMutexUnlock()
66 {
67     if (OsalMutexUnlock(&g_mutex) != HDF_SUCCESS) {
68         HDF_LOGE("%s: OsalMutexUnlock failed, line: %d\n", __FUNCTION__, __LINE__);
69     }
70 }