GNU Radio 3.2.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2007,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 along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00020 */ 00021 00022 #ifndef INCLUDED_MB_WORKER_H 00023 #define INCLUDED_MB_WORKER_H 00024 00025 #include <gnuradio/omnithread.h> 00026 #include <mblock/common.h> 00027 #include <mblock/class_registry.h> 00028 00029 00030 class mb_worker; 00031 //typedef boost::shared_ptr<mb_worker> mb_worker_sptr; 00032 00033 class mb_runtime_thread_per_block; 00034 00035 /*! 00036 * \brief Worker thread for thread_per_block runtime 00037 * \internal 00038 */ 00039 class mb_worker : public omni_thread 00040 { 00041 public: 00042 //! worker thread states 00043 enum worker_state_t { 00044 TS_UNINITIALIZED, // new, uninitialized 00045 TS_RUNNING, // normal steady-state condition. 00046 TS_DEAD // thread is dead 00047 }; 00048 00049 //! why we're dead 00050 enum cause_of_death_t { 00051 RIP_NOT_DEAD_YET, // not dead 00052 RIP_EXIT, // normal exit 00053 RIP_TERMINATE, // caught terminate exception 00054 RIP_CTOR_EXCEPTION, // constructor raised an exception 00055 RIP_INIT_EXCEPTION, // initial_transition rasised an exception 00056 RIP_UNHANDLED_EXCEPTION // somebody (most likely handle_message) raised an exception 00057 }; 00058 00059 /* 00060 * Args used by new thread to create mb_mblock 00061 */ 00062 mb_runtime_thread_per_block *d_runtime; 00063 mb_mblock_maker_t d_maker; 00064 std::string d_instance_name; 00065 pmt_t d_user_arg; 00066 00067 mb_mblock_sptr d_mblock; //< holds pointer to created mblock 00068 00069 /*! 00070 * \brief General mutex for all these fields. 00071 * 00072 * They are accessed by both the main runtime thread and the newly 00073 * created thread that runs the mblock's main loop. 00074 */ 00075 omni_mutex d_mutex; 00076 omni_condition d_state_cond; //< state change notifications 00077 worker_state_t d_state; 00078 cause_of_death_t d_why_dead; 00079 00080 mb_worker(mb_runtime_thread_per_block *runtime, 00081 mb_mblock_maker_t maker, 00082 const std::string &instance_name, 00083 pmt_t user_arg); 00084 00085 // ~mb_worker(); 00086 00087 00088 /*! 00089 * \brief This code runs as the top-level of the new thread 00090 */ 00091 void worker_thread_top_level(); 00092 00093 /*! 00094 * \brief Invokes the top-level of the new thread (name kind of sucks) 00095 */ 00096 void *run_undetached(void *arg); 00097 00098 private: 00099 // Neither d_mutex nor runtime->d_mutex may be held while calling this. 00100 // It locks and unlocks them itself. 00101 void set_state(worker_state_t state); 00102 }; 00103 00104 00105 00106 #endif /* INCLUDED_MB_WORKER_H */