aboutsummaryrefslogtreecommitdiffstats
path: root/src/mutex.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-05-18 18:33:19 +0000
committerlloyd <[email protected]>2006-05-18 18:33:19 +0000
commita2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch)
treead3d6c4fcc8dd0f403f8105598943616246fe172 /src/mutex.cpp
Initial checkin1.5.6
Diffstat (limited to 'src/mutex.cpp')
-rw-r--r--src/mutex.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/mutex.cpp b/src/mutex.cpp
new file mode 100644
index 000000000..1b6c7b2d6
--- /dev/null
+++ b/src/mutex.cpp
@@ -0,0 +1,73 @@
+/*************************************************
+* Mutex Source File *
+* (C) 1999-2006 The Botan Project *
+*************************************************/
+
+#include <botan/mutex.h>
+
+namespace Botan {
+
+namespace {
+
+/*************************************************
+* Default Mutex *
+*************************************************/
+class Default_Mutex : public Mutex
+ {
+ public:
+ void lock();
+ void unlock();
+ Default_Mutex() { locked = false; }
+ private:
+ bool locked;
+ };
+
+/*************************************************
+* Lock the mutex *
+*************************************************/
+void Default_Mutex::lock()
+ {
+ if(locked)
+ throw Internal_Error("Default_Mutex::lock: Mutex is already locked");
+ locked = true;
+ }
+
+/*************************************************
+* Unlock the mutex *
+*************************************************/
+void Default_Mutex::unlock()
+ {
+ if(!locked)
+ throw Internal_Error("Default_Mutex::unlock: Mutex is already unlocked");
+ locked = false;
+ }
+
+}
+
+/*************************************************
+* Mutex_Holder Constructor *
+*************************************************/
+Mutex_Holder::Mutex_Holder(Mutex* m) : mux(m)
+ {
+ 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* Mutex_Factory::make()
+ {
+ return new Default_Mutex;
+ }
+
+}