diff options
author | lloyd <[email protected]> | 2010-09-03 13:55:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-09-03 13:55:19 +0000 |
commit | 7e54763ea43c8b34729387c7429922dd981c4f5b (patch) | |
tree | 33a1bd0f32e4ab7958a484e468316291c527dd24 /Attic/mutex/pthreads | |
parent | fb68795162b8d107cbd284c4a75d8e13ce589829 (diff) | |
parent | ec8c59af3db02ff159908f9a446e53c4ea20d474 (diff) |
propagate from branch 'net.randombit.botan' (head a29c41b4a949207b1544096c3afab668f8b5179e)
to branch 'net.randombit.botan.c++0x' (head a9d0c2f805b3c20a4c648575d7256959db8329fe)
Diffstat (limited to 'Attic/mutex/pthreads')
-rw-r--r-- | Attic/mutex/pthreads/info.txt | 29 | ||||
-rw-r--r-- | Attic/mutex/pthreads/mux_pthr.cpp | 58 | ||||
-rw-r--r-- | Attic/mutex/pthreads/mux_pthr.h | 26 |
3 files changed, 113 insertions, 0 deletions
diff --git a/Attic/mutex/pthreads/info.txt b/Attic/mutex/pthreads/info.txt new file mode 100644 index 000000000..1d826b61c --- /dev/null +++ b/Attic/mutex/pthreads/info.txt @@ -0,0 +1,29 @@ +define MUTEX_PTHREAD + +<source> +mux_pthr.cpp +</source> + +<header:internal> +mux_pthr.h +</header:internal> + +<libs> +all!qnx,freebsd,dragonfly,openbsd,netbsd -> pthread +</libs> + +<os> +aix +cygwin +darwin +freebsd +dragonfly +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 +</os> 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(); + } + +} diff --git a/Attic/mutex/pthreads/mux_pthr.h b/Attic/mutex/pthreads/mux_pthr.h new file mode 100644 index 000000000..5cecd09ad --- /dev/null +++ b/Attic/mutex/pthreads/mux_pthr.h @@ -0,0 +1,26 @@ +/* +* Pthread Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_PTHREAD_H__ +#define BOTAN_MUTEX_PTHREAD_H__ + +#include <botan/internal/mutex.h> + +namespace Botan { + +/** +* Pthread Mutex Factory +*/ +class Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif |