diff options
author | lloyd <[email protected]> | 2009-09-30 18:03:46 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-09-30 18:03:46 +0000 |
commit | ce2c86429a5b69ff059205f348732b7fbf4eafc8 (patch) | |
tree | d9389731c8a6cbd7c3dc6b6082ea598459cfdb12 /Attic/mutex/pthreads/mux_pthr.cpp | |
parent | 59b4eb0bd2d1b9d65c3921f5205a012f1a98fdf8 (diff) | |
parent | d5c7febf558af0f7a6f0edf3595d55fe04dce0f5 (diff) |
propagate from branch 'net.randombit.botan' (head 8a5eb02c2e451fc983f234f7ba2f023f5a7d294f)
to branch 'net.randombit.botan.c++0x' (head e18cd411269e15638df3298d6a4165446e7ca529)
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..9f1d9816e --- /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/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(); + } + +} |