Default sched policy for prio=-2 threads

master
Ismael Gomez 7 years ago
parent a08c662028
commit e867184aa3

@ -51,6 +51,8 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void
pthread_attr_t attr; pthread_attr_t attr;
struct sched_param param; struct sched_param param;
cpu_set_t cpuset; cpu_set_t cpuset;
bool attr_enable = false;
if (prio_offset >= 0) { if (prio_offset >= 0) {
param.sched_priority = sched_get_priority_max(SCHED_FIFO) - prio_offset; param.sched_priority = sched_get_priority_max(SCHED_FIFO) - prio_offset;
pthread_attr_init(&attr); pthread_attr_init(&attr);
@ -64,6 +66,21 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void
perror("pthread_attr_setschedparam"); perror("pthread_attr_setschedparam");
fprintf(stderr, "Error not enough privileges to set Scheduling priority\n"); fprintf(stderr, "Error not enough privileges to set Scheduling priority\n");
} }
attr_enable = true;
} else if (prio_offset == -2) {
param.sched_priority = 0;
pthread_attr_init(&attr);
if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED)) {
perror("pthread_attr_setinheritsched");
}
if (pthread_attr_setschedpolicy(&attr, SCHED_OTHER)) {
perror("pthread_attr_setschedpolicy");
}
if (pthread_attr_setschedparam(&attr, &param)) {
perror("pthread_attr_setschedparam");
fprintf(stderr, "Error not enough privileges to set Scheduling priority\n");
}
attr_enable = true;
} }
if(cpu > 0) { if(cpu > 0) {
if(cpu > 50) { if(cpu > 50) {
@ -86,7 +103,7 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void
} }
} }
int err = pthread_create(thread, prio_offset >= 0 ? &attr : NULL, start_routine, arg); int err = pthread_create(thread, attr_enable ? &attr : NULL, start_routine, arg);
if (err) { if (err) {
if (EPERM == err) { if (EPERM == err) {
perror("Warning: Failed to create thread with real-time priority. Creating it with normal priority"); perror("Warning: Failed to create thread with real-time priority. Creating it with normal priority");
@ -102,7 +119,7 @@ bool threads_new_rt_cpu(pthread_t *thread, void *(*start_routine) (void*), void
} else { } else {
ret = true; ret = true;
} }
if (prio_offset >= 0) { if (attr_enable) {
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
} }
return ret; return ret;

Loading…
Cancel
Save