diff options
Diffstat (limited to 'modules/mux_pthr')
-rw-r--r-- | modules/mux_pthr/modinfo.txt | 25 | ||||
-rw-r--r-- | modules/mux_pthr/mux_pthr.cpp | 62 | ||||
-rw-r--r-- | modules/mux_pthr/mux_pthr.h | 24 |
3 files changed, 111 insertions, 0 deletions
diff --git a/modules/mux_pthr/modinfo.txt b/modules/mux_pthr/modinfo.txt new file mode 100644 index 000000000..0aeca05d6 --- /dev/null +++ b/modules/mux_pthr/modinfo.txt @@ -0,0 +1,25 @@ +realname "Pthread Mutex" + +define MUTEX_PTHREAD + +add_file mux_pthr.cpp +add_file mux_pthr.h + +<libs> +all!qnx,freebsd,openbsd,netbsd -> pthread +</libs> + +<os> +aix +cygwin +darwin +freebsd +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 +</os> diff --git a/modules/mux_pthr/mux_pthr.cpp b/modules/mux_pthr/mux_pthr.cpp new file mode 100644 index 000000000..ec2308fae --- /dev/null +++ b/modules/mux_pthr/mux_pthr.cpp @@ -0,0 +1,62 @@ +/************************************************* +* Pthread Mutex Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/mux_pthr.h> +#include <botan/exceptn.h> + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199506 +#endif + +#include <pthread.h> + +namespace Botan { + +namespace { + +/************************************************* +* Pthread Mutex * +*************************************************/ +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; + }; + +} + +/************************************************* +* Pthread Mutex Factory * +*************************************************/ +Mutex* Pthread_Mutex_Factory::make() + { + return new Pthread_Mutex(); + } + +} diff --git a/modules/mux_pthr/mux_pthr.h b/modules/mux_pthr/mux_pthr.h new file mode 100644 index 000000000..47503d390 --- /dev/null +++ b/modules/mux_pthr/mux_pthr.h @@ -0,0 +1,24 @@ +/************************************************* +* Pthread Mutex Header File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#ifndef BOTAN_EXT_MUTEX_PTHREAD_H__ +#define BOTAN_EXT_MUTEX_PTHREAD_H__ + +#include <botan/mutex.h> + +namespace Botan { + +/************************************************* +* Pthread Mutex Factory * +*************************************************/ +class Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif |