diff options
author | lloyd <[email protected]> | 2008-11-11 20:58:37 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-11-11 20:58:37 +0000 |
commit | 8879a51da7c3b93e27439122cea5d5aa81ae38c3 (patch) | |
tree | b1faa753266d4a762fc38252df35a2435b757b92 /src/mutex/pthreads | |
parent | 6eff33ae263109ccbbeb32bd0ffb25c77140cc45 (diff) |
Move utils/{timer,mutex} to toplevel
Diffstat (limited to 'src/mutex/pthreads')
-rw-r--r-- | src/mutex/pthreads/info.txt | 29 | ||||
-rw-r--r-- | src/mutex/pthreads/mux_pthr.cpp | 56 | ||||
-rw-r--r-- | src/mutex/pthreads/mux_pthr.h | 24 |
3 files changed, 109 insertions, 0 deletions
diff --git a/src/mutex/pthreads/info.txt b/src/mutex/pthreads/info.txt new file mode 100644 index 000000000..88de70de0 --- /dev/null +++ b/src/mutex/pthreads/info.txt @@ -0,0 +1,29 @@ +realname "Pthread Mutex" + +define MUTEX_PTHREAD + +load_on auto + +<add> +mux_pthr.cpp +mux_pthr.h +</add> + +<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/src/mutex/pthreads/mux_pthr.cpp b/src/mutex/pthreads/mux_pthr.cpp new file mode 100644 index 000000000..d003fa298 --- /dev/null +++ b/src/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(); + } + +} diff --git a/src/mutex/pthreads/mux_pthr.h b/src/mutex/pthreads/mux_pthr.h new file mode 100644 index 000000000..79eed0c97 --- /dev/null +++ b/src/mutex/pthreads/mux_pthr.h @@ -0,0 +1,24 @@ +/************************************************* +* Pthread Mutex Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MUTEX_PTHREAD_H__ +#define BOTAN_MUTEX_PTHREAD_H__ + +#include <botan/mutex.h> + +namespace Botan { + +/************************************************* +* Pthread Mutex Factory * +*************************************************/ +class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif |