1484543d1Sopenharmony_ci/* 2484543d1Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3484543d1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4484543d1Sopenharmony_ci * you may not use this file except in compliance with the License. 5484543d1Sopenharmony_ci * You may obtain a copy of the License at 6484543d1Sopenharmony_ci * 7484543d1Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8484543d1Sopenharmony_ci * 9484543d1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10484543d1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11484543d1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12484543d1Sopenharmony_ci * See the License for the specific language governing permissions and 13484543d1Sopenharmony_ci * limitations under the License. 14484543d1Sopenharmony_ci */ 15484543d1Sopenharmony_ci 16484543d1Sopenharmony_ci/** 17484543d1Sopenharmony_ci * @addtogroup Ffrt 18484543d1Sopenharmony_ci * @{ 19484543d1Sopenharmony_ci * 20484543d1Sopenharmony_ci * @brief ffrt provides APIs. 21484543d1Sopenharmony_ci * 22484543d1Sopenharmony_ci * 23484543d1Sopenharmony_ci * @syscap SystemCapability.Resourceschedule.Ffrt.Core 24484543d1Sopenharmony_ci */ 25484543d1Sopenharmony_ci 26484543d1Sopenharmony_ci/** 27484543d1Sopenharmony_ci * @file shared_mutex.h 28484543d1Sopenharmony_ci * 29484543d1Sopenharmony_ci * @brief Declares the rwlock interfaces in C. 30484543d1Sopenharmony_ci * 31484543d1Sopenharmony_ci * @syscap SystemCapability.Resourceschedule.Ffrt.Core 32484543d1Sopenharmony_ci * @version 1.0 33484543d1Sopenharmony_ci */ 34484543d1Sopenharmony_ci 35484543d1Sopenharmony_ci#ifndef FFRT_API_C_SHARED_MUTEX_H 36484543d1Sopenharmony_ci#define FFRT_API_C_SHARED_MUTEX_H 37484543d1Sopenharmony_ci#include "type_def_ext.h" 38484543d1Sopenharmony_ci 39484543d1Sopenharmony_ci/** 40484543d1Sopenharmony_ci * @brief Initializes a rwlock. 41484543d1Sopenharmony_ci * 42484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 43484543d1Sopenharmony_ci * @param attr Indicates a pointer to the rwlock attribute. 44484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is initialized; 45484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> otherwise. 46484543d1Sopenharmony_ci * @version 1.0 47484543d1Sopenharmony_ci */ 48484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_init(ffrt_rwlock_t* rwlock, const ffrt_rwlockattr_t* attr); 49484543d1Sopenharmony_ci 50484543d1Sopenharmony_ci/** 51484543d1Sopenharmony_ci * @brief Locks a write lock. 52484543d1Sopenharmony_ci * 53484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 54484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is locked; 55484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> or blocks the calling thread otherwise. 56484543d1Sopenharmony_ci * @version 1.0 57484543d1Sopenharmony_ci */ 58484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_wrlock(ffrt_rwlock_t* rwlock); 59484543d1Sopenharmony_ci 60484543d1Sopenharmony_ci/** 61484543d1Sopenharmony_ci * @brief Attempts to lock a write lock. 62484543d1Sopenharmony_ci * 63484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 64484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is locked; 65484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> or <b>ffrt_thrd_busy</b> otherwise. 66484543d1Sopenharmony_ci * @version 1.0 67484543d1Sopenharmony_ci */ 68484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_trywrlock(ffrt_rwlock_t* rwlock); 69484543d1Sopenharmony_ci 70484543d1Sopenharmony_ci/** 71484543d1Sopenharmony_ci * @brief Locks a read lock. 72484543d1Sopenharmony_ci * 73484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 74484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is locked; 75484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> or blocks the calling thread otherwise. 76484543d1Sopenharmony_ci * @version 1.0 77484543d1Sopenharmony_ci */ 78484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_rdlock(ffrt_rwlock_t* rwlock); 79484543d1Sopenharmony_ci 80484543d1Sopenharmony_ci/** 81484543d1Sopenharmony_ci * @brief Attempts to lock a read lock. 82484543d1Sopenharmony_ci * 83484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 84484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is locked; 85484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> or <b>ffrt_thrd_busy</b> otherwise. 86484543d1Sopenharmony_ci * @version 1.0 87484543d1Sopenharmony_ci */ 88484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_tryrdlock(ffrt_rwlock_t* rwlock); 89484543d1Sopenharmony_ci 90484543d1Sopenharmony_ci/** 91484543d1Sopenharmony_ci * @brief Unlocks a rwlock. 92484543d1Sopenharmony_ci * 93484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 94484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is unlocked; 95484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> otherwise. 96484543d1Sopenharmony_ci * @version 1.0 97484543d1Sopenharmony_ci */ 98484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_unlock(ffrt_rwlock_t* rwlock); 99484543d1Sopenharmony_ci 100484543d1Sopenharmony_ci/** 101484543d1Sopenharmony_ci * @brief Destroys a rwlock. 102484543d1Sopenharmony_ci * 103484543d1Sopenharmony_ci * @param rwlock Indicates a pointer to the rwlock. 104484543d1Sopenharmony_ci * @return Returns <b>ffrt_thrd_success</b> if the rwlock is destroyed; 105484543d1Sopenharmony_ci returns <b>ffrt_thrd_error</b> otherwise. 106484543d1Sopenharmony_ci * @version 1.0 107484543d1Sopenharmony_ci */ 108484543d1Sopenharmony_ciFFRT_C_API int ffrt_rwlock_destroy(ffrt_rwlock_t* rwlock); 109484543d1Sopenharmony_ci 110484543d1Sopenharmony_ci#endif 111