Imported Upstream version 3.2.2
[debian/gnuradio] / gruel / src / include / gruel / realtime.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 #ifndef INCLUDED_GRUEL_REALTIME_H
24 #define INCLUDED_GRUEL_REALTIME_H
25
26 #include <stdexcept>
27
28 /*!
29  * \brief System independent way to ask for realtime scheduling
30  *
31  * \sa sys_pri.h
32  */
33
34 namespace gruel {
35
36   typedef enum {
37     RT_OK = 0,
38     RT_NOT_IMPLEMENTED,
39     RT_NO_PRIVS,
40     RT_OTHER_ERROR
41   } rt_status_t;
42
43
44   enum rt_sched_policy {
45     RT_SCHED_RR   = 0,          // round robin
46     RT_SCHED_FIFO = 1,          // first in first out
47   };
48
49   /*
50    * Define the range for our virtual priorities (don't change these)
51    *
52    * Processes (or threads) with numerically higher priority values
53    * are scheduled before processes with numerically lower priority
54    * values.  Thus, the value returned by rt_priority_max() will be
55    * greater than the value returned by rt_priority_min().
56    */
57   static inline int rt_priority_min() { return  0; }
58   static inline int rt_priority_max() { return 15; }
59   static inline int rt_priority_default() { return 1; }
60
61   struct rt_sched_param {
62     int                 priority;
63     rt_sched_policy     policy;
64
65     rt_sched_param()
66       : priority(rt_priority_default()), policy(RT_SCHED_RR){}
67
68     rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
69     {
70       if (priority_ < rt_priority_min() || priority_ > rt_priority_max())
71         throw std::invalid_argument("rt_sched_param: priority out of range");
72
73       priority = priority_;
74       policy = policy_;
75     }
76   };
77
78   /*!
79    * \brief If possible, enable "realtime" scheduling.
80    * \ingroup misc
81    *
82    * In general, this means that the code will be scheduled before any
83    * non-realtime (normal) processes.  Note that if your code contains
84    * an non-blocking infinite loop and you enable realtime scheduling,
85    * it's possible to hang the system.
86    */
87
88   // NOTE: If you change this, you need to change the code in 
89   // gnuradio-core/src/lib/runtime/gr_realtime.i, see note there.
90   rt_status_t
91   enable_realtime_scheduling(rt_sched_param = rt_sched_param());
92
93 } // namespace gruel
94
95 #endif /* INCLUDED_GRUEL_REALTIME_H */