gr_realtime now uses gruel::enable_realtime_scheduling
authoreb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 20 Sep 2008 00:16:41 +0000 (00:16 +0000)
committereb <eb@221aa14e-8319-0410-a670-987f0aec2ac5>
Sat, 20 Sep 2008 00:16:41 +0000 (00:16 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@9610 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/runtime/gr_realtime.cc
gnuradio-core/src/lib/runtime/gr_realtime.h

index d3cda0eaa50af15db5b0c8b31b54d5131ca77fb7..b44c4d408cd280c0c4b8a43f7b70b7e60ad53a5a 100644 (file)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2006,2007 Free Software Foundation, Inc.
+ * Copyright 2006,2007,2008 Free Software Foundation, Inc.
  * 
  * This file is part of GNU Radio
  * 
 #endif
 #include <gr_realtime.h>
 
-#ifdef HAVE_SCHED_H
-#include <sched.h>
-#endif
-
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-
-#if defined(HAVE_SCHED_SETSCHEDULER)
-
 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;
-  int pid = 0;  // this process
-
-  struct sched_param param;
-  memset(&param, 0, sizeof(param));
-  param.sched_priority = pri;
-  int result = sched_setscheduler(pid, policy, &param);
-  if (result != 0){
-    if (errno == EPERM)
-      return RT_NO_PRIVS;
-    else {
-      perror ("sched_setscheduler: failed to set real time priority");
-      return RT_OTHER_ERROR;
-    }
-  }
-  //printf("SCHED_FIFO enabled with priority = %d\n", pri);
-  return RT_OK;
+  return gruel::enable_realtime_scheduling();
 }
-
-#elif defined(HAVE_PTHREAD_SETSCHEDPARAM)
-
-#include <pthread.h>
-#include <stdio.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
-
-gr_rt_status_t
-gr_enable_realtime_scheduling()
-{
-  return RT_NOT_IMPLEMENTED;
-}
-
-#endif
index cf0423aaa7026725e72d08911f701090ff158dce..830c201d76f1a8f6827dc6459d54e50036f65fb2 100644 (file)
 #ifndef INCLUDED_GR_REALTIME_H
 #define INCLUDED_GR_REALTIME_H
 
-typedef enum {
-  RT_OK = 0,
-  RT_NOT_IMPLEMENTED,
-  RT_NO_PRIVS,
-  RT_OTHER_ERROR
-} gr_rt_status_t;
+#include <gruel/realtime.h>
+
+typedef gruel::rt_status_t gr_rt_status_t;
 
 /*!
  * \brief If possible, enable high-priority "real time" scheduling.
  * \ingroup misc
  */
-gr_rt_status_t
-gr_enable_realtime_scheduling();
+gr_rt_status_t gr_enable_realtime_scheduling();
 
 #endif /* INCLUDED_GR_REALTIME_H */