summaryrefslogtreecommitdiffstats
path: root/src/pulsecore
diff options
context:
space:
mode:
authorColin Guthrie <cguthrie@mandriva.org>2011-03-24 09:08:05 +0000
committerColin Guthrie <cguthrie@mandriva.org>2011-03-24 09:08:05 +0000
commitae35ec1ed5f76aab6a0a60a27adf1d6b92323e70 (patch)
treedce87fc98f6429a679cec0353be3d94f0455c88e /src/pulsecore
parent11da057d81a1a5d28134d1cc8cc2c6469524561d (diff)
parentfc339a608e0a295312a1887b6cfb78883f7c556c (diff)
Merge remote-tracking branch 'zonique/osx'
Diffstat (limited to 'src/pulsecore')
-rw-r--r--src/pulsecore/core-util.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 3eb12428..796ff57c 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -107,6 +107,10 @@
#ifdef __APPLE__
#include <xlocale.h>
+#include <mach/mach_init.h>
+#include <mach/thread_act.h>
+#include <mach/thread_policy.h>
+#include <sys/sysctl.h>
#endif
#ifdef HAVE_DBUS
@@ -691,7 +695,39 @@ static int set_scheduler(int rtprio) {
* the thread is already realtime, don't do anything. */
int pa_make_realtime(int rtprio) {
-#ifdef _POSIX_PRIORITY_SCHEDULING
+#if defined(OS_IS_DARWIN)
+ struct thread_time_constraint_policy ttcpolicy;
+ uint64_t freq = 0;
+ size_t size = sizeof(freq);
+ int ret;
+
+ ret = sysctlbyname("hw.cpufrequency", &freq, &size, NULL, 0);
+ if (ret < 0) {
+ pa_log_info("Unable to read CPU frequency, acquisition of real-time scheduling failed.");
+ return -1;
+ }
+
+ pa_log_debug("sysctl for hw.cpufrequency: %llu", freq);
+
+ /* See http://developer.apple.com/library/mac/#documentation/Darwin/Conceptual/KernelProgramming/scheduler/scheduler.html */
+ ttcpolicy.period = freq / 160;
+ ttcpolicy.computation = freq / 3300;
+ ttcpolicy.constraint = freq / 2200;
+ ttcpolicy.preemptible = 1;
+
+ ret = thread_policy_set(mach_thread_self(),
+ THREAD_TIME_CONSTRAINT_POLICY,
+ (thread_policy_t) &ttcpolicy,
+ THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+ if (ret) {
+ pa_log_info("Unable to set real-time thread priority (%08x).", ret);
+ return -1;
+ }
+
+ pa_log_info("Successfully acquired real-time thread priority.");
+ return 0;
+
+#elif _POSIX_PRIORITY_SCHEDULING
int p;
if (set_scheduler(rtprio) >= 0) {