aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/mutex/pthreads/mux_pthr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/mutex/pthreads/mux_pthr.cpp')
-rw-r--r--src/utils/mutex/pthreads/mux_pthr.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/utils/mutex/pthreads/mux_pthr.cpp b/src/utils/mutex/pthreads/mux_pthr.cpp
new file mode 100644
index 000000000..d003fa298
--- /dev/null
+++ b/src/utils/mutex/pthreads/mux_pthr.cpp
@@ -0,0 +1,56 @@
+/*************************************************
+* Pthread Mutex Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/mux_pthr.h>
+#include <botan/exceptn.h>
+
+#ifndef _POSIX_C_SOURCE
+ #define _POSIX_C_SOURCE 199506
+#endif
+
+#include <pthread.h>
+
+namespace Botan {
+
+/*************************************************
+* Pthread Mutex Factory *
+*************************************************/
+Mutex* Pthread_Mutex_Factory::make()
+ {
+
+ class Pthread_Mutex : public Mutex
+ {
+ public:
+ void lock()
+ {
+ if(pthread_mutex_lock(&mutex) != 0)
+ throw Exception("Pthread_Mutex::lock: Error occured");
+ }
+
+ void unlock()
+ {
+ if(pthread_mutex_unlock(&mutex) != 0)
+ throw Exception("Pthread_Mutex::unlock: Error occured");
+ }
+
+ Pthread_Mutex()
+ {
+ if(pthread_mutex_init(&mutex, 0) != 0)
+ throw Exception("Pthread_Mutex: initialization failed");
+ }
+
+ ~Pthread_Mutex()
+ {
+ if(pthread_mutex_destroy(&mutex) != 0)
+ throw Invalid_State("~Pthread_Mutex: mutex is still locked");
+ }
+ private:
+ pthread_mutex_t mutex;
+ };
+
+ return new Pthread_Mutex();
+ }
+
+}