blob: 95cd5d199ae396495222874b93b68a97ca9a6f60 [file] [log] [blame]
Tony Huang9ac5e6e2023-08-24 09:01:44 +00001/*
2 * Copyright 2023 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#include <sys/types.h>
17
18#include "SmallAreaDetectionAllowMappings.h"
19
20namespace android::scheduler {
21void SmallAreaDetectionAllowMappings::update(
22 std::vector<std::pair<uid_t, float>>& uidThresholdMappings) {
23 std::lock_guard lock(mLock);
24 mMap.clear();
25 for (std::pair<uid_t, float> row : uidThresholdMappings) {
26 if (!isValidThreshold(row.second)) continue;
27
28 mMap.emplace(row.first, row.second);
29 }
30}
31
32void SmallAreaDetectionAllowMappings::setThesholdForUid(uid_t uid, float threshold) {
33 if (!isValidThreshold(threshold)) return;
34
35 std::lock_guard lock(mLock);
36 mMap.emplace(uid, threshold);
37}
38
39std::optional<float> SmallAreaDetectionAllowMappings::getThresholdForUid(uid_t uid) {
40 std::lock_guard lock(mLock);
41 const auto iter = mMap.find(uid);
42 if (iter != mMap.end()) {
43 return iter->second;
44 }
45 return std::nullopt;
46}
47} // namespace android::scheduler