GNU Radio 3.4.2 C++ API
realtime.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2006,2008 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_GRUEL_REALTIME_H
00024 #define INCLUDED_GRUEL_REALTIME_H
00025 
00026 #include <stdexcept>
00027 
00028 /*!
00029  * \brief System independent way to ask for realtime scheduling
00030  *
00031  * \sa sys_pri.h
00032  */
00033 
00034 namespace gruel {
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 
00044   enum rt_sched_policy {
00045     RT_SCHED_RR   = 0,          // round robin
00046     RT_SCHED_FIFO = 1,          // first in first out
00047   };
00048 
00049   /*
00050    * Define the range for our virtual priorities (don't change these)
00051    *
00052    * Processes (or threads) with numerically higher priority values
00053    * are scheduled before processes with numerically lower priority
00054    * values.  Thus, the value returned by rt_priority_max() will be
00055    * greater than the value returned by rt_priority_min().
00056    */
00057   static inline int rt_priority_min() { return  0; }
00058   static inline int rt_priority_max() { return 15; }
00059   static inline int rt_priority_default() { return 1; }
00060 
00061   struct rt_sched_param {
00062     int                 priority;
00063     rt_sched_policy     policy;
00064 
00065     rt_sched_param()
00066       : priority(rt_priority_default()), policy(RT_SCHED_RR){}
00067 
00068     rt_sched_param(int priority_, rt_sched_policy policy_ = RT_SCHED_RR)
00069     {
00070       if (priority_ < rt_priority_min() || priority_ > rt_priority_max())
00071         throw std::invalid_argument("rt_sched_param: priority out of range");
00072 
00073       priority = priority_;
00074       policy = policy_;
00075     }
00076   };
00077 
00078   /*!
00079    * \brief If possible, enable "realtime" scheduling.
00080    * \ingroup misc
00081    *
00082    * In general, this means that the code will be scheduled before any
00083    * non-realtime (normal) processes.  Note that if your code contains
00084    * an non-blocking infinite loop and you enable realtime scheduling,
00085    * it's possible to hang the system.
00086    */
00087 
00088   // NOTE: If you change this, you need to change the code in 
00089   // gnuradio-core/src/lib/runtime/gr_realtime.i, see note there.
00090   rt_status_t
00091   enable_realtime_scheduling(rt_sched_param = rt_sched_param());
00092 
00093 } // namespace gruel
00094 
00095 #endif /* INCLUDED_GRUEL_REALTIME_H */