3 * Copyright 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.
24 #include <gr_sptr_magic.h>
25 #include <gr_hier_block2.h>
30 #include <gruel/thread.h>
34 static gruel::mutex s_mutex;
35 typedef std::map<gr_basic_block*, gr_basic_block_sptr> sptr_map;
36 static sptr_map s_map;
39 detail::sptr_magic::create_and_stash_initial_sptr(gr_hier_block2 *p)
41 gr_basic_block_sptr sptr(p);
42 gruel::scoped_lock guard(s_mutex);
43 s_map.insert(sptr_map::value_type(static_cast<gr_basic_block *>(p), sptr));
48 detail::sptr_magic::fetch_initial_sptr(gr_basic_block *p)
51 * If p isn't a subclass of gr_hier_block2, just create the
52 * shared ptr and return it.
54 gr_hier_block2 *hb2 = dynamic_cast<gr_hier_block2 *>(p);
56 return gr_basic_block_sptr(p);
60 * p is a subclass of gr_hier_block2, thus we've already created the shared pointer
61 * and stashed it away. Fish it out and return it.
63 gruel::scoped_lock guard(s_mutex);
64 sptr_map::iterator pos = s_map.find(static_cast<gr_basic_block *>(p));
65 if (pos == s_map.end())
66 throw std::invalid_argument("gr_sptr_magic: invalid pointer!");
68 gr_basic_block_sptr sptr = pos->second;