Made changes, such that:
[debian/gnuradio] / gnuradio-core / src / lib / runtime / gr_realtime.cc
index 878411df296bb1291dcc3baf8f8a242c5af5df5f..35d0ef38103154af50dab970d9a63797adb23d18 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2007 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
@@ -58,6 +58,33 @@ gr_enable_realtime_scheduling()
   return RT_OK;
 }
 
+#elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
+
+#include <pthread.h>
+
+gr_rt_status_t
+gr_enable_realtime_scheduling()
+{
+  int policy = SCHED_FIFO;
+  int pri = (sched_get_priority_max (policy) +
+            sched_get_priority_min (policy)) / 2;
+  pthread_t this_thread = pthread_self ();  // this process
+  struct sched_param param;
+  memset (&param, 0, sizeof (param));
+  param.sched_priority = pri;
+  int result = pthread_setschedparam (this_thread, policy, &param);
+  if (result != 0) {
+    if (errno == EPERM)
+      return RT_NO_PRIVS;
+    else {
+      perror ("pthread_setschedparam: failed to set real time priority");
+      return RT_OTHER_ERROR;
+    }
+  }
+  //printf("SCHED_FIFO enabled with priority = %d\n", pri);
+  return RT_OK;
+}
+
 // #elif // could try negative niceness
 
 #else