diff options
author | lloyd <[email protected]> | 2009-04-01 15:43:27 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-04-01 15:43:27 +0000 |
commit | 99e8c1a20700631103ec20386f8080eeee4df588 (patch) | |
tree | bc3ecc536cb98a39c2707dc8eba08e3a648a5c45 /src/libstate/libstate.cpp | |
parent | 855b569d25b5810213ae7e52c04df4e5e0cf8d46 (diff) |
Remove the mutex classes in favor of C++0x's std::mutex and std::lock_guard
Diffstat (limited to 'src/libstate/libstate.cpp')
-rw-r--r-- | src/libstate/libstate.cpp | 76 |
1 files changed, 17 insertions, 59 deletions
diff --git a/src/libstate/libstate.cpp b/src/libstate/libstate.cpp index 3275c6493..839d71d60 100644 --- a/src/libstate/libstate.cpp +++ b/src/libstate/libstate.cpp @@ -9,21 +9,12 @@ #include <botan/init.h> #include <botan/engine.h> #include <botan/stl_util.h> -#include <botan/mutex.h> #include <botan/mux_noop.h> #include <botan/charset.h> #include <botan/defalloc.h> #include <botan/def_eng.h> #include <algorithm> -#if defined(BOTAN_HAS_MUTEX_PTHREAD) - #include <botan/mux_pthr.h> -#elif defined(BOTAN_HAS_MUTEX_WIN32) - #include <botan/mux_win32.h> -#elif defined(BOTAN_HAS_MUTEX_QT) - #include <botan/mux_qt.h> -#endif - #if defined(BOTAN_HAS_ALLOC_MMAP) #include <botan/mmap_mem.h> #endif @@ -92,19 +83,11 @@ Library_State* swap_global_state(Library_State* new_state) } /* -* Get a new mutex object -*/ -Mutex* Library_State::get_mutex() const - { - return mutex_factory->make(); - } - -/* * Get an allocator by its name */ -Allocator* Library_State::get_allocator(const std::string& type) const +Allocator* Library_State::get_allocator(const std::string& type) { - Mutex_Holder lock(allocator_lock); + std::lock_guard<std::mutex> lock(allocator_lock); if(type != "") return search_map<std::string, Allocator*>(alloc_factory, type, 0); @@ -128,7 +111,7 @@ Allocator* Library_State::get_allocator(const std::string& type) const */ void Library_State::add_allocator(Allocator* allocator) { - Mutex_Holder lock(allocator_lock); + std::lock_guard<std::mutex> lock(allocator_lock); allocator->init(); @@ -141,7 +124,7 @@ void Library_State::add_allocator(Allocator* allocator) */ void Library_State::set_default_allocator(const std::string& type) { - Mutex_Holder lock(allocator_lock); + std::lock_guard<std::mutex> lock(allocator_lock); if(type == "") return; @@ -154,9 +137,9 @@ void Library_State::set_default_allocator(const std::string& type) * Get a configuration value */ std::string Library_State::get(const std::string& section, - const std::string& key) const + const std::string& key) { - Mutex_Holder lock(config_lock); + std::lock_guard<std::mutex> lock(config_lock); return search_map<std::string, std::string>(config, section + "/" + key, ""); @@ -166,9 +149,9 @@ std::string Library_State::get(const std::string& section, * See if a particular option has been set */ bool Library_State::is_set(const std::string& section, - const std::string& key) const + const std::string& key) { - Mutex_Holder lock(config_lock); + std::lock_guard<std::mutex> lock(config_lock); return search_map(config, section + "/" + key, false, true); } @@ -179,7 +162,7 @@ bool Library_State::is_set(const std::string& section, void Library_State::set(const std::string& section, const std::string& key, const std::string& value, bool overwrite) { - Mutex_Holder lock(config_lock); + std::lock_guard<std::mutex> lock(config_lock); std::string full_key = section + "/" + key; @@ -201,7 +184,7 @@ void Library_State::add_alias(const std::string& key, const std::string& value) /* * Dereference an alias to a fixed name */ -std::string Library_State::deref_alias(const std::string& key) const +std::string Library_State::deref_alias(const std::string& key) { std::string result = key; while(is_set("alias", result)) @@ -221,7 +204,7 @@ void Library_State::set_option(const std::string key, /* * Get an option value */ -std::string Library_State::option(const std::string& key) const +std::string Library_State::option(const std::string& key) { return get("conf", key); } @@ -239,38 +222,18 @@ Algorithm_Factory& Library_State::algorithm_factory() /* * Load a set of modules */ -void Library_State::initialize(bool thread_safe) +void Library_State::initialize() { - if(mutex_factory) + if(m_algorithm_factory) throw Invalid_State("Library_State has already been initialized"); - if(!thread_safe) - { - mutex_factory = new Noop_Mutex_Factory; - } - else - { -#if defined(BOTAN_HAS_MUTEX_PTHREAD) - mutex_factory = new Pthread_Mutex_Factory; -#elif defined(BOTAN_HAS_MUTEX_WIN32) - mutex_factory = new Win32_Mutex_Factory; -#elif defined(BOTAN_HAS_MUTEX_QT) - mutex_factory Qt_Mutex_Factory; -#else - throw Invalid_State("Could not find a thread-safe mutex object to use"); -#endif - } - - allocator_lock = mutex_factory->make(); - config_lock = mutex_factory->make(); - cached_default_allocator = 0; add_allocator(new Malloc_Allocator); - add_allocator(new Locking_Allocator(mutex_factory->make())); + add_allocator(new Locking_Allocator); #if defined(BOTAN_HAS_ALLOC_MMAP) - add_allocator(new MemoryMapping_Allocator(mutex_factory->make())); + add_allocator(new MemoryMapping_Allocator); #endif set_default_allocator("locking"); @@ -301,7 +264,7 @@ void Library_State::initialize(bool thread_safe) engines.push_back(new Default_Engine); - m_algorithm_factory = new Algorithm_Factory(engines, *mutex_factory); + m_algorithm_factory = new Algorithm_Factory(engines); } /* @@ -309,8 +272,6 @@ void Library_State::initialize(bool thread_safe) */ Library_State::Library_State() { - mutex_factory = 0; - allocator_lock = config_lock = 0; cached_default_allocator = 0; m_algorithm_factory = 0; } @@ -321,6 +282,7 @@ Library_State::Library_State() Library_State::~Library_State() { delete m_algorithm_factory; + m_algorithm_factory = 0; cached_default_allocator = 0; @@ -329,10 +291,6 @@ Library_State::~Library_State() allocators[j]->destroy(); delete allocators[j]; } - - delete allocator_lock; - delete mutex_factory; - delete config_lock; } } |