summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri <yuri@tsoft.com>2017-01-09 11:38:55 -0800
committerYuri <yuri@tsoft.com>2017-01-09 11:38:55 -0800
commit02029576c4eb23c99e780df2b3499b01edf7de5e (patch)
tree5998ad1dcf808348d1d42395aaf31925516ac04d
parent0dc6f4a0aba1c5efe6020bfd107023f3a153252b (diff)
downloadjack1-02029576c4eb23c99e780df2b3499b01edf7de5e.tar.gz
Using the process realtime priority instead of the thread realtime priority when sufficient.
-rw-r--r--libjack/thread.c37
1 files changed, 35 insertions, 2 deletions
diff --git a/libjack/thread.c b/libjack/thread.c
index d17e7d8..4727c07 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,45 @@ 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 +320,9 @@ 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;