threadCreate(): check for and handle missing SYS_NICE
SYS_NICE is a capability that allows a process to set thread affinity and priority, among other things (see capabilities(7) for more info). In this commit, add a function that allows to determine if the process has this capability, and try to change the thread affinity and priority, if requested. If the capability does not exist, the function will simply not attempt to change the corresponding thread attributes. To determine if the process has SYS_NICE, libcap can be used. However, it might not be installed by default. To avoid requiring another dependency, if we detect that libcap is not present, use a workaround by try to set a real-time scheduling policy; if it's present, or can be changed, we assume that the process has SYS_NICE (and clean up, if relevant). Simplify reading of capabilities
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#define _SYSTEM_H_OAI_
|
||||
#include <stdint.h>
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -44,6 +45,7 @@ void start_background_system(void);
|
||||
|
||||
void lock_memory_to_ram(void);
|
||||
|
||||
bool has_cap_sys_nice(void);
|
||||
void threadCreate(pthread_t *t, void *(*func)(void *), void *param, char *name, int affinity, int priority);
|
||||
|
||||
#define SCHED_OAI SCHED_RR
|
||||
|
||||
Reference in New Issue
Block a user