summaryrefslogtreecommitdiff
path: root/mblock/src/lib/mb_worker.h
diff options
context:
space:
mode:
authoreb2007-05-02 04:08:47 +0000
committereb2007-05-02 04:08:47 +0000
commit0bf2128a621ae84099f43744e1b81800f2b9d2d7 (patch)
tree1345b44ae9060e99ff236f983dd272c6d35a012e /mblock/src/lib/mb_worker.h
parent28259329a829f157fd877a1c14139eaf0117dabd (diff)
downloadgnuradio-0bf2128a621ae84099f43744e1b81800f2b9d2d7.tar.gz
gnuradio-0bf2128a621ae84099f43744e1b81800f2b9d2d7.tar.bz2
gnuradio-0bf2128a621ae84099f43744e1b81800f2b9d2d7.zip
Merged features/inband -r4812:5218 into trunk. This group of changes
includes: * working stand-alone mblock code * work-in-progress on usrp inband signaling usrp now depends on mblock, and guile is a dependency. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@5221 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'mblock/src/lib/mb_worker.h')
-rw-r--r--mblock/src/lib/mb_worker.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/mblock/src/lib/mb_worker.h b/mblock/src/lib/mb_worker.h
new file mode 100644
index 000000000..b207f4db5
--- /dev/null
+++ b/mblock/src/lib/mb_worker.h
@@ -0,0 +1,106 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef INCLUDED_MB_WORKER_H
+#define INCLUDED_MB_WORKER_H
+
+#include <omnithread.h>
+#include <mb_common.h>
+#include <mb_class_registry.h>
+
+
+class mb_worker;
+//typedef boost::shared_ptr<mb_worker> mb_worker_sptr;
+
+class mb_runtime_thread_per_block;
+
+/*!
+ * \brief Worker thread for thread_per_block runtime
+ * \implementation
+ */
+class mb_worker : public omni_thread
+{
+public:
+ //! worker thread states
+ enum worker_state_t {
+ TS_UNINITIALIZED, // new, uninitialized
+ TS_RUNNING, // normal steady-state condition.
+ TS_DEAD // thread is dead
+ };
+
+ //! why we're dead
+ enum cause_of_death_t {
+ RIP_NOT_DEAD_YET, // not dead
+ RIP_EXIT, // normal exit
+ RIP_TERMINATE, // caught terminate exception
+ RIP_CTOR_EXCEPTION, // constructor raised an exception
+ RIP_INIT_EXCEPTION, // initial_transition rasised an exception
+ RIP_UNHANDLED_EXCEPTION // somebody (most likely handle_message) raised an exception
+ };
+
+ /*
+ * Args used by new thread to create mb_mblock
+ */
+ mb_runtime_thread_per_block *d_runtime;
+ mb_mblock_maker_t d_maker;
+ std::string d_instance_name;
+ pmt_t d_user_arg;
+
+ mb_mblock_sptr d_mblock; //< holds pointer to created mblock
+
+ /*!
+ * \brief General mutex for all these fields.
+ *
+ * They are accessed by both the main runtime thread and the newly
+ * created thread that runs the mblock's main loop.
+ */
+ omni_mutex d_mutex;
+ omni_condition d_state_cond; //< state change notifications
+ worker_state_t d_state;
+ cause_of_death_t d_why_dead;
+
+ mb_worker(mb_runtime_thread_per_block *runtime,
+ mb_mblock_maker_t maker,
+ const std::string &instance_name,
+ pmt_t user_arg);
+
+ // ~mb_worker();
+
+
+ /*!
+ * \brief This code runs as the top-level of the new thread
+ */
+ void worker_thread_top_level();
+
+ /*!
+ * \brief Invokes the top-level of the new thread (name kind of sucks)
+ */
+ void *run_undetached(void *arg);
+
+private:
+ // Neither d_mutex nor runtime->d_mutex may be held while calling this.
+ // It locks and unlocks them itself.
+ void set_state(worker_state_t state);
+};
+
+
+
+#endif /* INCLUDED_MB_WORKER_H */