/* -*- c++ -*- */
/*
- * Copyright 2006 Free Software Foundation, Inc.
+ * Copyright 2006,2008 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
* Boston, MA 02110-1301, USA.
*/
-#ifndef INCLUDED_REALTIME_H
-#define INCLUDED_REALTIME_H
+#ifndef INCLUDED_GRUEL_REALTIME_H
+#define INCLUDED_GRUEL_REALTIME_H
+
+#include <stdexcept>
+
+/*!
+ * \brief System independent way to ask for realtime scheduling
+ *
+ * \sa sys_pri.h
+ */
namespace gruel {
RT_OTHER_ERROR
} rt_status_t;
+
+ enum rt_sched_policy {
+ RT_SCHED_RR = 0, // round robin
+ RT_SCHED_FIFO = 1, // first in first out
+ };
+
+ /*
+ * Define the range for our virtual priorities (don't change these)
+ *
+ * Processes (or threads) with numerically higher priority values
+ * are scheduled before processes with numerically lower priority
+ * values. Thus, the value returned by rt_priority_max() will be
+ * greater than the value returned by rt_priority_min().
+ */
+ static inline int rt_priority_min() { return 0; }
+ static inline int rt_priority_max() { return 15; }
+ static inline int rt_priority_default() { return 1; }
+
+ struct rt_sched_param {
+ int priority;
+ rt_sched_policy policy;
+
+ rt_sched_param()
+ : priority(rt_priority_default()), policy(RT_SCHED_RR){}
+
+ rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
+ {
+ if (priority_ < rt_priority_min() || priority_ > rt_priority_max())
+ throw std::invalid_argument("rt_sched_param: priority out of range");
+
+ priority = priority_;
+ policy = policy_;
+ }
+ };
+
/*!
- * \brief If possible, enable high-priority "real time" scheduling.
+ * \brief If possible, enable "realtime" scheduling.
* \ingroup misc
+ *
+ * In general, this means that the code will be scheduled before any
+ * non-realtime (normal) processes. Note that if your code contains
+ * an non-blocking infinite loop and you enable realtime scheduling,
+ * it's possible to hang the system.
*/
rt_status_t
- enable_realtime_scheduling();
+ enable_realtime_scheduling(rt_sched_param = rt_sched_param());
} // namespace gruel
-#endif /* INCLUDED_GR_REALTIME_H */
+#endif /* INCLUDED_GRUEL_REALTIME_H */