GNU Radio Manual and C++ API Reference  3.9.0.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  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GNURADIO_REALTIME_H
12 #define INCLUDED_GNURADIO_REALTIME_H
13 
14 #include <gnuradio/api.h>
15 #include <stdexcept>
16 
17 /*!
18  * \brief System independent way to ask for realtime scheduling
19  */
20 namespace gr {
21 
23 
25  RT_SCHED_RR = 0, // round robin
26  RT_SCHED_FIFO = 1, // first in first out
27 };
28 
29 namespace impl {
30 /*
31  * Define the range for our virtual priorities (don't change
32  * these)
33  *
34  * Processes (or threads) with numerically higher priority values
35  * are scheduled before processes with numerically lower priority
36  * values. Thus, the value returned by rt_priority_max() will be
37  * greater than the value returned by rt_priority_min().
38  */
39 static inline int rt_priority_min() { return 0; }
40 static inline int rt_priority_max() { return 15; }
41 static inline int rt_priority_default() { return 1; }
42 
44  int priority;
46 
47  rt_sched_param() : priority(rt_priority_default()), policy(RT_SCHED_RR) {}
48 
49  rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
50  {
51  if (priority_ < rt_priority_min() || priority_ > rt_priority_max())
52  throw std::invalid_argument("rt_sched_param: priority out of range");
53 
54  priority = priority_;
55  policy = policy_;
56  }
57 };
58 
59 /*!
60  * \brief If possible, enable "realtime" scheduling.
61  * \ingroup misc
62  *
63  * In general, this means that the code will be scheduled before
64  * any non-realtime (normal) processes. Note that if your code
65  * contains an non-blocking infinite loop and you enable realtime
66  * scheduling, it's possible to hang the system.
67  */
68 
70 
71 } /* namespace impl */
72 } /* namespace gr */
73 
74 #endif /* INCLUDED_GNURADIO_REALTIME_H */
#define GR_RUNTIME_API
Definition: gnuradio-runtime/include/gnuradio/api.h:18
GR_RUNTIME_API rt_status_t enable_realtime_scheduling(rt_sched_param=rt_sched_param())
If possible, enable "realtime" scheduling.
static int rt_priority_default()
Definition: realtime_impl.h:41
static int rt_priority_max()
Definition: realtime_impl.h:40
static int rt_priority_min()
Definition: realtime_impl.h:39
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
rt_status_t
Definition: realtime_impl.h:22
@ RT_OK
Definition: realtime_impl.h:22
@ RT_OTHER_ERROR
Definition: realtime_impl.h:22
@ RT_NO_PRIVS
Definition: realtime_impl.h:22
@ RT_NOT_IMPLEMENTED
Definition: realtime_impl.h:22
rt_sched_policy
Definition: realtime_impl.h:24
@ RT_SCHED_FIFO
Definition: realtime_impl.h:26
@ RT_SCHED_RR
Definition: realtime_impl.h:25
Definition: realtime_impl.h:43
rt_sched_policy policy
Definition: realtime_impl.h:45
rt_sched_param()
Definition: realtime_impl.h:47
int priority
Definition: realtime_impl.h:44
rt_sched_param(int priority_, rt_sched_policy policy_=RT_SCHED_RR)
Definition: realtime_impl.h:49