1 /*
2  * Copyright 2021 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 <sched.h>
18 #include <sys/types.h>
19 
20 namespace {
21 constexpr int kRealTimeFifoSchedulingPriority = 1;
22 }  // namespace
23 
thread_scheduler_enable_real_time(pid_t linux_tid)24 bool thread_scheduler_enable_real_time(pid_t linux_tid) {
25   struct sched_param rt_params = {.sched_priority =
26                                       kRealTimeFifoSchedulingPriority};
27   return sched_setscheduler(linux_tid, SCHED_FIFO, &rt_params) == 0;
28 }
29 
thread_scheduler_get_priority_range(int & min,int & max)30 bool thread_scheduler_get_priority_range(int& min, int& max) {
31   min = sched_get_priority_min(SCHED_FIFO);
32   max = sched_get_priority_max(SCHED_FIFO);
33   return (min != -1 && max != -1) ? true : false;
34 }
35