GNU Radio 3.5.1 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 <gruel/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 
00035 namespace gruel {
00036 
00037   typedef enum {
00038     RT_OK = 0,
00039     RT_NOT_IMPLEMENTED,
00040     RT_NO_PRIVS,
00041     RT_OTHER_ERROR
00042   } rt_status_t;
00043 
00044 
00045   enum rt_sched_policy {
00046     RT_SCHED_RR   = 0,          // round robin
00047     RT_SCHED_FIFO = 1,          // first in first out
00048   };
00049 
00050   /*
00051    * Define the range for our virtual priorities (don't change 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 GRUEL_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 any
00084    * non-realtime (normal) processes.  Note that if your code contains
00085    * an non-blocking infinite loop and you enable realtime scheduling,
00086    * it's possible to hang the system.
00087    */
00088 
00089   // NOTE: If you change this, you need to change the code in 
00090   // gnuradio-core/src/lib/runtime/gr_realtime.i, see note there.
00091   rt_status_t
00092   GRUEL_API enable_realtime_scheduling(rt_sched_param = rt_sched_param());
00093 
00094 } // namespace gruel
00095 
00096 #endif /* INCLUDED_GRUEL_REALTIME_H */