diff options
author | lloyd <[email protected]> | 2011-06-13 17:06:08 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2011-06-13 17:06:08 +0000 |
commit | 5fcdf6953ed820a446862702311221c10ae0b91d (patch) | |
tree | 10354a54bb8ef5c8f9c6cdd9fa0142ab0037c635 /Attic/mutex/pthreads/mux_pthr.cpp | |
parent | b145e593616e83a4c124bba70d451ef0f03c5f3f (diff) | |
parent | 1a28f7ef6064041955e7a662c5e087bbea03b6ad (diff) |
propagate from branch 'net.randombit.botan' (head 150bd11dd8090559ee1e83394b8283bf93a018de)
to branch 'net.randombit.botan.c++0x' (head 7480693bb3f1e8a4e039a3e7ba3d9a7007f9730e)
Diffstat (limited to 'Attic/mutex/pthreads/mux_pthr.cpp')
-rw-r--r-- | Attic/mutex/pthreads/mux_pthr.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Attic/mutex/pthreads/mux_pthr.cpp b/Attic/mutex/pthreads/mux_pthr.cpp new file mode 100644 index 000000000..165132239 --- /dev/null +++ b/Attic/mutex/pthreads/mux_pthr.cpp @@ -0,0 +1,58 @@ +/* +* Pthread Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/internal/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 Invalid_State("Pthread_Mutex::lock: Error occured"); + } + + void unlock() + { + if(pthread_mutex_unlock(&mutex) != 0) + throw Invalid_State("Pthread_Mutex::unlock: Error occured"); + } + + Pthread_Mutex() + { + if(pthread_mutex_init(&mutex, 0) != 0) + throw Invalid_State("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(); + } + +} |