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 "hc_condition.h" 17 HcCondWait(struct HcConditionT * hcCond)18int HcCondWait(struct HcConditionT* hcCond) 19 { 20 if (hcCond == NULL) { 21 return -1; 22 } 23 24 return sem_wait(&hcCond->sem); 25 } 26 HcCondNotify(struct HcConditionT * hcCond)27void HcCondNotify(struct HcConditionT* hcCond) 28 { 29 if (hcCond == NULL) { 30 return; 31 } 32 33 sem_post(&hcCond->sem); 34 } 35 InitHcCond(HcCondition * hcCond,HcMutex * mutex)36int32_t InitHcCond(HcCondition* hcCond, HcMutex* mutex) 37 { 38 (void)mutex; 39 if (hcCond == NULL) { 40 return -1; 41 } 42 hcCond->wait = HcCondWait; 43 hcCond->notify = HcCondNotify; 44 hcCond->waitWithoutLock = HcCondWait; 45 hcCond->notifyWithoutLock = HcCondNotify; 46 47 // init the signal value to zero 48 return sem_init(&hcCond->sem, 0, 0); 49 } 50 DestroyHcCond(HcCondition * hcCond)51void DestroyHcCond(HcCondition* hcCond) 52 { 53 if (hcCond == NULL) { 54 return; 55 } 56 57 sem_destroy(&hcCond->sem); 58 }