1/* 2 * Copyright (c) 2021-2022 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_mutex.h" 20#include "wifi_driver_client.h" 21 22#ifdef __cplusplus 23#if __cplusplus 24extern "C" { 25#endif 26#endif 27 28OSAL_DECLARE_MUTEX(g_mutex); 29static bool g_isInitMutex = false; 30 31int32_t HalMutexInit(void) 32{ 33 int32_t ret = HDF_SUCCESS; 34 if (!g_isInitMutex) { 35 ret = OsalMutexInit(&g_mutex); 36 if (ret != HDF_SUCCESS) { 37 HDF_LOGE("%s: OsalMutexInit failed, line: %d, error no: %d", __FUNCTION__, __LINE__, ret); 38 return ret; 39 } 40 g_isInitMutex = true; 41 } 42 return ret; 43} 44 45int32_t HalMutexDestroy(void) 46{ 47 int32_t ret = HDF_SUCCESS; 48 if (g_isInitMutex) { 49 ret = OsalMutexDestroy(&g_mutex); 50 if (ret != HDF_SUCCESS) { 51 HDF_LOGE("%s: OsalMutexDestroy failed, line: %d, error no: %d", __FUNCTION__, __LINE__, ret); 52 return ret; 53 } 54 g_isInitMutex = false; 55 } 56 return ret; 57} 58 59void HalMutexLock(void) 60{ 61 if (OsalMutexLock(&g_mutex) != HDF_SUCCESS) { 62 HDF_LOGE("%s: OsalMutexLock failed, line: %d", __FUNCTION__, __LINE__); 63 } 64} 65 66void HalMutexUnlock(void) 67{ 68 if (OsalMutexUnlock(&g_mutex) != HDF_SUCCESS) { 69 HDF_LOGE("%s: OsalMutexUnlock failed, line: %d", __FUNCTION__, __LINE__); 70 } 71}