1 /* 2 * This file is part of the openHiTLS project. 3 * 4 * openHiTLS is licensed under the Mulan PSL v2. 5 * You can use this software according to the terms and conditions of the Mulan PSL v2. 6 * You may obtain a copy of Mulan PSL v2 at: 7 * 8 * http://license.coscl.org.cn/MulanPSL2 9 * 10 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 11 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 12 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 13 * See the Mulan PSL v2 for more details. 14 */ 15 16 #ifndef SAL_LOCKIMPL_H 17 #define SAL_LOCKIMPL_H 18 19 #include <stdint.h> 20 #include "hitls_build.h" 21 #include "bsl_sal.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif // __cplusplus 26 27 typedef struct ThreadCallback { 28 /** 29 * @ingroup bsl_sal 30 * @brief Create a thread lock. 31 * 32 * Create a thread lock. 33 * 34 * @param lock [IN/OUT] Lock handle 35 * @retval #BSL_SUCCESS, created successfully. 36 * @retval #BSL_MALLOC_FAIL, memory space is insufficient and thread lock space cannot be applied for. 37 * @retval #BSL_SAL_ERR_UNKNOWN, thread lock initialization failed. 38 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 39 */ 40 int32_t (*pfThreadLockNew)(BSL_SAL_ThreadLockHandle *lock); 41 42 /** 43 * @ingroup bsl_sal 44 * @brief Release the thread lock. 45 * 46 * Release the thread lock. Ensure that the lock can be released when other threads obtain the lock. 47 * 48 * @param lock [IN] Lock handle 49 */ 50 void (*pfThreadLockFree)(BSL_SAL_ThreadLockHandle lock); 51 52 /** 53 * @ingroup bsl_sal 54 * @brief Lock the read operation. 55 * 56 * Lock the read operation. 57 * 58 * @param lock [IN] Lock handle 59 * @retval #BSL_SUCCESS, succeeded. 60 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 61 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 62 */ 63 int32_t (*pfThreadReadLock)(BSL_SAL_ThreadLockHandle lock); 64 65 /** 66 * @ingroup bsl_sal 67 * @brief Lock the write operation. 68 * 69 * Lock the write operation. 70 * 71 * @param lock [IN] Lock handle 72 * @retval #BSL_SUCCESS, succeeded. 73 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 74 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 75 */ 76 int32_t (*pfThreadWriteLock)(BSL_SAL_ThreadLockHandle lock); 77 78 /** 79 * @ingroup bsl_sal 80 * @brief Unlock 81 * 82 * Unlock 83 * 84 * @param lock [IN] Lock handle 85 * @retval #BSL_SUCCESS, succeeded. 86 * @retval #BSL_SAL_ERR_UNKNOWN, operation failed. 87 * @retval #BSL_SAL_ERR_BAD_PARAM, parameter error. The value of lock is NULL. 88 */ 89 int32_t (*pfThreadUnlock)(BSL_SAL_ThreadLockHandle lock); 90 91 /** 92 * @ingroup bsl_sal 93 * @brief Obtain the thread ID. 94 * 95 * Obtain the thread ID. 96 * 97 * @retval Thread ID 98 */ 99 uint64_t (*pfThreadGetId)(void); 100 } BSL_SAL_ThreadCallback; 101 102 int32_t SAL_ThreadCallback_Ctrl(BSL_SAL_CB_FUNC_TYPE type, void *funcCb); 103 104 #ifdef HITLS_BSL_SAL_LINUX 105 #ifdef HITLS_BSL_SAL_LOCK 106 int32_t SAL_RwLockNew(BSL_SAL_ThreadLockHandle *lock); 107 108 int32_t SAL_RwReadLock(BSL_SAL_ThreadLockHandle rwLock); 109 110 int32_t SAL_RwWriteLock(BSL_SAL_ThreadLockHandle rwLock); 111 112 int32_t SAL_RwUnlock(BSL_SAL_ThreadLockHandle rwLock); 113 114 void SAL_RwLockFree(BSL_SAL_ThreadLockHandle rwLock); 115 #endif 116 117 #ifdef HITLS_BSL_SAL_THREAD 118 int32_t SAL_PthreadRunOnce(uint32_t *onceControl, BSL_SAL_ThreadInitRoutine initFunc); 119 120 uint64_t SAL_GetPid(void); 121 #endif 122 #endif 123 124 #ifdef __cplusplus 125 } 126 #endif // __cplusplus 127 128 #endif // SAL_LOCKIMPL_H 129