3 * Copyright 2008 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.
24 #include <gr_sptr_magic.h>
25 #include <gr_hier_block2.h>
31 #include <boost/thread.hpp>
32 typedef boost::mutex mutex;
33 typedef boost::mutex::scoped_lock scoped_lock;
35 #include <gnuradio/omnithread.h>
36 typedef omni_mutex mutex;
37 typedef omni_mutex_lock scoped_lock;
43 typedef std::map<gr_basic_block*, gr_basic_block_sptr> sptr_map;
44 static sptr_map s_map;
47 detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p)
49 gr_basic_block_sptr sptr(p);
51 s_map.insert(sptr_map::value_type(static_cast<gr_basic_block *>(p), sptr));
56 detail::sptr_magic::fetch_initial_sptr(gr_basic_block *p)
59 * If p isn't a subclass of gr_hier_block2, just create the
60 * shared ptr and return it.
62 gr_hier_block2 *hb2 = dynamic_cast<gr_hier_block2 *>(p);
64 return gr_basic_block_sptr(p);
68 * p is a subclass of gr_hier_block2, thus we've already created the shared pointer
69 * and stashed it away. Fish it out and return it.
72 sptr_map::iterator pos = s_map.find(static_cast<gr_basic_block *>(p));
73 if (pos == s_map.end())
74 throw std::invalid_argument("gr_sptr_magic: invalid pointer!");
76 gr_basic_block_sptr sptr = pos->second;