--- soundserver/artsd.cc	10 Jul 2002 02:52:33 -0000	1.1.1.2
+++ soundserver/artsd.cc	20 Oct 2002 19:11:01 -0000	1.4
@@ -35,6 +35,13 @@
 #include "debug.h"
 #include "artsversion.h"
 
+#ifdef HAVE_MACH_REALTIME_SCHED
+  #include <mach/mach.h>
+  #include <mach/thread_policy.h>
+  #include <sys/param.h>
+  #include <sys/sysctl.h>
+#endif
+
 using namespace std;
 using namespace Arts;
 
@@ -232,6 +239,29 @@
 	cerr << endl;
 }
 
+#ifdef HAVE_MACH_REALTIME_SCHED
+static void mach_get_realtime_priority()
+{
+	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 / 2400;
+	ttcpolicy.constraint = bus_speed / 1200;
+	ttcpolicy.preemptible = 1;
+
+	thread_policy_set (mach_thread_self (),
+			   THREAD_TIME_CONSTRAINT_POLICY,
+			   (int*)&ttcpolicy,
+			   THREAD_TIME_CONSTRAINT_POLICY_COUNT);
+}
+#endif
+
 int main(int argc, char **argv)
 {
 	handleArgs(argc, argv);
@@ -244,7 +274,9 @@
 
 	if(cfgPort)			 TCPServer::setPort(cfgPort);
 
+#ifndef ARTS_NO_ALARM
 	CPUUsage	cpuUsage;
+#endif
 	Dispatcher	dispatcher(0,cfgServers);
 
 	initSignals();
@@ -298,6 +330,10 @@
 		cleanUnusedReferences();
 		if(!publishReferences(server,audioManager,false)) return 1;
 	}
+
+#ifdef HAVE_MACH_REALTIME_SCHED
+	mach_get_realtime_priority();
+#endif
 
 	/* warn if there was a problem with artswrapper */
 	char *wrapper = getenv("STARTED_THROUGH_ARTSWRAPPER");
