aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/base
diff options
context:
space:
mode:
authorJack Lloyd <[email protected]>2016-10-12 15:32:14 -0400
committerJack Lloyd <[email protected]>2016-10-12 15:32:14 -0400
commited9e147695e4c5e800e83654baf365a634f3a2a7 (patch)
tree59bad402cff7d7af9baa5fd79081d677b60afc83 /src/lib/base
parentd59b164a2ad2bc2290265530ac1a5c7be7855975 (diff)
Abstract out mutex type. Make threads optional.
Diffstat (limited to 'src/lib/base')
-rw-r--r--src/lib/base/algo_registry.h16
-rw-r--r--src/lib/base/scan_name.cpp6
-rw-r--r--src/lib/base/scan_name.h4
3 files changed, 13 insertions, 13 deletions
diff --git a/src/lib/base/algo_registry.h b/src/lib/base/algo_registry.h
index f7e66b3e2..bca3715b6 100644
--- a/src/lib/base/algo_registry.h
+++ b/src/lib/base/algo_registry.h
@@ -13,7 +13,7 @@
#include <botan/exceptn.h>
#include <botan/scan_name.h>
#include <functional>
-#include <mutex>
+#include <botan/mutex.h>
#include <vector>
#include <map>
#include <string>
@@ -77,14 +77,14 @@ class Algo_Registry
void add(const std::string& name, const std::string& provider, maker_fn fn, byte pref)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
if(!m_algo_info[name].add_provider(provider, fn, pref))
throw Exception("Duplicated registration of " + name + "/" + provider);
}
std::vector<std::string> providers_of(const Spec& spec)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
auto i = m_algo_info.find(spec.algo_name());
if(i != m_algo_info.end())
return i->second.providers();
@@ -93,7 +93,7 @@ class Algo_Registry
void set_provider_preference(const Spec& spec, const std::string& provider, byte pref)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
auto i = m_algo_info.find(spec.algo_name());
if(i != m_algo_info.end())
i->second.set_pref(provider, pref);
@@ -137,16 +137,16 @@ class Algo_Registry
private:
#if defined(BOTAN_WORKAROUND_GH_321)
- using mutex = WinCS_Mutex;
+ using af_mutex_type = WinCS_Mutex;
#else
- using mutex = std::mutex;
+ using af_mutex_type = mutex_type;
#endif
Algo_Registry() { }
std::vector<maker_fn> get_makers(const Spec& spec, const std::string& provider)
{
- std::lock_guard<mutex> lock(m_mutex);
+ lock_guard_type<af_mutex_type> lock(m_mutex);
return m_algo_info[spec.algo_name()].get_makers(provider);
}
@@ -208,7 +208,7 @@ class Algo_Registry
std::unordered_map<std::string, maker_fn> m_maker_fns;
};
- mutex m_mutex;
+ af_mutex_type m_mutex;
std::unordered_map<std::string, Algo_Info> m_algo_info;
};
diff --git a/src/lib/base/scan_name.cpp b/src/lib/base/scan_name.cpp
index 08f5e8702..76d9b1a17 100644
--- a/src/lib/base/scan_name.cpp
+++ b/src/lib/base/scan_name.cpp
@@ -172,7 +172,7 @@ size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const
return to_u32bit(m_args[i]);
}
-std::mutex SCAN_Name::g_alias_map_mutex;
+mutex_type SCAN_Name::g_alias_map_mutex;
std::map<std::string, std::string> SCAN_Name::g_alias_map = {
{ "3DES", "TripleDES" },
{ "ARC4", "RC4" },
@@ -197,7 +197,7 @@ std::map<std::string, std::string> SCAN_Name::g_alias_map = {
void SCAN_Name::add_alias(const std::string& alias, const std::string& basename)
{
- std::lock_guard<std::mutex> lock(g_alias_map_mutex);
+ lock_guard_type<mutex_type> lock(g_alias_map_mutex);
if(g_alias_map.find(alias) == g_alias_map.end())
g_alias_map[alias] = basename;
@@ -205,7 +205,7 @@ void SCAN_Name::add_alias(const std::string& alias, const std::string& basename)
std::string SCAN_Name::deref_alias(const std::string& alias)
{
- std::lock_guard<std::mutex> lock(g_alias_map_mutex);
+ lock_guard_type<mutex_type> lock(g_alias_map_mutex);
std::string name = alias;
diff --git a/src/lib/base/scan_name.h b/src/lib/base/scan_name.h
index d59d5889e..1d9132729 100644
--- a/src/lib/base/scan_name.h
+++ b/src/lib/base/scan_name.h
@@ -11,7 +11,7 @@
#include <botan/types.h>
#include <string>
#include <vector>
-#include <mutex>
+#include <botan/mutex.h>
#include <map>
namespace Botan {
@@ -107,7 +107,7 @@ class BOTAN_DLL SCAN_Name
static std::string deref_alias(const std::string& alias);
private:
- static std::mutex g_alias_map_mutex;
+ static mutex_type g_alias_map_mutex;
static std::map<std::string, std::string> g_alias_map;
std::string m_orig_algo_spec;