diff options
author | lloyd <[email protected]> | 2008-09-28 23:37:39 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-09-28 23:37:39 +0000 |
commit | ce4f262d2519324e2a5f0dd9d5b786e43c968f96 (patch) | |
tree | e4f278140be9cca7588ee273d4e59550718d4f73 /src | |
parent | a6f3801debb5239505ec2c9523a7fec5a9bbb070 (diff) |
Move Default_Mutex (now Noop_Mutex) into module
Diffstat (limited to 'src')
-rw-r--r-- | src/libstate.cpp | 8 | ||||
-rw-r--r-- | src/modules.cpp | 13 | ||||
-rw-r--r-- | src/mutex/noop_mutex/modinfo.txt | 10 | ||||
-rw-r--r-- | src/mutex/noop_mutex/mux_noop.cpp (renamed from src/mutex.cpp) | 34 | ||||
-rw-r--r-- | src/mutex/noop_mutex/mux_noop.h | 24 |
5 files changed, 58 insertions, 31 deletions
diff --git a/src/libstate.cpp b/src/libstate.cpp index 141e0d1ec..df9d2b519 100644 --- a/src/libstate.cpp +++ b/src/libstate.cpp @@ -228,10 +228,10 @@ void Library_State::initialize(const InitializerOptions& args, if(mutex_factory) throw Invalid_State("Library_State has already been initialized"); - if(args.thread_safe()) - mutex_factory = modules.mutex_factory(); - else - mutex_factory = new Default_Mutex_Factory; + mutex_factory = modules.mutex_factory(args.thread_safe()); + + if(!mutex_factory) + throw Invalid_State("Could not acquire a mutex module at init"); allocator_lock = get_mutex(); engine_lock = get_mutex(); diff --git a/src/modules.cpp b/src/modules.cpp index d38a29c9a..08ab0cdbb 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -17,6 +17,10 @@ #include <botan/mux_qt.h> #endif +#if defined(BOTAN_HAS_MUTEX_NOOP) + #include <botan/mux_noop.h> +#endif + #if defined(BOTAN_HAS_ALLOC_MMAP) #include <botan/mmap_mem.h> #endif @@ -34,8 +38,15 @@ namespace Botan { /************************************************* * Return a mutex factory, if available * *************************************************/ -Mutex_Factory* Builtin_Modules::mutex_factory() const +Mutex_Factory* Builtin_Modules::mutex_factory(bool thread_safe) const { + if(!thread_safe) + { +#if defined(BOTAN_HAS_MUTEX_NOOP) + return new Noop_Mutex_Factory; +#endif + } + #if defined(BOTAN_HAS_MUTEX_PTHREAD) return new Pthread_Mutex_Factory; #elif defined(BOTAN_HAS_MUTEX_WIN32) diff --git a/src/mutex/noop_mutex/modinfo.txt b/src/mutex/noop_mutex/modinfo.txt new file mode 100644 index 000000000..1f49f5e1c --- /dev/null +++ b/src/mutex/noop_mutex/modinfo.txt @@ -0,0 +1,10 @@ +realname "No-Op Mutex" + +load_on auto + +define MUTEX_NOOP + +<add> +mux_noop.cpp +mux_noop.h +</add> diff --git a/src/mutex.cpp b/src/mutex/noop_mutex/mux_noop.cpp index b7de6b8f2..eb3a12702 100644 --- a/src/mutex.cpp +++ b/src/mutex/noop_mutex/mux_noop.cpp @@ -1,43 +1,25 @@ /************************************************* -* Mutex Source File * +* No-Op Mutex Factory Source File * * (C) 1999-2007 Jack Lloyd * *************************************************/ -#include <botan/mutex.h> +#include <botan/mux_noop.h> namespace Botan { /************************************************* -* Mutex_Holder Constructor * +* No-Op Mutex Factory * *************************************************/ -Mutex_Holder::Mutex_Holder(Mutex* m) : mux(m) +Mutex* Noop_Mutex_Factory::make() { - if(!mux) - throw Invalid_Argument("Mutex_Holder: Argument was NULL"); - mux->lock(); - } - -/************************************************* -* Mutex_Holder Destructor * -*************************************************/ -Mutex_Holder::~Mutex_Holder() - { - mux->unlock(); - } - -/************************************************* -* Default Mutex Factory * -*************************************************/ -Mutex* Default_Mutex_Factory::make() - { - class Default_Mutex : public Mutex + class Noop_Mutex : public Mutex { public: class Mutex_State_Error : public Internal_Error { public: Mutex_State_Error(const std::string& where) : - Internal_Error("Default_Mutex::" + where + ": " + + Internal_Error("Noop_Mutex::" + where + ": " + "Mutex is already " + where + "ed") {} }; @@ -55,12 +37,12 @@ Mutex* Default_Mutex_Factory::make() locked = false; } - Default_Mutex() { locked = false; } + Noop_Mutex() { locked = false; } private: bool locked; }; - return new Default_Mutex; + return new Noop_Mutex; } } diff --git a/src/mutex/noop_mutex/mux_noop.h b/src/mutex/noop_mutex/mux_noop.h new file mode 100644 index 000000000..a5b802cc0 --- /dev/null +++ b/src/mutex/noop_mutex/mux_noop.h @@ -0,0 +1,24 @@ +/************************************************* +* No-Op Mutex Factory Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_NOOP_MUTEX_FACTORY_H__ +#define BOTAN_NOOP_MUTEX_FACTORY_H__ + +#include <botan/mutex.h> + +namespace Botan { + +/************************************************* +* No-Op Mutex Factory * +*************************************************/ +class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif |