From a0a4c483bc1f4e50d5e7cde622aad01acbdec204 Mon Sep 17 00:00:00 2001 From: "Adam C. Emerson" Date: Thu, 5 Oct 2017 18:32:32 -0400 Subject: [PATCH] config: Add templated _get_val for use in observers When notified by a config observer, the config lock is already held, create a _get_val template to manipulate newstyle options when notified. Signed-off-by: Adam C. Emerson --- src/common/config.cc | 10 +++++++++- src/common/config.h | 7 +++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/common/config.cc b/src/common/config.cc index 564039b9c81ec..4883418c03ab5 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -726,8 +726,16 @@ void md_config_t::_apply_changes(std::ostream *oss) void md_config_t::call_all_observers() { std::map > obs; + // Have the scope of the lock extend to the scope of + // handle_conf_change since that function expects to be called with + // the lock held. (And the comment in config.h says that is the + // expected behavior.) + // + // An alternative might be to pass a std::unique_lock to + // handle_conf_change and have a version of get_var that can take it + // by reference and lock as appropriate. + Mutex::Locker l(lock); { - Mutex::Locker l(lock); expand_all_meta(); diff --git a/src/common/config.h b/src/common/config.h index 1e573f5e11b28..768521f9489ea 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -162,6 +162,7 @@ public: int _get_val(const std::string &key, char **buf, int len) const; Option::value_t get_val_generic(const std::string &key) const; template T get_val(const std::string &key) const; + template T _get_val(const std::string &key) const; void get_all_keys(std::vector *keys) const; @@ -338,6 +339,12 @@ template T md_config_t::get_val(const std::string &key) const { return boost::apply_visitor(gtv, generic_val); } +template T md_config_t::_get_val(const std::string &key) const { + Option::value_t generic_val = this->_get_val(key); + get_typed_value_visitor gtv; + return boost::apply_visitor(gtv, generic_val); +} + inline std::ostream& operator<<(std::ostream& o, const boost::blank& ) { return o << "INVALID_CONFIG_VALUE"; } -- 2.39.5