1 /*
2 * Copyright (c) 2024-2024 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 "hks_upgrade_lock.h"
17
18 #include "hks_condition.h"
19 #include "hks_mutex.h"
20 #include "hks_template.h"
21 #include "hks_type_enum.h"
22
23 #include <rwlock.h>
24 #include <atomic>
25
26 namespace OHOS {
27 namespace Security {
28 namespace Hks {
29 static HksCondition *g_powerOnUpgradeCondition = NULL;
30 OHOS::Utils::RWLock g_upgradeOrRequestLock(true);
31
HksProcessConditionCreate(void)32 int32_t HksProcessConditionCreate(void)
33 {
34 g_powerOnUpgradeCondition = HksConditionCreate();
35 HKS_IF_NULL_LOGE_RETURN(g_powerOnUpgradeCondition, HKS_ERROR_BAD_STATE, "create process condition failed.")
36 return HKS_SUCCESS;
37 }
38
HksWaitIfPowerOnUpgrading(void)39 int32_t HksWaitIfPowerOnUpgrading(void)
40 {
41 int32_t ret = HksConditionWait(g_powerOnUpgradeCondition);
42 HKS_IF_NOT_SUCC_LOGE_RETURN(ret, HKS_ERROR_BAD_STATE,
43 "HksWaitIfPowerOnUpgrading HksConditionWait fail %" LOG_PUBLIC "d", ret)
44 return HKS_SUCCESS;
45 }
46
HksUpgradeOnPowerOnDoneNotifyAll(void)47 void HksUpgradeOnPowerOnDoneNotifyAll(void)
48 {
49 HKS_LOG_I("HksUpgradeOnPowerOnDoneNotifyAll HksConditionNotifyAll");
50 int32_t ret = HksConditionNotifyAll(g_powerOnUpgradeCondition);
51 if (ret != HKS_SUCCESS) {
52 HKS_LOG_E("HksUpgradeOnPowerOnDoneNotifyAll HksConditionNotifyAll fail %" LOG_PUBLIC "d", ret);
53 } else {
54 HKS_LOG_I("HksUpgradeOnPowerOnDoneNotifyAll HksConditionNotifyAll ok!");
55 }
56 }
57 }
58 }
59 }
60