aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-04-02 18:52:13 +0000
committerlloyd <[email protected]>2008-04-02 18:52:13 +0000
commit8a5ffc5c6294786ad70f7a8fdd7606f411690ce9 (patch)
tree16b7d8d757e1ac6c8b2460d3e6a42768de466c8c /src/config.cpp
parent91c318bbad1fcff1c9b04f1077fb4ec75d59a549 (diff)
Remove the Named_Mutex_Holder and associated code. Convert all uses to
instead allocate a reference to a mutex locally and use the more typical Mutex_Holder RAII object. Named_Mutex_Holder (and in particular the string->mutex mappings contained in the global state) have been found to be pretty expensive in at least some situations (see post by Jack Cummings to monotone-devel 2008-03-12), and doesn't really buy us that much in terms of ease of use. Also, it relies on the global state object, which has shown itself to be a rich source of race conditions and locking bugs. The intent is to incrementally remove all of the shared / global state and require applications to maintain that state where necessary.
Diffstat (limited to 'src/config.cpp')
-rw-r--r--src/config.cpp38
1 files changed, 27 insertions, 11 deletions
diff --git a/src/config.cpp b/src/config.cpp
index 3f03c70c0..7706a33f3 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -23,12 +23,36 @@ Config& global_config()
}
/*************************************************
+* Dereference an alias *
+*************************************************/
+std::string deref_alias(const std::string& name)
+ {
+ return global_state().config().deref_alias(name);
+ }
+
+/*************************************************
+* Get a configuration value *
+*************************************************/
+Config::Config()
+ {
+ mutex = global_state().get_mutex();
+ }
+
+/*************************************************
+* Get a configuration value *
+*************************************************/
+Config::~Config()
+ {
+ delete mutex;
+ }
+
+/*************************************************
* Get a configuration value *
*************************************************/
std::string Config::get(const std::string& section,
const std::string& key) const
{
- Named_Mutex_Holder lock("config");
+ Mutex_Holder lock(mutex);
return search_map<std::string, std::string>(settings,
section + "/" + key, "");
@@ -40,7 +64,7 @@ std::string Config::get(const std::string& section,
bool Config::is_set(const std::string& section,
const std::string& key) const
{
- Named_Mutex_Holder lock("config");
+ Mutex_Holder lock(mutex);
return search_map(settings, section + "/" + key, false, true);
}
@@ -51,7 +75,7 @@ bool Config::is_set(const std::string& section,
void Config::set(const std::string& section, const std::string& key,
const std::string& value, bool overwrite)
{
- Named_Mutex_Holder lock("config");
+ Mutex_Holder lock(mutex);
std::string full_key = section + "/" + key;
@@ -192,12 +216,4 @@ void Config::choose_sig_format(const std::string& algo_name,
throw Invalid_Argument("Unknown X.509 signing key type: " + algo_name);
}
-/*************************************************
-* Dereference an alias *
-*************************************************/
-std::string deref_alias(const std::string& name)
- {
- return global_config().deref_alias(name);
- }
-
}