GNU Radio 3.7.0 C++ API
realtime_impl.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2008,2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_GNURADIO_REALTIME_H
00024 #define INCLUDED_GNURADIO_REALTIME_H
00025 
00026 #include <gnuradio/api.h>
00027 #include <stdexcept>
00028 
00029 /*!
00030  * \brief System independent way to ask for realtime scheduling
00031  *
00032  * \sa sys_pri.h
00033  */
00034 namespace gr {
00035 
00036   typedef enum {
00037     RT_OK = 0,
00038     RT_NOT_IMPLEMENTED,
00039     RT_NO_PRIVS,
00040     RT_OTHER_ERROR
00041   } rt_status_t;
00042 
00043   enum rt_sched_policy {
00044     RT_SCHED_RR   = 0,          // round robin
00045     RT_SCHED_FIFO = 1,          // first in first out
00046   };
00047 
00048   namespace impl {
00049     /*
00050      * Define the range for our virtual priorities (don't change
00051      * these)
00052      *
00053      * Processes (or threads) with numerically higher priority values
00054      * are scheduled before processes with numerically lower priority
00055      * values. Thus, the value returned by rt_priority_max() will be
00056      * greater than the value returned by rt_priority_min().
00057      */
00058     static inline int rt_priority_min() { return  0; }
00059     static inline int rt_priority_max() { return 15; }
00060     static inline int rt_priority_default() { return 1; }
00061 
00062     struct GR_RUNTIME_API rt_sched_param {
00063       int priority;
00064       rt_sched_policy policy;
00065 
00066       rt_sched_param()
00067         : priority(rt_priority_default()), policy(RT_SCHED_RR){}
00068 
00069       rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
00070       {
00071         if(priority_ < rt_priority_min() || priority_ > rt_priority_max())
00072           throw std::invalid_argument("rt_sched_param: priority out of range");
00073 
00074         priority = priority_;
00075         policy = policy_;
00076       }
00077     };
00078 
00079     /*!
00080      * \brief If possible, enable "realtime" scheduling.
00081      * \ingroup misc
00082      *
00083      * In general, this means that the code will be scheduled before
00084      * any non-realtime (normal) processes.  Note that if your code
00085      * contains an non-blocking infinite loop and you enable realtime
00086      * scheduling, it's possible to hang the system.
00087      */
00088 
00089     // NOTE: If you change this, you need to change the code in
00090     // gnuradio-runtime/swig/realtime.i, see note there.
00091     GR_RUNTIME_API rt_status_t enable_realtime_scheduling(rt_sched_param = rt_sched_param());
00092 
00093   } /* namespace impl */
00094 } /* namespace gr */
00095 
00096 #endif /* INCLUDED_GNURADIO_REALTIME_H */