From 8879a51da7c3b93e27439122cea5d5aa81ae38c3 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 11 Nov 2008 20:58:37 +0000 Subject: Move utils/{timer,mutex} to toplevel --- src/mutex/noop_mutex/info.txt | 10 ++++++ src/mutex/noop_mutex/mux_noop.cpp | 48 +++++++++++++++++++++++++ src/mutex/noop_mutex/mux_noop.h | 24 +++++++++++++ src/mutex/pthreads/info.txt | 29 ++++++++++++++++ src/mutex/pthreads/mux_pthr.cpp | 56 ++++++++++++++++++++++++++++++ src/mutex/pthreads/mux_pthr.h | 24 +++++++++++++ src/mutex/qt_mutex/info.txt | 18 ++++++++++ src/mutex/qt_mutex/mux_qt.cpp | 33 ++++++++++++++++++ src/mutex/qt_mutex/mux_qt.h | 25 +++++++++++++ src/mutex/win32_crit_section/info.txt | 17 +++++++++ src/mutex/win32_crit_section/mux_win32.cpp | 32 +++++++++++++++++ src/mutex/win32_crit_section/mux_win32.h | 24 +++++++++++++ 12 files changed, 340 insertions(+) create mode 100644 src/mutex/noop_mutex/info.txt create mode 100644 src/mutex/noop_mutex/mux_noop.cpp create mode 100644 src/mutex/noop_mutex/mux_noop.h create mode 100644 src/mutex/pthreads/info.txt create mode 100644 src/mutex/pthreads/mux_pthr.cpp create mode 100644 src/mutex/pthreads/mux_pthr.h create mode 100644 src/mutex/qt_mutex/info.txt create mode 100644 src/mutex/qt_mutex/mux_qt.cpp create mode 100644 src/mutex/qt_mutex/mux_qt.h create mode 100644 src/mutex/win32_crit_section/info.txt create mode 100644 src/mutex/win32_crit_section/mux_win32.cpp create mode 100644 src/mutex/win32_crit_section/mux_win32.h (limited to 'src/mutex') diff --git a/src/mutex/noop_mutex/info.txt b/src/mutex/noop_mutex/info.txt new file mode 100644 index 000000000..1f49f5e1c --- /dev/null +++ b/src/mutex/noop_mutex/info.txt @@ -0,0 +1,10 @@ +realname "No-Op Mutex" + +load_on auto + +define MUTEX_NOOP + + +mux_noop.cpp +mux_noop.h + diff --git a/src/mutex/noop_mutex/mux_noop.cpp b/src/mutex/noop_mutex/mux_noop.cpp new file mode 100644 index 000000000..eb3a12702 --- /dev/null +++ b/src/mutex/noop_mutex/mux_noop.cpp @@ -0,0 +1,48 @@ +/************************************************* +* No-Op Mutex Factory Source File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#include + +namespace Botan { + +/************************************************* +* No-Op Mutex Factory * +*************************************************/ +Mutex* Noop_Mutex_Factory::make() + { + class Noop_Mutex : public Mutex + { + public: + class Mutex_State_Error : public Internal_Error + { + public: + Mutex_State_Error(const std::string& where) : + Internal_Error("Noop_Mutex::" + where + ": " + + "Mutex is already " + where + "ed") {} + }; + + void lock() + { + if(locked) + throw Mutex_State_Error("lock"); + locked = true; + } + + void unlock() + { + if(!locked) + throw Mutex_State_Error("unlock"); + locked = false; + } + + Noop_Mutex() { locked = false; } + private: + bool locked; + }; + + return new Noop_Mutex; + } + +} diff --git a/src/mutex/noop_mutex/mux_noop.h b/src/mutex/noop_mutex/mux_noop.h new file mode 100644 index 000000000..a5b802cc0 --- /dev/null +++ b/src/mutex/noop_mutex/mux_noop.h @@ -0,0 +1,24 @@ +/************************************************* +* No-Op Mutex Factory Header File * +* (C) 1999-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_NOOP_MUTEX_FACTORY_H__ +#define BOTAN_NOOP_MUTEX_FACTORY_H__ + +#include + +namespace Botan { + +/************************************************* +* No-Op Mutex Factory * +*************************************************/ +class BOTAN_DLL Noop_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif 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 + + +mux_pthr.cpp +mux_pthr.h + + + +all!qnx,freebsd,openbsd,netbsd -> pthread + + + +aix +cygwin +darwin +freebsd +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + 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 +#include + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199506 +#endif + +#include + +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 + +namespace Botan { + +/************************************************* +* Pthread Mutex Factory * +*************************************************/ +class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/mutex/qt_mutex/info.txt b/src/mutex/qt_mutex/info.txt new file mode 100644 index 000000000..a21108c79 --- /dev/null +++ b/src/mutex/qt_mutex/info.txt @@ -0,0 +1,18 @@ +realname "Qt Mutex" + +define MUTEX_QT + +note "You'll probably have to add -I/-L flags to the Makefile to find Qt" + +load_on request + + +mux_qt.cpp +mux_qt.h + + +# I think we want to always use qt-mt, not qt -- not much point in supporting +# mutexes in a single threaded application, after all. + +all -> qt-mt + diff --git a/src/mutex/qt_mutex/mux_qt.cpp b/src/mutex/qt_mutex/mux_qt.cpp new file mode 100644 index 000000000..421b771c7 --- /dev/null +++ b/src/mutex/qt_mutex/mux_qt.cpp @@ -0,0 +1,33 @@ +/************************************************* +* Qt Thread Mutex Source File * +* (C) 2004-2007 Justin Karneges * +* 2004-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +#if !defined(QT_THREAD_SUPPORT) + #error Your version of Qt does not support threads or mutexes +#endif + +namespace Botan { + +/************************************************* +* Qt Mutex Factory * +*************************************************/ +Mutex* Qt_Mutex_Factory::make() + { + class Qt_Mutex : public Mutex + { + public: + void lock() { mutex.lock(); } + void unlock() { mutex.unlock(); } + private: + QMutex mutex; + }; + + return new Qt_Mutex(); + } + +} diff --git a/src/mutex/qt_mutex/mux_qt.h b/src/mutex/qt_mutex/mux_qt.h new file mode 100644 index 000000000..bf230e1ff --- /dev/null +++ b/src/mutex/qt_mutex/mux_qt.h @@ -0,0 +1,25 @@ +/************************************************* +* Qt Mutex Header File * +* (C) 2004-2007 Justin Karneges * +* 2004-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MUTEX_QT_H__ +#define BOTAN_MUTEX_QT_H__ + +#include + +namespace Botan { + +/************************************************* +* Qt Mutex * +*************************************************/ +class BOTAN_DLL Qt_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/src/mutex/win32_crit_section/info.txt b/src/mutex/win32_crit_section/info.txt new file mode 100644 index 000000000..a2d339c3b --- /dev/null +++ b/src/mutex/win32_crit_section/info.txt @@ -0,0 +1,17 @@ +realname "Win32 Mutex" + +define MUTEX_WIN32 +modset win32 + +load_on auto + + +mux_win32.cpp +mux_win32.h + + + +cygwin +windows +mingw + diff --git a/src/mutex/win32_crit_section/mux_win32.cpp b/src/mutex/win32_crit_section/mux_win32.cpp new file mode 100644 index 000000000..622a707fa --- /dev/null +++ b/src/mutex/win32_crit_section/mux_win32.cpp @@ -0,0 +1,32 @@ +/************************************************* +* Win32 Mutex Source File * +* (C) 2006 Luca Piccarreta * +* 2006-2007 Jack Lloyd * +*************************************************/ + +#include +#include + +namespace Botan { + +/************************************************* +* Win32 Mutex Factory * +*************************************************/ +Mutex* Win32_Mutex_Factory::make() + { + class Win32_Mutex : public Mutex + { + public: + void lock() { EnterCriticalSection(&mutex); } + void unlock() { LeaveCriticalSection(&mutex); } + + Win32_Mutex() { InitializeCriticalSection(&mutex); } + ~Win32_Mutex() { DeleteCriticalSection(&mutex); } + private: + CRITICAL_SECTION mutex; + }; + + return new Win32_Mutex(); + } + +} diff --git a/src/mutex/win32_crit_section/mux_win32.h b/src/mutex/win32_crit_section/mux_win32.h new file mode 100644 index 000000000..9073b0d3c --- /dev/null +++ b/src/mutex/win32_crit_section/mux_win32.h @@ -0,0 +1,24 @@ +/************************************************* +* Win32 Mutex Header File * +* (C) 2006 Luca Piccarreta * +* 2006-2007 Jack Lloyd * +*************************************************/ + +#ifndef BOTAN_MUTEX_WIN32_H__ +#define BOTAN_MUTEX_WIN32_H__ + +#include + +namespace Botan { + +/************************************************* +* Win32 Mutex Factory * +*************************************************/ +class BOTAN_DLL Win32_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; +} + +#endif -- cgit v1.2.3