-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpriority.h
More file actions
50 lines (34 loc) · 970 Bytes
/
Copy pathpriority.h
File metadata and controls
50 lines (34 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Functions for handling POSIX thread scheduling policy/priority
*/
#ifndef PRIORITY_H
#define PRIORITY_H
#include <sched.h>
#include <pthread.h>
#include <thread>
namespace priority
{
inline bool set_realtime(std::thread::native_handle_type handle)
{
sched_param sch;
auto priority = sched_get_priority_max(SCHED_FIFO);
sch.sched_priority = priority > 0 ? priority : 1; // FIFO must be at least 1
return pthread_setschedparam(handle, SCHED_FIFO, &sch) == 0;
}
inline bool is_realtime(std::thread::native_handle_type handle)
{
sched_param sch;
int policy;
if (pthread_getschedparam(handle, &policy, &sch) == 0)
return policy == SCHED_FIFO || policy == SCHED_RR;
return false;
}
inline int current_priority(std::thread::native_handle_type handle)
{
sched_param sch;
int policy;
if (pthread_getschedparam(handle, &policy, &sch) == 0)
return sch.sched_priority;
return -1;
}
} // namespace priority
#endif // PRIORITY_H