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