GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
realtime_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006,2008,2013 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_GNURADIO_REALTIME_H
24 #define INCLUDED_GNURADIO_REALTIME_H
25 
26 #include <gnuradio/api.h>
27 #include <stdexcept>
28 
29 /*!
30  * \brief System independent way to ask for realtime scheduling
31  *
32  * \sa sys_pri.h
33  */
34 namespace gr {
35 
36  typedef enum {
37  RT_OK = 0,
41  } rt_status_t;
42 
44  RT_SCHED_RR = 0, // round robin
45  RT_SCHED_FIFO = 1, // first in first out
46  };
47 
48  namespace impl {
49  /*
50  * Define the range for our virtual priorities (don't change
51  * these)
52  *
53  * Processes (or threads) with numerically higher priority values
54  * are scheduled before processes with numerically lower priority
55  * values. Thus, the value returned by rt_priority_max() will be
56  * greater than the value returned by rt_priority_min().
57  */
58  static inline int rt_priority_min() { return 0; }
59  static inline int rt_priority_max() { return 15; }
60  static inline int rt_priority_default() { return 1; }
61 
63  int priority;
65 
67  : priority(rt_priority_default()), policy(RT_SCHED_RR){}
68 
69  rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
70  {
71  if(priority_ < rt_priority_min() || priority_ > rt_priority_max())
72  throw std::invalid_argument("rt_sched_param: priority out of range");
73 
74  priority = priority_;
75  policy = policy_;
76  }
77  };
78 
79  /*!
80  * \brief If possible, enable "realtime" scheduling.
81  * \ingroup misc
82  *
83  * In general, this means that the code will be scheduled before
84  * any non-realtime (normal) processes. Note that if your code
85  * contains an non-blocking infinite loop and you enable realtime
86  * scheduling, it's possible to hang the system.
87  */
88 
89  // NOTE: If you change this, you need to change the code in
90  // gnuradio-runtime/swig/realtime.i, see note there.
91  GR_RUNTIME_API rt_status_t enable_realtime_scheduling(rt_sched_param = rt_sched_param());
92 
93  } /* namespace impl */
94 } /* namespace gr */
95 
96 #endif /* INCLUDED_GNURADIO_REALTIME_H */
rt_sched_policy
Definition: realtime_impl.h:43
Definition: realtime_impl.h:39
int priority
Definition: realtime_impl.h:63
Definition: realtime_impl.h:45
Definition: realtime_impl.h:37
Definition: realtime_impl.h:62
static int rt_priority_default()
Definition: realtime_impl.h:60
Definition: realtime_impl.h:40
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
static int rt_priority_max()
Definition: realtime_impl.h:59
rt_sched_policy policy
Definition: realtime_impl.h:64
rt_sched_param(int priority_, rt_sched_policy policy_=RT_SCHED_RR)
Definition: realtime_impl.h:69
Definition: realtime_impl.h:44
static int rt_priority_min()
Definition: realtime_impl.h:58
rt_status_t
Definition: realtime_impl.h:36
Definition: realtime_impl.h:38
rt_sched_param()
Definition: realtime_impl.h:66
GR_RUNTIME_API rt_status_t enable_realtime_scheduling(rt_sched_param=rt_sched_param())
If possible, enable "realtime" scheduling.In general, this means that the code will be scheduled be...