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 <stdint.h>
17
18 #include <los_pm.h>
19
20 #include "hilog_wrapper.h"
21 #include "power/suspend_ops.h"
22
HandleRunningLock(const char * name,BOOL acquire)23 static void HandleRunningLock(const char* name, BOOL acquire)
24 {
25 if (name == NULL) {
26 POWER_HILOGE("Invalid lock name");
27 return;
28 }
29
30 uint32_t ret = (acquire == TRUE) ? LOS_PmLockRequest(name) : LOS_PmLockRelease(name);
31 POWER_HILOGI("%{public}s runninglock: %{public}s, ret: %{public}u",
32 (acquire == TRUE) ? "Acquire" : "Release", name, ret);
33 }
34
RunningLockAcquire(const char * name)35 static void RunningLockAcquire(const char *name)
36 {
37 HandleRunningLock(name, TRUE);
38 }
39
RunningLockRelease(const char * name)40 static void RunningLockRelease(const char *name)
41 {
42 HandleRunningLock(name, FALSE);
43 }
44
45 static struct RunningLockOps g_ops = {
46 .Acquire = RunningLockAcquire,
47 .Release = RunningLockRelease,
48 };
49
RunningLockOpsInit()50 struct RunningLockOps* RunningLockOpsInit()
51 {
52 return &g_ops;
53 }
54