diff options
author | Thomas Habets <habets@google.com> | 2021-04-06 21:14:19 +0100 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-05-02 19:00:31 -0400 |
commit | e396aefe6c4f796da6ce3dcc626615ad8b847e7e (patch) | |
tree | ca7c1baddd8651edf0928cc9dc425a4d929384ef | |
parent | c9482f9a91e2fa58097097be390bcf76ef4c5ba5 (diff) |
runtime: Use mutex for prefs
Signed-off-by: Thomas Habets <thomas@habets.se>
-rw-r--r-- | gnuradio-runtime/include/gnuradio/prefs.h | 2 | ||||
-rw-r--r-- | gnuradio-runtime/lib/prefs.cc | 12 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc | 2 |
3 files changed, 11 insertions, 5 deletions
diff --git a/gnuradio-runtime/include/gnuradio/prefs.h b/gnuradio-runtime/include/gnuradio/prefs.h index 606cf0b1b1..2fa6f86bc4 100644 --- a/gnuradio-runtime/include/gnuradio/prefs.h +++ b/gnuradio-runtime/include/gnuradio/prefs.h @@ -154,7 +154,7 @@ protected: void set_general(const std::string& section, const std::string& option, const T& val); private: - // TODO: add back and actually use: gr::thread::mutex d_mutex; + std::mutex d_mutex; config_map_t d_config_map; }; diff --git a/gnuradio-runtime/lib/prefs.cc b/gnuradio-runtime/lib/prefs.cc index 14d3fe25fd..5236b9c59f 100644 --- a/gnuradio-runtime/lib/prefs.cc +++ b/gnuradio-runtime/lib/prefs.cc @@ -20,6 +20,7 @@ #include <filesystem> #include <fstream> #include <iostream> +#include <mutex> #include <boost/program_options.hpp> namespace fs = std::filesystem; @@ -107,6 +108,7 @@ void prefs::_read_files(const std::vector<std::string>& filenames) // value of a basic_option is always a std::vector<string>; we only // allow single values, so: std::string value = o.value[0]; + std::lock_guard<std::mutex> lk(d_mutex); d_config_map[section][key] = value; } } catch (std::exception& e) { @@ -129,6 +131,7 @@ std::string prefs::to_string() config_map_itr sections; config_map_elem_itr options; std::stringstream s; + std::lock_guard<std::mutex> lk(d_mutex); for (sections = d_config_map.begin(); sections != d_config_map.end(); sections++) { s << "[" << sections->first << "]" << std::endl; @@ -166,6 +169,7 @@ bool prefs::has_section(const std::string& section) { std::string s = section; stolower(s); + std::lock_guard<std::mutex> lk(d_mutex); return d_config_map.count(s) > 0; } @@ -183,6 +187,7 @@ bool prefs::has_option(const std::string& section, const std::string& option) std::string o = option; stolower(o); + std::lock_guard<std::mutex> lk(d_mutex); config_map_itr sec = d_config_map.find(s); return sec->second.count(o) > 0; } @@ -206,6 +211,7 @@ const std::string prefs::get_string(const std::string& section, std::string o = option; stolower(o); + std::lock_guard<std::mutex> lk(d_mutex); config_map_itr sec = d_config_map.find(s); config_map_elem_itr opt = sec->second.find(o); return opt->second; @@ -259,12 +265,12 @@ void prefs::set_general(const std::string& section, stolower(s); std::string o = option; stolower(o); - std::map<std::string, std::string> opt_map = d_config_map[s]; std::stringstream sstr; sstr << val; - opt_map[o] = sstr.str(); - d_config_map[s] = opt_map; + + std::lock_guard<std::mutex> lk(d_mutex); + d_config_map[s][o] = sstr.str(); } void prefs::set_bool(const std::string& section, const std::string& option, bool val) diff --git a/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc b/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc index a9d42dac51..e5e21ca49b 100644 --- a/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc +++ b/gnuradio-runtime/python/gnuradio/gr/bindings/prefs_python.cc @@ -14,7 +14,7 @@ /* BINDTOOL_GEN_AUTOMATIC(0) */ /* BINDTOOL_USE_PYGCCXML(0) */ /* BINDTOOL_HEADER_FILE(prefs.h) */ -/* BINDTOOL_HEADER_FILE_HASH(59ed43a1f982f3c7da3f0f6b51941294) */ +/* BINDTOOL_HEADER_FILE_HASH(4d5fd75bdefb15004e9f86e1ddec95fc) */ /***********************************************************************************/ #include <pybind11/complex.h> |