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