3 * Copyright 2007,2008,2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef INCLUDED_MB_WORKER_H
23 #define INCLUDED_MB_WORKER_H
25 #include <gnuradio/omnithread.h>
26 #include <mblock/common.h>
27 #include <mblock/class_registry.h>
31 //typedef boost::shared_ptr<mb_worker> mb_worker_sptr;
33 class mb_runtime_thread_per_block;
36 * \brief Worker thread for thread_per_block runtime
39 class mb_worker : public omni_thread
42 //! worker thread states
44 TS_UNINITIALIZED, // new, uninitialized
45 TS_RUNNING, // normal steady-state condition.
46 TS_DEAD // thread is dead
50 enum cause_of_death_t {
51 RIP_NOT_DEAD_YET, // not dead
52 RIP_EXIT, // normal exit
53 RIP_TERMINATE, // caught terminate exception
54 RIP_CTOR_EXCEPTION, // constructor raised an exception
55 RIP_INIT_EXCEPTION, // initial_transition rasised an exception
56 RIP_UNHANDLED_EXCEPTION // somebody (most likely handle_message) raised an exception
60 * Args used by new thread to create mb_mblock
62 mb_runtime_thread_per_block *d_runtime;
63 mb_mblock_maker_t d_maker;
64 std::string d_instance_name;
65 gruel::pmt_t d_user_arg;
67 mb_mblock_sptr d_mblock; //< holds pointer to created mblock
70 * \brief General mutex for all these fields.
72 * They are accessed by both the main runtime thread and the newly
73 * created thread that runs the mblock's main loop.
76 omni_condition d_state_cond; //< state change notifications
77 worker_state_t d_state;
78 cause_of_death_t d_why_dead;
80 mb_worker(mb_runtime_thread_per_block *runtime,
81 mb_mblock_maker_t maker,
82 const std::string &instance_name,
83 gruel::pmt_t user_arg);
89 * \brief This code runs as the top-level of the new thread
91 void worker_thread_top_level();
94 * \brief Invokes the top-level of the new thread (name kind of sucks)
96 void *run_undetached(void *arg);
99 // Neither d_mutex nor runtime->d_mutex may be held while calling this.
100 // It locks and unlocks them itself.
101 void set_state(worker_state_t state);
106 #endif /* INCLUDED_MB_WORKER_H */