• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #pragma once
17 
18 #include <android/system/suspend/internal/WakeupInfo.h>
19 
20 #include <utils/Mutex.h>
21 
22 #include <list>
23 #include <unordered_map>
24 
25 using ::android::system::suspend::internal::WakeupInfo;
26 
27 namespace android {
28 namespace system {
29 namespace suspend {
30 namespace V1_0 {
31 
32 /*
33  * WakeupList to collect wakeup stats.
34  * This class is thread safe.
35  */
36 class WakeupList {
37    public:
38     WakeupList(size_t capacity);
39     void getWakeupStats(std::vector<WakeupInfo>* wakeups) const;
40     void update(const std::vector<std::string>& wakeupReasons);
41 
42    private:
43     void evict() REQUIRES(mLock);
44     void insert(WakeupInfo entry) REQUIRES(mLock);
45     void erase(std::list<WakeupInfo>::iterator entry) REQUIRES(mLock);
46 
47     size_t mCapacity;
48     mutable std::mutex mLock;
49     std::list<WakeupInfo> mWakeups GUARDED_BY(mLock);
50     std::unordered_map<std::string, std::list<WakeupInfo>::iterator> mLookupTable GUARDED_BY(mLock);
51 };
52 
53 }  // namespace V1_0
54 }  // namespace suspend
55 }  // namespace system
56 }  // namespace android