• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hilog_wrapper.h"
17 #include "power/suspend_ops.h"
18 
19 static struct AutoSuspendOps* g_suspendOps = NULL;
20 static struct RunningLockOps* g_runningLockOps = NULL;
21 
RunningLockHubLock(const char * name)22 void RunningLockHubLock(const char* name)
23 {
24     if (!g_runningLockOps || !g_suspendOps) {
25         POWER_HILOGE("Invalid running lock or suspend ops");
26         return;
27     }
28     g_runningLockOps->Acquire(name);
29     /*
30      * Because the upper layer call can ensure the acquirment of locks, it is simple to implement here.
31      * It's better to maintain a running lock map by name.
32      */
33     g_suspendOps->IncSuspendBlockCounter();
34 }
35 
RunningLockHubUnlock(const char * name)36 void RunningLockHubUnlock(const char* name)
37 {
38     if (!g_runningLockOps || !g_suspendOps) {
39         POWER_HILOGE("Invalid running lock or suspend ops");
40         return;
41     }
42     g_runningLockOps->Release(name);
43     g_suspendOps->DecSuspendBlockCounter();
44 }
45 
RunningLockHubInit(struct AutoSuspendOps * suspendOps)46 BOOL RunningLockHubInit(struct AutoSuspendOps* suspendOps)
47 {
48     g_runningLockOps = RunningLockOpsInit();
49     if (!g_runningLockOps) {
50         POWER_HILOGE("Failed to init runninglock ops");
51         return FALSE;
52     }
53     g_suspendOps = suspendOps;
54     return TRUE;
55 }
56