• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #ifndef OHOS_MEMORY_MEMMGR_BUNDLE_PRIORITY_INFO_H
17 #define OHOS_MEMORY_MEMMGR_BUNDLE_PRIORITY_INFO_H
18 
19 #include <string>
20 #include <map>
21 #include <mutex>
22 
23 #include "reclaim_priority_constants.h"
24 #include "process_priority_info.h"
25 
26 namespace OHOS {
27 namespace Memory {
28 class BundlePriorityInfo {
29 public:
30     using ProcessesInfoMap = std::map<pid_t, ProcessPriorityInfo>;
31     explicit BundlePriorityInfo(const std::string &name, int bundleUid);
32     explicit BundlePriorityInfo(const std::string &name, int bundleUid, int priority);
33     explicit BundlePriorityInfo(const std::string &name, int bundleUid, int priority, int accountId, BundleState state);
34     BundlePriorityInfo(const BundlePriorityInfo &copyBundle);
35     inline bool operator<(const BundlePriorityInfo &tmp) const
36     {
37         return priority_ < tmp.priority_;
38     }
39     std::string name_;
40     int uid_;
41     ProcessesInfoMap procs_;
42     int priority_;
43     int accountId_;
44     BundleState state_;
45     std::mutex bundleLock_;
46 
47     bool HasProc(pid_t pid);
48     void AddProc(ProcessPriorityInfo &newProcess);
49     void RemoveProcByPid(pid_t pid);
50     ProcessPriorityInfo& FindProcByPid(pid_t pid);
51     int GetProcsCount();
52     int GetMinProcPriority();
53     void SetPriority(int targetPriority);
54     void UpdatePriority();
55     BundleState GetState();
56     void SetState(BundleState state);
57     void IncreaseProcsPriority(int delta);
58 };
59 } // namespace Memory
60 } // namespace OHOS
61 #endif // OHOS_MEMORY_MEMMGR_BUNDLE_PRIORITY_INFO_H
62