1 /*
2 * Copyright (C) 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
17 #include <processgroup/sched_policy.h>
18 #include <sys/resource.h>
19
20 #include "utils.h"
21 #include "debug.h"
22
23 namespace android {
24 namespace hardware {
25 namespace camera {
26 namespace provider {
27 namespace implementation {
28
setThreadPriority(const SchedPolicy policy,const int prio)29 bool setThreadPriority(const SchedPolicy policy, const int prio) {
30 int e = set_sched_policy(0, policy);
31 if (e < 0) {
32 return FAILURE_V(false, "set_sched_policy(%d) failed with %s (%d)",
33 static_cast<int>(policy), strerror(-e), -e);
34 }
35
36 if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
37 e = errno;
38 return FAILURE_V(false, "setpriority(%d) failed with %s (%d)",
39 prio, strerror(e), e);
40 }
41
42 return true;
43 }
44
45 } // namespace implementation
46 } // namespace provider
47 } // namespace camera
48 } // namespace hardware
49 } // namespace android
50