diff options
author | Adrian Knoth <adi@drcomp.erfurt.thur.de> | 2017-01-10 11:13:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-10 11:13:51 +0100 |
commit | 00ead84a3b95bd013f76befb01b8a4b2ea22ad43 (patch) | |
tree | 550664b2ddb5102c7cc4ddf0474206935270f8f5 | |
parent | d355c7d28cc8ad424f6bf4bda2c85b13d5968e73 (diff) | |
parent | 51d8d22a9be16060ccf6a81a4e1544a7e4b196df (diff) | |
download | jack1-00ead84a3b95bd013f76befb01b8a4b2ea22ad43.tar.gz |
Merge pull request #60 from yurivict/use-process-realtime-priority
Using the process realtime priority instead of the thread realtime priority when sufficient.
-rw-r--r-- | libjack/thread.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/libjack/thread.c b/libjack/thread.c index d17e7d8..a7466cc 100644 --- a/libjack/thread.c +++ b/libjack/thread.c @@ -33,6 +33,11 @@ #include <stdio.h> #include <string.h> #include <errno.h> +#if defined(__FreeBSD__) +#include <sys/types.h> +#include <sys/rtprio.h> +#include <unistd.h> +#endif #include "local.h" @@ -267,20 +272,46 @@ jack_acquire_real_time_scheduling (pthread_t thread, int priority) #else /* !JACK_USE_MACH_THREADS */ +static int +jack_process_already_has_real_time_scheduling (int priority) +{ +#if defined(__FreeBSD__) + int res; + struct rtprio rtp; + res = rtprio(RTP_LOOKUP, getpid(), &rtp); + if (res == 0 && rtp.type == RTP_PRIO_REALTIME && rtp.prio <= priority) { + jack_info("process already runs at sufficient realtime priority %u (<=%d)", + (unsigned)rtp.prio, + priority); + return 1; // process priority is sufficient + } +#endif + return 0; // no or don't know +} + int jack_drop_real_time_scheduling (pthread_t thread) { struct sched_param rtparam; - int x; + int x, policy; + + if ((x = pthread_getschedparam (thread, &policy, &rtparam)) != 0) { + jack_error ("cannot read thread scheduling priority(%s)\n", + strerror (errno)); + return -1; + } + if (policy == SCHED_OTHER) { + return 0; // already + } memset (&rtparam, 0, sizeof(rtparam)); - rtparam.sched_priority = 0; if ((x = pthread_setschedparam (thread, SCHED_OTHER, &rtparam)) != 0) { jack_error ("cannot switch to normal scheduling priority(%s)\n", strerror (errno)); return -1; } + return 0; } @@ -290,6 +321,10 @@ jack_acquire_real_time_scheduling (pthread_t thread, int priority) struct sched_param rtparam; int x; + if (jack_process_already_has_real_time_scheduling (priority) != 0) { + return 0; + } + memset (&rtparam, 0, sizeof(rtparam)); rtparam.sched_priority = priority; |