diff options
Diffstat (limited to 'gnuradio-runtime')
-rw-r--r-- | gnuradio-runtime/include/gnuradio/block_registry.h | 1 | ||||
-rw-r--r-- | gnuradio-runtime/lib/block_registry.cc | 14 | ||||
-rw-r--r-- | gnuradio-runtime/lib/flat_flowgraph.cc | 11 | ||||
-rw-r--r-- | gnuradio-runtime/lib/vmcircbuf.cc | 4 | ||||
-rw-r--r-- | gnuradio-runtime/lib/vmcircbuf.h | 3 | ||||
-rw-r--r-- | gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc | 4 |
6 files changed, 36 insertions, 1 deletions
diff --git a/gnuradio-runtime/include/gnuradio/block_registry.h b/gnuradio-runtime/include/gnuradio/block_registry.h index f94be2dafb..49f0b7222d 100644 --- a/gnuradio-runtime/include/gnuradio/block_registry.h +++ b/gnuradio-runtime/include/gnuradio/block_registry.h @@ -59,6 +59,7 @@ namespace gr { blockmap_t d_map; pmt::pmt_t d_ref_map; std::map< std::string, block*> primitive_map; + gr::thread::mutex d_mutex; }; } /* namespace gr */ diff --git a/gnuradio-runtime/lib/block_registry.cc b/gnuradio-runtime/lib/block_registry.cc index f17e3e4af9..c4dc7647d6 100644 --- a/gnuradio-runtime/lib/block_registry.cc +++ b/gnuradio-runtime/lib/block_registry.cc @@ -39,6 +39,8 @@ namespace gr { long block_registry::block_register(basic_block* block) { + gr::thread::scoped_lock guard(d_mutex); + if(d_map.find(block->name()) == d_map.end()) { d_map[block->name()] = blocksubmap_t(); d_map[block->name()][0] = block; @@ -58,6 +60,8 @@ namespace gr { void block_registry::block_unregister(basic_block* block) { + gr::thread::scoped_lock guard(d_mutex); + d_map[block->name()].erase( d_map[block->name()].find(block->symbolic_id())); d_ref_map = pmt::dict_delete(d_ref_map, pmt::intern(block->symbol_name())); if(block->alias_set()) { @@ -78,6 +82,8 @@ namespace gr { void block_registry::register_symbolic_name(basic_block* block, std::string name) { + gr::thread::scoped_lock guard(d_mutex); + if(pmt::dict_has_key(d_ref_map, pmt::intern(name))) { throw std::runtime_error("symbol already exists, can not re-use!"); } @@ -87,6 +93,8 @@ namespace gr { basic_block_sptr block_registry::block_lookup(pmt::pmt_t symbol) { + gr::thread::scoped_lock guard(d_mutex); + pmt::pmt_t ref = pmt::dict_ref(d_ref_map, symbol, pmt::PMT_NIL); if(pmt::eq(ref, pmt::PMT_NIL)) { throw std::runtime_error("block lookup failed! block not found!"); @@ -98,18 +106,24 @@ namespace gr { void block_registry::register_primitive(std::string blk, block* ref) { + gr::thread::scoped_lock guard(d_mutex); + primitive_map[blk] = ref; } void block_registry::unregister_primitive(std::string blk) { + gr::thread::scoped_lock guard(d_mutex); + primitive_map.erase(primitive_map.find(blk)); } void block_registry::notify_blk(std::string blk) { + gr::thread::scoped_lock guard(d_mutex); + if(primitive_map.find(blk) == primitive_map.end()) { return; } diff --git a/gnuradio-runtime/lib/flat_flowgraph.cc b/gnuradio-runtime/lib/flat_flowgraph.cc index b8a1a67bc7..ae79288334 100644 --- a/gnuradio-runtime/lib/flat_flowgraph.cc +++ b/gnuradio-runtime/lib/flat_flowgraph.cc @@ -161,7 +161,16 @@ namespace gr { } // std::cout << "make_buffer(" << nitems << ", " << item_size << ", " << grblock << "\n"; - return make_buffer(nitems, item_size, grblock); + // We're going to let this fail once and retry. If that fails, + // throw and exit. + buffer_sptr b; + try { + b = make_buffer(nitems, item_size, grblock); + } + catch(std::bad_alloc&) { + b = make_buffer(nitems, item_size, grblock); + } + return b; } void diff --git a/gnuradio-runtime/lib/vmcircbuf.cc b/gnuradio-runtime/lib/vmcircbuf.cc index 0fccb3d914..315d409c5d 100644 --- a/gnuradio-runtime/lib/vmcircbuf.cc +++ b/gnuradio-runtime/lib/vmcircbuf.cc @@ -40,6 +40,8 @@ #include "vmcircbuf_mmap_shm_open.h" #include "vmcircbuf_mmap_tmpfile.h" +gr::thread::mutex s_vm_mutex; + namespace gr { static const char *FACTORY_PREF_KEY = "vmcircbuf_default_factory"; @@ -64,6 +66,8 @@ namespace gr { bool verbose = false; + gr::thread::scoped_lock guard(s_vm_mutex); + std::vector<gr::vmcircbuf_factory *> all = all_factories (); const char *name = gr::vmcircbuf_prefs::get(FACTORY_PREF_KEY); diff --git a/gnuradio-runtime/lib/vmcircbuf.h b/gnuradio-runtime/lib/vmcircbuf.h index c3ddfe0043..f9ed045168 100644 --- a/gnuradio-runtime/lib/vmcircbuf.h +++ b/gnuradio-runtime/lib/vmcircbuf.h @@ -24,8 +24,11 @@ #define GR_VMCIRCBUF_H #include <gnuradio/api.h> +#include <gnuradio/thread/thread.h> #include <vector> +extern gr::thread::mutex s_vm_mutex; + namespace gr { /*! diff --git a/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc b/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc index 0d7e9b7d34..484b1a914e 100644 --- a/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc +++ b/gnuradio-runtime/lib/vmcircbuf_sysv_shm.cc @@ -46,6 +46,8 @@ namespace gr { vmcircbuf_sysv_shm::vmcircbuf_sysv_shm(int size) : gr::vmcircbuf(size) { + gr::thread::scoped_lock guard(s_vm_mutex); + #if !defined(HAVE_SYS_SHM_H) fprintf(stderr, "gr::vmcircbuf_sysv_shm: sysv shared memory is not available\n"); throw std::runtime_error("gr::vmcircbuf_sysv_shm"); @@ -150,6 +152,8 @@ namespace gr { vmcircbuf_sysv_shm::~vmcircbuf_sysv_shm() { + gr::thread::scoped_lock guard(s_vm_mutex); + #if defined(HAVE_SYS_SHM_H) if(shmdt(d_base - gr::pagesize()) == -1 || shmdt(d_base) == -1 |