Userspace Resource Manager
Loading...
Searching...
No Matches
RequestManager.h
1// Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
2// SPDX-License-Identifier: BSD-3-Clause-Clear
3
4#ifndef REQUEST_MANAGER_H
5#define REQUEST_MANAGER_H
6
7#include <unordered_set>
8#include <unordered_map>
9#include <memory>
10
11#include "Request.h"
12#include "CocoTable.h"
13#include "ClientDataManager.h"
14
15typedef std::pair<Request*, int8_t> RequestInfo;
16
17enum RequestListType {
18 ACTIVE_TUNE = 0,
19 PENDING_TUNE,
20};
21
22enum RequestProcessingStatus : int8_t {
23 REQ_UNCHANGED = 0x01,
24 REQ_CANCELLED = 0x02,
25 REQ_COMPLETED = 0x04,
26 REQ_NOT_FOUND = 0x08,
27};
28
37private:
38 static std::shared_ptr<RequestManager> mReqeustManagerInstance;
39 static std::mutex instanceProtectionLock;
40
41 int64_t mTotalRequestServed;
42 std::unordered_set<Request*> mRequestsList[2];
43 std::unordered_map<int64_t, RequestInfo> mActiveRequests;
44 MinLRUCache mUntuneCache;
45 std::shared_timed_mutex mRequestMapMutex;
46
48
49 int8_t checkOwnership(Request* request, Request* targetRequest);
50 int8_t isSane(Request* request);
51 int8_t requestMatch(Request* request);
52
53public:
55
64 int8_t verifyHandle(int64_t handle);
65
74 int8_t shouldRequestBeAdded(Request* request);
75
81 int8_t addRequest(Request* request);
82
87 void removeRequest(Request* request);
88
95 RequestInfo getRequestFromMap(int64_t handle);
96
102
114 int8_t disableRequestProcessing(int64_t handle);
115
116 void markRequestAsComplete(int64_t handle);
117
118 int8_t getRequestProcessingStatus(int64_t handle);
119
120 std::vector<Request*> getPendingList();
121
132
133 void clearPending();
134
135 static std::shared_ptr<RequestManager> getInstance() {
136 if(mReqeustManagerInstance == nullptr) {
137 instanceProtectionLock.lock();
138 if(mReqeustManagerInstance == nullptr) {
139 try {
140 mReqeustManagerInstance = std::shared_ptr<RequestManager> (new RequestManager());
141 } catch(const std::bad_alloc& e) {
142 instanceProtectionLock.unlock();
143 return nullptr;
144 }
145 }
146 instanceProtectionLock.unlock();
147 }
148 return mReqeustManagerInstance;
149 }
150};
151
152#endif
RequestManager.
int8_t disableRequestProcessing(int64_t handle)
Mark the Request Handle, so that the Request won't be applied.
void moveToPendingList()
Handles Device Mode transition from RESUME to SUSPEND.
RequestInfo getRequestFromMap(int64_t handle)
Retrieve the Request with the given Handle.
int64_t getActiveReqeustsCount()
Get the current Global Active Requests Count.
int8_t addRequest(Request *request)
Add the specified request to the RequestMap.
void removeRequest(Request *request)
Remove a given request from the RequestMap.
int8_t verifyHandle(int64_t handle)
Check if a Request with the specified handle exists in the RequestMap.
int8_t shouldRequestBeAdded(Request *request)
Checks whether the specified Request should be added to the RequestMap.
Encapsulation type for a Resource Provisioning Request.
Definition Request.h:23