summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarek Kawamoto <darek@he360.com>2016-10-26 16:54:23 -0400
committerJohnathan Corgan <johnathan@corganlabs.com>2016-10-28 11:02:40 -0700
commit1799695dc23d2a9135a7c966cb56c80c08880801 (patch)
treec18d6abb71bdd53b83a94ec7805bf2b90716af43
parent7d80de84057817d0134699b6893efd19717ed1ab (diff)
pmt.cc: Adding mutex for thread-safety to handle simultaneous pmt_symbol insertions.
-rw-r--r--gnuradio-runtime/lib/pmt/pmt.cc12
1 files changed, 11 insertions, 1 deletions
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index 51fb86e58c..e09452e60e 100644
--- a/gnuradio-runtime/lib/pmt/pmt.cc
+++ b/gnuradio-runtime/lib/pmt/pmt.cc
@@ -281,7 +281,17 @@ string_to_symbol(const std::string &name)
if (name == _symbol(sym)->name())
return sym; // Yes. Return it
}
-
+
+ // Lock the table on insert for thread safety:
+ static boost::mutex thread_safety;
+ boost::mutex::scoped_lock lock(thread_safety);
+ // Re-do the search in case another thread inserted this symbol into the table
+ // before we got the lock
+ for (pmt_t sym = (*get_symbol_hash_table())[hash]; sym; sym = _symbol(sym)->next()){
+ if (name == _symbol(sym)->name())
+ return sym; // Yes. Return it
+ }
+
// Nope. Make a new one.
pmt_t sym = pmt_t(new pmt_symbol(name));
_symbol(sym)->set_next((*get_symbol_hash_table())[hash]);