$NetBSD$

--- libxmms/util.c.orig	2003-05-19 14:22:07.000000000 -0700
+++ libxmms/util.c
@@ -15,6 +15,13 @@
 #include <sys/sysctl.h>
 #endif
 
+#if defined(__APPLE__) && defined(__MACH__)
+#include <mach/mach.h>
+#include <mach/thread_policy.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
 #if TIME_WITH_SYS_TIME
 # include <sys/time.h>
 # include <time.h>
@@ -73,6 +80,28 @@ GtkWidget *xmms_show_message(gchar * tit
 
 gboolean xmms_check_realtime_priority(void)
 {
+#if defined(__APPLE__) && defined(__MACH__)
+	struct thread_time_constraint_policy ttcpolicy;
+	int bus_speed, mib [2] = { CTL_HW, HW_BUS_FREQ };
+	size_t len;
+
+	len = sizeof (bus_speed);
+	sysctl (mib, 2, &bus_speed, &len, NULL, 0);
+
+	/* Is it enough? */
+	ttcpolicy.period = bus_speed / 120;
+	ttcpolicy.computation = bus_speed / 1000;
+	ttcpolicy.constraint = bus_speed / 500;
+	ttcpolicy.preemptible = 1;
+
+	thread_policy_set (mach_thread_self (),
+			   THREAD_TIME_CONSTRAINT_POLICY,
+			   (int*)&ttcpolicy,
+			   THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+
+	return TRUE;
+#endif
+
 #ifdef HAVE_SCHED_SETSCHEDULER
 #ifdef __FreeBSD__
 	/*
