GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
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 namespace gr {
33 
35 
37  RT_SCHED_RR = 0, // round robin
38  RT_SCHED_FIFO = 1, // first in first out
39 };
40 
41 namespace impl {
42 /*
43  * Define the range for our virtual priorities (don't change
44  * these)
45  *
46  * Processes (or threads) with numerically higher priority values
47  * are scheduled before processes with numerically lower priority
48  * values. Thus, the value returned by rt_priority_max() will be
49  * greater than the value returned by rt_priority_min().
50  */
51 static inline int rt_priority_min() { return 0; }
52 static inline int rt_priority_max() { return 15; }
53 static inline int rt_priority_default() { return 1; }
54 
56  int priority;
58 
59  rt_sched_param() : priority(rt_priority_default()), policy(RT_SCHED_RR) {}
60 
61  rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
62  {
63  if (priority_ < rt_priority_min() || priority_ > rt_priority_max())
64  throw std::invalid_argument("rt_sched_param: priority out of range");
65 
66  priority = priority_;
67  policy = policy_;
68  }
69 };
70 
71 /*!
72  * \brief If possible, enable "realtime" scheduling.
73  * \ingroup misc
74  *
75  * In general, this means that the code will be scheduled before
76  * any non-realtime (normal) processes. Note that if your code
77  * contains an non-blocking infinite loop and you enable realtime
78  * scheduling, it's possible to hang the system.
79  */
80 
81 // NOTE: If you change this, you need to change the code in
82 // gnuradio-runtime/swig/realtime.i, see note there.
84 
85 } /* namespace impl */
86 } /* namespace gr */
87 
88 #endif /* INCLUDED_GNURADIO_REALTIME_H */
rt_sched_policy
Definition: realtime_impl.h:36
Definition: realtime_impl.h:34
int priority
Definition: realtime_impl.h:56
Definition: realtime_impl.h:38
Definition: realtime_impl.h:34
Definition: realtime_impl.h:55
static int rt_priority_default()
Definition: realtime_impl.h:53
Definition: realtime_impl.h:34
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:30
static int rt_priority_max()
Definition: realtime_impl.h:52
rt_sched_policy policy
Definition: realtime_impl.h:57
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
rt_sched_param(int priority_, rt_sched_policy policy_=RT_SCHED_RR)
Definition: realtime_impl.h:61
Definition: realtime_impl.h:37
static int rt_priority_min()
Definition: realtime_impl.h:51
rt_status_t
Definition: realtime_impl.h:34
Definition: realtime_impl.h:34
rt_sched_param()
Definition: realtime_impl.h:59
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 befo...