[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 05/05: pmt.cc: Adding mutex for thread-safe
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 05/05: pmt.cc: Adding mutex for thread-safety to handle simultaneous pmt_symbol insertions. |
Date: |
Fri, 28 Oct 2016 18:55:45 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch maint
in repository gnuradio.
commit 1799695dc23d2a9135a7c966cb56c80c08880801
Author: Darek Kawamoto <address@hidden>
Date: Wed Oct 26 16:54:23 2016 -0400
pmt.cc: Adding mutex for thread-safety to handle simultaneous pmt_symbol
insertions.
---
gnuradio-runtime/lib/pmt/pmt.cc | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/gnuradio-runtime/lib/pmt/pmt.cc b/gnuradio-runtime/lib/pmt/pmt.cc
index 51fb86e..e09452e 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]);