From 99e8c1a20700631103ec20386f8080eeee4df588 Mon Sep 17 00:00:00 2001 From: lloyd Date: Wed, 1 Apr 2009 15:43:27 +0000 Subject: Remove the mutex classes in favor of C++0x's std::mutex and std::lock_guard --- Attic/mutex.h | 56 +++++++++++++++++++++++++++ Attic/mutex/noop_mutex/info.txt | 10 +++++ Attic/mutex/noop_mutex/mux_noop.cpp | 50 ++++++++++++++++++++++++ Attic/mutex/noop_mutex/mux_noop.h | 26 +++++++++++++ Attic/mutex/pthreads/info.txt | 29 ++++++++++++++ Attic/mutex/pthreads/mux_pthr.cpp | 58 ++++++++++++++++++++++++++++ Attic/mutex/pthreads/mux_pthr.h | 26 +++++++++++++ Attic/mutex/qt_mutex/info.txt | 18 +++++++++ Attic/mutex/qt_mutex/mux_qt.cpp | 35 +++++++++++++++++ Attic/mutex/qt_mutex/mux_qt.h | 27 +++++++++++++ Attic/mutex/win32_crit_section/info.txt | 17 ++++++++ Attic/mutex/win32_crit_section/mux_win32.cpp | 34 ++++++++++++++++ Attic/mutex/win32_crit_section/mux_win32.h | 26 +++++++++++++ 13 files changed, 412 insertions(+) create mode 100644 Attic/mutex.h create mode 100644 Attic/mutex/noop_mutex/info.txt create mode 100644 Attic/mutex/noop_mutex/mux_noop.cpp create mode 100644 Attic/mutex/noop_mutex/mux_noop.h create mode 100644 Attic/mutex/pthreads/info.txt create mode 100644 Attic/mutex/pthreads/mux_pthr.cpp create mode 100644 Attic/mutex/pthreads/mux_pthr.h create mode 100644 Attic/mutex/qt_mutex/info.txt create mode 100644 Attic/mutex/qt_mutex/mux_qt.cpp create mode 100644 Attic/mutex/qt_mutex/mux_qt.h create mode 100644 Attic/mutex/win32_crit_section/info.txt create mode 100644 Attic/mutex/win32_crit_section/mux_win32.cpp create mode 100644 Attic/mutex/win32_crit_section/mux_win32.h (limited to 'Attic') diff --git a/Attic/mutex.h b/Attic/mutex.h new file mode 100644 index 000000000..a04ff83c9 --- /dev/null +++ b/Attic/mutex.h @@ -0,0 +1,56 @@ +/* +* Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_H__ +#define BOTAN_MUTEX_H__ + +#include + +namespace Botan { + +/* +* Mutex Base Class +*/ +class BOTAN_DLL Mutex + { + public: + virtual void lock() = 0; + virtual void unlock() = 0; + virtual ~Mutex() {} + }; + +/* +* Mutex Factory +*/ +class BOTAN_DLL Mutex_Factory + { + public: + virtual Mutex* make() = 0; + virtual ~Mutex_Factory() {} + }; + +/* +* Mutex Holding Class +*/ +class BOTAN_DLL Mutex_Holder + { + public: + Mutex_Holder(Mutex* m) : mux(m) + { + if(!mux) + throw Invalid_Argument("Mutex_Holder: Argument was NULL"); + mux->lock(); + } + + ~Mutex_Holder() { mux->unlock(); } + private: + Mutex* mux; + }; + +} + +#endif diff --git a/Attic/mutex/noop_mutex/info.txt b/Attic/mutex/noop_mutex/info.txt new file mode 100644 index 000000000..1f49f5e1c --- /dev/null +++ b/Attic/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/Attic/mutex/noop_mutex/mux_noop.cpp b/Attic/mutex/noop_mutex/mux_noop.cpp new file mode 100644 index 000000000..5c45084fe --- /dev/null +++ b/Attic/mutex/noop_mutex/mux_noop.cpp @@ -0,0 +1,50 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/noop_mutex/mux_noop.h b/Attic/mutex/noop_mutex/mux_noop.h new file mode 100644 index 000000000..94201cb7c --- /dev/null +++ b/Attic/mutex/noop_mutex/mux_noop.h @@ -0,0 +1,26 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/pthreads/info.txt b/Attic/mutex/pthreads/info.txt new file mode 100644 index 000000000..88de70de0 --- /dev/null +++ b/Attic/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/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 +#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/Attic/mutex/pthreads/mux_pthr.h b/Attic/mutex/pthreads/mux_pthr.h new file mode 100644 index 000000000..118853947 --- /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 + +namespace Botan { + +/* +* Pthread Mutex Factory +*/ +class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/Attic/mutex/qt_mutex/info.txt b/Attic/mutex/qt_mutex/info.txt new file mode 100644 index 000000000..a21108c79 --- /dev/null +++ b/Attic/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/Attic/mutex/qt_mutex/mux_qt.cpp b/Attic/mutex/qt_mutex/mux_qt.cpp new file mode 100644 index 000000000..0f670c8b4 --- /dev/null +++ b/Attic/mutex/qt_mutex/mux_qt.cpp @@ -0,0 +1,35 @@ +/* +* Qt Thread Mutex +* (C) 2004-2007 Justin Karneges +* 2004-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/qt_mutex/mux_qt.h b/Attic/mutex/qt_mutex/mux_qt.h new file mode 100644 index 000000000..5aed77f4b --- /dev/null +++ b/Attic/mutex/qt_mutex/mux_qt.h @@ -0,0 +1,27 @@ +/* +* Qt Mutex +* (C) 2004-2007 Justin Karneges +* 2004-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/win32_crit_section/info.txt b/Attic/mutex/win32_crit_section/info.txt new file mode 100644 index 000000000..a2d339c3b --- /dev/null +++ b/Attic/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/Attic/mutex/win32_crit_section/mux_win32.cpp b/Attic/mutex/win32_crit_section/mux_win32.cpp new file mode 100644 index 000000000..2a967892b --- /dev/null +++ b/Attic/mutex/win32_crit_section/mux_win32.cpp @@ -0,0 +1,34 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/win32_crit_section/mux_win32.h b/Attic/mutex/win32_crit_section/mux_win32.h new file mode 100644 index 000000000..a91850e71 --- /dev/null +++ b/Attic/mutex/win32_crit_section/mux_win32.h @@ -0,0 +1,26 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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 From 7f715b77711f55d9e30f232ff32001fe9e375a56 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 3 Jul 2009 04:45:58 +0000 Subject: Move mutex from Attic to src to deal with merge conflict --- Attic/mutex/noop_mutex/info.txt | 10 ----- Attic/mutex/noop_mutex/mux_noop.cpp | 50 ------------------------ Attic/mutex/noop_mutex/mux_noop.h | 26 ------------- Attic/mutex/pthreads/info.txt | 29 -------------- Attic/mutex/pthreads/mux_pthr.cpp | 58 ---------------------------- Attic/mutex/pthreads/mux_pthr.h | 26 ------------- Attic/mutex/qt_mutex/info.txt | 18 --------- Attic/mutex/qt_mutex/mux_qt.cpp | 35 ----------------- Attic/mutex/qt_mutex/mux_qt.h | 27 ------------- Attic/mutex/win32_crit_section/info.txt | 17 -------- Attic/mutex/win32_crit_section/mux_win32.cpp | 34 ---------------- Attic/mutex/win32_crit_section/mux_win32.h | 26 ------------- src/mutex/noop_mutex/info.txt | 10 +++++ src/mutex/noop_mutex/mux_noop.cpp | 50 ++++++++++++++++++++++++ src/mutex/noop_mutex/mux_noop.h | 26 +++++++++++++ src/mutex/pthreads/info.txt | 29 ++++++++++++++ src/mutex/pthreads/mux_pthr.cpp | 58 ++++++++++++++++++++++++++++ src/mutex/pthreads/mux_pthr.h | 26 +++++++++++++ src/mutex/qt_mutex/info.txt | 18 +++++++++ src/mutex/qt_mutex/mux_qt.cpp | 35 +++++++++++++++++ src/mutex/qt_mutex/mux_qt.h | 27 +++++++++++++ src/mutex/win32_crit_section/info.txt | 17 ++++++++ src/mutex/win32_crit_section/mux_win32.cpp | 34 ++++++++++++++++ src/mutex/win32_crit_section/mux_win32.h | 26 +++++++++++++ 24 files changed, 356 insertions(+), 356 deletions(-) delete mode 100644 Attic/mutex/noop_mutex/info.txt delete mode 100644 Attic/mutex/noop_mutex/mux_noop.cpp delete mode 100644 Attic/mutex/noop_mutex/mux_noop.h delete mode 100644 Attic/mutex/pthreads/info.txt delete mode 100644 Attic/mutex/pthreads/mux_pthr.cpp delete mode 100644 Attic/mutex/pthreads/mux_pthr.h delete mode 100644 Attic/mutex/qt_mutex/info.txt delete mode 100644 Attic/mutex/qt_mutex/mux_qt.cpp delete mode 100644 Attic/mutex/qt_mutex/mux_qt.h delete mode 100644 Attic/mutex/win32_crit_section/info.txt delete mode 100644 Attic/mutex/win32_crit_section/mux_win32.cpp delete mode 100644 Attic/mutex/win32_crit_section/mux_win32.h 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 'Attic') diff --git a/Attic/mutex/noop_mutex/info.txt b/Attic/mutex/noop_mutex/info.txt deleted file mode 100644 index 1f49f5e1c..000000000 --- a/Attic/mutex/noop_mutex/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -realname "No-Op Mutex" - -load_on auto - -define MUTEX_NOOP - - -mux_noop.cpp -mux_noop.h - diff --git a/Attic/mutex/noop_mutex/mux_noop.cpp b/Attic/mutex/noop_mutex/mux_noop.cpp deleted file mode 100644 index 5c45084fe..000000000 --- a/Attic/mutex/noop_mutex/mux_noop.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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/Attic/mutex/noop_mutex/mux_noop.h b/Attic/mutex/noop_mutex/mux_noop.h deleted file mode 100644 index 94201cb7c..000000000 --- a/Attic/mutex/noop_mutex/mux_noop.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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/Attic/mutex/pthreads/info.txt b/Attic/mutex/pthreads/info.txt deleted file mode 100644 index 88de70de0..000000000 --- a/Attic/mutex/pthreads/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -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/Attic/mutex/pthreads/mux_pthr.cpp b/Attic/mutex/pthreads/mux_pthr.cpp deleted file mode 100644 index 9f1d9816e..000000000 --- a/Attic/mutex/pthreads/mux_pthr.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Pthread Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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/Attic/mutex/pthreads/mux_pthr.h b/Attic/mutex/pthreads/mux_pthr.h deleted file mode 100644 index 118853947..000000000 --- a/Attic/mutex/pthreads/mux_pthr.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -namespace Botan { - -/* -* Pthread Mutex Factory -*/ -class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory - { - public: - Mutex* make(); - }; - -} - -#endif diff --git a/Attic/mutex/qt_mutex/info.txt b/Attic/mutex/qt_mutex/info.txt deleted file mode 100644 index a21108c79..000000000 --- a/Attic/mutex/qt_mutex/info.txt +++ /dev/null @@ -1,18 +0,0 @@ -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/Attic/mutex/qt_mutex/mux_qt.cpp b/Attic/mutex/qt_mutex/mux_qt.cpp deleted file mode 100644 index 0f670c8b4..000000000 --- a/Attic/mutex/qt_mutex/mux_qt.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Qt Thread Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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/Attic/mutex/qt_mutex/mux_qt.h b/Attic/mutex/qt_mutex/mux_qt.h deleted file mode 100644 index 5aed77f4b..000000000 --- a/Attic/mutex/qt_mutex/mux_qt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Qt Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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/Attic/mutex/win32_crit_section/info.txt b/Attic/mutex/win32_crit_section/info.txt deleted file mode 100644 index a2d339c3b..000000000 --- a/Attic/mutex/win32_crit_section/info.txt +++ /dev/null @@ -1,17 +0,0 @@ -realname "Win32 Mutex" - -define MUTEX_WIN32 -modset win32 - -load_on auto - - -mux_win32.cpp -mux_win32.h - - - -cygwin -windows -mingw - diff --git a/Attic/mutex/win32_crit_section/mux_win32.cpp b/Attic/mutex/win32_crit_section/mux_win32.cpp deleted file mode 100644 index 2a967892b..000000000 --- a/Attic/mutex/win32_crit_section/mux_win32.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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/Attic/mutex/win32_crit_section/mux_win32.h b/Attic/mutex/win32_crit_section/mux_win32.h deleted file mode 100644 index a91850e71..000000000 --- a/Attic/mutex/win32_crit_section/mux_win32.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 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..5c45084fe --- /dev/null +++ b/src/mutex/noop_mutex/mux_noop.cpp @@ -0,0 +1,50 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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..94201cb7c --- /dev/null +++ b/src/mutex/noop_mutex/mux_noop.h @@ -0,0 +1,26 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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..9f1d9816e --- /dev/null +++ b/src/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 +#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..118853947 --- /dev/null +++ b/src/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 + +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..0f670c8b4 --- /dev/null +++ b/src/mutex/qt_mutex/mux_qt.cpp @@ -0,0 +1,35 @@ +/* +* Qt Thread Mutex +* (C) 2004-2007 Justin Karneges +* 2004-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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..5aed77f4b --- /dev/null +++ b/src/mutex/qt_mutex/mux_qt.h @@ -0,0 +1,27 @@ +/* +* Qt Mutex +* (C) 2004-2007 Justin Karneges +* 2004-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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..2a967892b --- /dev/null +++ b/src/mutex/win32_crit_section/mux_win32.cpp @@ -0,0 +1,34 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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..a91850e71 --- /dev/null +++ b/src/mutex/win32_crit_section/mux_win32.h @@ -0,0 +1,26 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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 From ce5cab439b617800f48c94ebaeeb7cd3bd786cfe Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 3 Jul 2009 04:46:44 +0000 Subject: Move mutex.h to src/mutex (from Attic) --- Attic/mutex.h | 56 ------------------------------------------------------- src/mutex/mutex.h | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 Attic/mutex.h create mode 100644 src/mutex/mutex.h (limited to 'Attic') diff --git a/Attic/mutex.h b/Attic/mutex.h deleted file mode 100644 index a04ff83c9..000000000 --- a/Attic/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MUTEX_H__ -#define BOTAN_MUTEX_H__ - -#include - -namespace Botan { - -/* -* Mutex Base Class -*/ -class BOTAN_DLL Mutex - { - public: - virtual void lock() = 0; - virtual void unlock() = 0; - virtual ~Mutex() {} - }; - -/* -* Mutex Factory -*/ -class BOTAN_DLL Mutex_Factory - { - public: - virtual Mutex* make() = 0; - virtual ~Mutex_Factory() {} - }; - -/* -* Mutex Holding Class -*/ -class BOTAN_DLL Mutex_Holder - { - public: - Mutex_Holder(Mutex* m) : mux(m) - { - if(!mux) - throw Invalid_Argument("Mutex_Holder: Argument was NULL"); - mux->lock(); - } - - ~Mutex_Holder() { mux->unlock(); } - private: - Mutex* mux; - }; - -} - -#endif diff --git a/src/mutex/mutex.h b/src/mutex/mutex.h new file mode 100644 index 000000000..a04ff83c9 --- /dev/null +++ b/src/mutex/mutex.h @@ -0,0 +1,56 @@ +/* +* Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_H__ +#define BOTAN_MUTEX_H__ + +#include + +namespace Botan { + +/* +* Mutex Base Class +*/ +class BOTAN_DLL Mutex + { + public: + virtual void lock() = 0; + virtual void unlock() = 0; + virtual ~Mutex() {} + }; + +/* +* Mutex Factory +*/ +class BOTAN_DLL Mutex_Factory + { + public: + virtual Mutex* make() = 0; + virtual ~Mutex_Factory() {} + }; + +/* +* Mutex Holding Class +*/ +class BOTAN_DLL Mutex_Holder + { + public: + Mutex_Holder(Mutex* m) : mux(m) + { + if(!mux) + throw Invalid_Argument("Mutex_Holder: Argument was NULL"); + mux->lock(); + } + + ~Mutex_Holder() { mux->unlock(); } + private: + Mutex* mux; + }; + +} + +#endif -- cgit v1.2.3 From b438a3c6d08893ca77a1d18baef1b02e955eccf8 Mon Sep 17 00:00:00 2001 From: lloyd Date: Fri, 3 Jul 2009 04:47:49 +0000 Subject: Move mutex directory back to the Attic --- Attic/mutex/info.txt | 9 +++++ Attic/mutex/mutex.h | 56 +++++++++++++++++++++++++++ Attic/mutex/noop_mutex/info.txt | 10 +++++ Attic/mutex/noop_mutex/mux_noop.cpp | 50 ++++++++++++++++++++++++ Attic/mutex/noop_mutex/mux_noop.h | 26 +++++++++++++ Attic/mutex/pthreads/info.txt | 29 ++++++++++++++ Attic/mutex/pthreads/mux_pthr.cpp | 58 ++++++++++++++++++++++++++++ Attic/mutex/pthreads/mux_pthr.h | 26 +++++++++++++ Attic/mutex/qt_mutex/info.txt | 18 +++++++++ Attic/mutex/qt_mutex/mux_qt.cpp | 35 +++++++++++++++++ Attic/mutex/qt_mutex/mux_qt.h | 27 +++++++++++++ Attic/mutex/win32_crit_section/info.txt | 17 ++++++++ Attic/mutex/win32_crit_section/mux_win32.cpp | 34 ++++++++++++++++ Attic/mutex/win32_crit_section/mux_win32.h | 26 +++++++++++++ src/mutex/info.txt | 9 ----- src/mutex/mutex.h | 56 --------------------------- src/mutex/noop_mutex/info.txt | 10 ----- src/mutex/noop_mutex/mux_noop.cpp | 50 ------------------------ src/mutex/noop_mutex/mux_noop.h | 26 ------------- src/mutex/pthreads/info.txt | 29 -------------- src/mutex/pthreads/mux_pthr.cpp | 58 ---------------------------- src/mutex/pthreads/mux_pthr.h | 26 ------------- src/mutex/qt_mutex/info.txt | 18 --------- src/mutex/qt_mutex/mux_qt.cpp | 35 ----------------- src/mutex/qt_mutex/mux_qt.h | 27 ------------- src/mutex/win32_crit_section/info.txt | 17 -------- src/mutex/win32_crit_section/mux_win32.cpp | 34 ---------------- src/mutex/win32_crit_section/mux_win32.h | 26 ------------- 28 files changed, 421 insertions(+), 421 deletions(-) create mode 100644 Attic/mutex/info.txt create mode 100644 Attic/mutex/mutex.h create mode 100644 Attic/mutex/noop_mutex/info.txt create mode 100644 Attic/mutex/noop_mutex/mux_noop.cpp create mode 100644 Attic/mutex/noop_mutex/mux_noop.h create mode 100644 Attic/mutex/pthreads/info.txt create mode 100644 Attic/mutex/pthreads/mux_pthr.cpp create mode 100644 Attic/mutex/pthreads/mux_pthr.h create mode 100644 Attic/mutex/qt_mutex/info.txt create mode 100644 Attic/mutex/qt_mutex/mux_qt.cpp create mode 100644 Attic/mutex/qt_mutex/mux_qt.h create mode 100644 Attic/mutex/win32_crit_section/info.txt create mode 100644 Attic/mutex/win32_crit_section/mux_win32.cpp create mode 100644 Attic/mutex/win32_crit_section/mux_win32.h delete mode 100644 src/mutex/info.txt delete mode 100644 src/mutex/mutex.h delete mode 100644 src/mutex/noop_mutex/info.txt delete mode 100644 src/mutex/noop_mutex/mux_noop.cpp delete mode 100644 src/mutex/noop_mutex/mux_noop.h delete mode 100644 src/mutex/pthreads/info.txt delete mode 100644 src/mutex/pthreads/mux_pthr.cpp delete mode 100644 src/mutex/pthreads/mux_pthr.h delete mode 100644 src/mutex/qt_mutex/info.txt delete mode 100644 src/mutex/qt_mutex/mux_qt.cpp delete mode 100644 src/mutex/qt_mutex/mux_qt.h delete mode 100644 src/mutex/win32_crit_section/info.txt delete mode 100644 src/mutex/win32_crit_section/mux_win32.cpp delete mode 100644 src/mutex/win32_crit_section/mux_win32.h (limited to 'Attic') diff --git a/Attic/mutex/info.txt b/Attic/mutex/info.txt new file mode 100644 index 000000000..ff79bf753 --- /dev/null +++ b/Attic/mutex/info.txt @@ -0,0 +1,9 @@ +realname "Mutex Wrappers" + +define MUTEX_WRAPPERS + +load_on auto + + +mutex.h + diff --git a/Attic/mutex/mutex.h b/Attic/mutex/mutex.h new file mode 100644 index 000000000..a04ff83c9 --- /dev/null +++ b/Attic/mutex/mutex.h @@ -0,0 +1,56 @@ +/* +* Mutex +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_MUTEX_H__ +#define BOTAN_MUTEX_H__ + +#include + +namespace Botan { + +/* +* Mutex Base Class +*/ +class BOTAN_DLL Mutex + { + public: + virtual void lock() = 0; + virtual void unlock() = 0; + virtual ~Mutex() {} + }; + +/* +* Mutex Factory +*/ +class BOTAN_DLL Mutex_Factory + { + public: + virtual Mutex* make() = 0; + virtual ~Mutex_Factory() {} + }; + +/* +* Mutex Holding Class +*/ +class BOTAN_DLL Mutex_Holder + { + public: + Mutex_Holder(Mutex* m) : mux(m) + { + if(!mux) + throw Invalid_Argument("Mutex_Holder: Argument was NULL"); + mux->lock(); + } + + ~Mutex_Holder() { mux->unlock(); } + private: + Mutex* mux; + }; + +} + +#endif diff --git a/Attic/mutex/noop_mutex/info.txt b/Attic/mutex/noop_mutex/info.txt new file mode 100644 index 000000000..1f49f5e1c --- /dev/null +++ b/Attic/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/Attic/mutex/noop_mutex/mux_noop.cpp b/Attic/mutex/noop_mutex/mux_noop.cpp new file mode 100644 index 000000000..5c45084fe --- /dev/null +++ b/Attic/mutex/noop_mutex/mux_noop.cpp @@ -0,0 +1,50 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/noop_mutex/mux_noop.h b/Attic/mutex/noop_mutex/mux_noop.h new file mode 100644 index 000000000..94201cb7c --- /dev/null +++ b/Attic/mutex/noop_mutex/mux_noop.h @@ -0,0 +1,26 @@ +/* +* No-Op Mutex Factory +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/pthreads/info.txt b/Attic/mutex/pthreads/info.txt new file mode 100644 index 000000000..88de70de0 --- /dev/null +++ b/Attic/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/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 +#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/Attic/mutex/pthreads/mux_pthr.h b/Attic/mutex/pthreads/mux_pthr.h new file mode 100644 index 000000000..118853947 --- /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 + +namespace Botan { + +/* +* Pthread Mutex Factory +*/ +class BOTAN_DLL Pthread_Mutex_Factory : public Mutex_Factory + { + public: + Mutex* make(); + }; + +} + +#endif diff --git a/Attic/mutex/qt_mutex/info.txt b/Attic/mutex/qt_mutex/info.txt new file mode 100644 index 000000000..a21108c79 --- /dev/null +++ b/Attic/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/Attic/mutex/qt_mutex/mux_qt.cpp b/Attic/mutex/qt_mutex/mux_qt.cpp new file mode 100644 index 000000000..0f670c8b4 --- /dev/null +++ b/Attic/mutex/qt_mutex/mux_qt.cpp @@ -0,0 +1,35 @@ +/* +* Qt Thread Mutex +* (C) 2004-2007 Justin Karneges +* 2004-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/qt_mutex/mux_qt.h b/Attic/mutex/qt_mutex/mux_qt.h new file mode 100644 index 000000000..5aed77f4b --- /dev/null +++ b/Attic/mutex/qt_mutex/mux_qt.h @@ -0,0 +1,27 @@ +/* +* Qt Mutex +* (C) 2004-2007 Justin Karneges +* 2004-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/win32_crit_section/info.txt b/Attic/mutex/win32_crit_section/info.txt new file mode 100644 index 000000000..a2d339c3b --- /dev/null +++ b/Attic/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/Attic/mutex/win32_crit_section/mux_win32.cpp b/Attic/mutex/win32_crit_section/mux_win32.cpp new file mode 100644 index 000000000..2a967892b --- /dev/null +++ b/Attic/mutex/win32_crit_section/mux_win32.cpp @@ -0,0 +1,34 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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/Attic/mutex/win32_crit_section/mux_win32.h b/Attic/mutex/win32_crit_section/mux_win32.h new file mode 100644 index 000000000..a91850e71 --- /dev/null +++ b/Attic/mutex/win32_crit_section/mux_win32.h @@ -0,0 +1,26 @@ +/* +* Win32 Mutex +* (C) 2006 Luca Piccarreta +* 2006-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#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 diff --git a/src/mutex/info.txt b/src/mutex/info.txt deleted file mode 100644 index ff79bf753..000000000 --- a/src/mutex/info.txt +++ /dev/null @@ -1,9 +0,0 @@ -realname "Mutex Wrappers" - -define MUTEX_WRAPPERS - -load_on auto - - -mutex.h - diff --git a/src/mutex/mutex.h b/src/mutex/mutex.h deleted file mode 100644 index a04ff83c9..000000000 --- a/src/mutex/mutex.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -* Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_MUTEX_H__ -#define BOTAN_MUTEX_H__ - -#include - -namespace Botan { - -/* -* Mutex Base Class -*/ -class BOTAN_DLL Mutex - { - public: - virtual void lock() = 0; - virtual void unlock() = 0; - virtual ~Mutex() {} - }; - -/* -* Mutex Factory -*/ -class BOTAN_DLL Mutex_Factory - { - public: - virtual Mutex* make() = 0; - virtual ~Mutex_Factory() {} - }; - -/* -* Mutex Holding Class -*/ -class BOTAN_DLL Mutex_Holder - { - public: - Mutex_Holder(Mutex* m) : mux(m) - { - if(!mux) - throw Invalid_Argument("Mutex_Holder: Argument was NULL"); - mux->lock(); - } - - ~Mutex_Holder() { mux->unlock(); } - private: - Mutex* mux; - }; - -} - -#endif diff --git a/src/mutex/noop_mutex/info.txt b/src/mutex/noop_mutex/info.txt deleted file mode 100644 index 1f49f5e1c..000000000 --- a/src/mutex/noop_mutex/info.txt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 5c45084fe..000000000 --- a/src/mutex/noop_mutex/mux_noop.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 deleted file mode 100644 index 94201cb7c..000000000 --- a/src/mutex/noop_mutex/mux_noop.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* No-Op Mutex Factory -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 deleted file mode 100644 index 88de70de0..000000000 --- a/src/mutex/pthreads/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 9f1d9816e..000000000 --- a/src/mutex/pthreads/mux_pthr.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* -* Pthread Mutex -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 deleted file mode 100644 index 118853947..000000000 --- a/src/mutex/pthreads/mux_pthr.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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 - -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 deleted file mode 100644 index a21108c79..000000000 --- a/src/mutex/qt_mutex/info.txt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 0f670c8b4..000000000 --- a/src/mutex/qt_mutex/mux_qt.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* -* Qt Thread Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 deleted file mode 100644 index 5aed77f4b..000000000 --- a/src/mutex/qt_mutex/mux_qt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Qt Mutex -* (C) 2004-2007 Justin Karneges -* 2004-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 deleted file mode 100644 index a2d339c3b..000000000 --- a/src/mutex/win32_crit_section/info.txt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 2a967892b..000000000 --- a/src/mutex/win32_crit_section/mux_win32.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 deleted file mode 100644 index a91850e71..000000000 --- a/src/mutex/win32_crit_section/mux_win32.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -* Win32 Mutex -* (C) 2006 Luca Piccarreta -* 2006-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#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 From 92f31b22dfe2aa1b2bde84cbaf4ce7365fa4ec68 Mon Sep 17 00:00:00 2001 From: lloyd Date: Tue, 13 Oct 2009 21:27:28 +0000 Subject: Attic-ize all of src/timer, except for time_t_to_tm and system_time (which will go later) which will live in the new time.h --- Attic/timer/cpu_counter/info.txt | 36 +++++++++++++++ Attic/timer/cpu_counter/tm_hard.cpp | 51 +++++++++++++++++++++ Attic/timer/cpu_counter/tm_hard.h | 33 ++++++++++++++ Attic/timer/gettimeofday/info.txt | 33 ++++++++++++++ Attic/timer/gettimeofday/tm_unix.cpp | 23 ++++++++++ Attic/timer/gettimeofday/tm_unix.h | 27 +++++++++++ Attic/timer/info.txt | 14 ++++++ Attic/timer/posix_rt/info.txt | 29 ++++++++++++ Attic/timer/posix_rt/tm_posix.cpp | 32 ++++++++++++++ Attic/timer/posix_rt/tm_posix.h | 27 +++++++++++ Attic/timer/timer.cpp | 64 +++++++++++++++++++++++++++ Attic/timer/timer.h | 53 ++++++++++++++++++++++ Attic/timer/win32_query_perf_ctr/info.txt | 26 +++++++++++ Attic/timer/win32_query_perf_ctr/tm_win32.cpp | 23 ++++++++++ Attic/timer/win32_query_perf_ctr/tm_win32.h | 27 +++++++++++ checks/cvc_tests.cpp | 2 +- src/asn1/asn1_tm.cpp | 2 +- src/cert/cvc/asn1_eac_tm.cpp | 2 +- src/cert/cvc/cvc_self.cpp | 2 +- src/cert/x509/crl_ent.cpp | 2 +- src/cert/x509/x509_ca.cpp | 2 +- src/cert/x509/x509opt.cpp | 2 +- src/cert/x509/x509stor.cpp | 2 +- src/rng/auto_rng/info.txt | 1 - src/timer/cpu_counter/info.txt | 36 --------------- src/timer/cpu_counter/tm_hard.cpp | 51 --------------------- src/timer/cpu_counter/tm_hard.h | 33 -------------- src/timer/gettimeofday/info.txt | 33 -------------- src/timer/gettimeofday/tm_unix.cpp | 23 ---------- src/timer/gettimeofday/tm_unix.h | 27 ----------- src/timer/info.txt | 14 ------ src/timer/posix_rt/info.txt | 29 ------------ src/timer/posix_rt/tm_posix.cpp | 32 -------------- src/timer/posix_rt/tm_posix.h | 27 ----------- src/timer/timer.cpp | 64 --------------------------- src/timer/timer.h | 53 ---------------------- src/timer/win32_query_perf_ctr/info.txt | 26 ----------- src/timer/win32_query_perf_ctr/tm_win32.cpp | 23 ---------- src/timer/win32_query_perf_ctr/tm_win32.h | 27 ----------- src/utils/time.h | 39 ++++++++++++++++ 40 files changed, 545 insertions(+), 507 deletions(-) create mode 100644 Attic/timer/cpu_counter/info.txt create mode 100644 Attic/timer/cpu_counter/tm_hard.cpp create mode 100644 Attic/timer/cpu_counter/tm_hard.h create mode 100644 Attic/timer/gettimeofday/info.txt create mode 100644 Attic/timer/gettimeofday/tm_unix.cpp create mode 100644 Attic/timer/gettimeofday/tm_unix.h create mode 100644 Attic/timer/info.txt create mode 100644 Attic/timer/posix_rt/info.txt create mode 100644 Attic/timer/posix_rt/tm_posix.cpp create mode 100644 Attic/timer/posix_rt/tm_posix.h create mode 100644 Attic/timer/timer.cpp create mode 100644 Attic/timer/timer.h create mode 100644 Attic/timer/win32_query_perf_ctr/info.txt create mode 100644 Attic/timer/win32_query_perf_ctr/tm_win32.cpp create mode 100644 Attic/timer/win32_query_perf_ctr/tm_win32.h delete mode 100644 src/timer/cpu_counter/info.txt delete mode 100644 src/timer/cpu_counter/tm_hard.cpp delete mode 100644 src/timer/cpu_counter/tm_hard.h delete mode 100644 src/timer/gettimeofday/info.txt delete mode 100644 src/timer/gettimeofday/tm_unix.cpp delete mode 100644 src/timer/gettimeofday/tm_unix.h delete mode 100644 src/timer/info.txt delete mode 100644 src/timer/posix_rt/info.txt delete mode 100644 src/timer/posix_rt/tm_posix.cpp delete mode 100644 src/timer/posix_rt/tm_posix.h delete mode 100644 src/timer/timer.cpp delete mode 100644 src/timer/timer.h delete mode 100644 src/timer/win32_query_perf_ctr/info.txt delete mode 100644 src/timer/win32_query_perf_ctr/tm_win32.cpp delete mode 100644 src/timer/win32_query_perf_ctr/tm_win32.h create mode 100644 src/utils/time.h (limited to 'Attic') diff --git a/Attic/timer/cpu_counter/info.txt b/Attic/timer/cpu_counter/info.txt new file mode 100644 index 000000000..025663a84 --- /dev/null +++ b/Attic/timer/cpu_counter/info.txt @@ -0,0 +1,36 @@ +realname "Hardware Timer" + +define TIMER_HARDWARE + +load_on asm_ok + + +tm_hard.cpp +tm_hard.h + + + +gcc + + + +# RDTSC: Pentium and up +i586 +i686 +athlon +pentium4 +pentium-m +amd64 + +ppc # PPC timebase register +ppc64 # PPC timebase register +alpha # rpcc +sparc64 # %tick register +ia64 # ar.itc +s390x +hppa + + + +timer + diff --git a/Attic/timer/cpu_counter/tm_hard.cpp b/Attic/timer/cpu_counter/tm_hard.cpp new file mode 100644 index 000000000..9e31aee39 --- /dev/null +++ b/Attic/timer/cpu_counter/tm_hard.cpp @@ -0,0 +1,51 @@ +/* +* Hardware Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include + +namespace Botan { + +/* +* Get the timestamp +*/ +u64bit Hardware_Timer::clock() const + { + u64bit rtc = 0; + +#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64) + u32bit rtc_low = 0, rtc_high = 0; + asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); + rtc = (static_cast(rtc_high) << 32) | rtc_low; + +#elif defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64) + u32bit rtc_low = 0, rtc_high = 0; + asm volatile("mftbu %0; mftb %1" : "=r" (rtc_high), "=r" (rtc_low)); + rtc = (static_cast(rtc_high) << 32) | rtc_low; + +#elif defined(BOTAN_TARGET_ARCH_IS_ALPHA) + asm volatile("rpcc %0" : "=r" (rtc)); + +#elif defined(BOTAN_TARGET_ARCH_IS_SPARC64) + asm volatile("rd %%tick, %0" : "=r" (rtc)); + +#elif defined(BOTAN_TARGET_ARCH_IS_IA64) + asm volatile("mov %0=ar.itc" : "=r" (rtc)); + +#elif defined(BOTAN_TARGET_ARCH_IS_S390X) + asm volatile("stck 0(%0)" : : "a" (&rtc) : "memory", "cc"); + +#elif defined(BOTAN_TARGET_ARCH_IS_HPPA) + asm volatile("mfctl 16,%0" : "=r" (rtc)); // 64-bit only? + +#else + #error "Unsure how to access hardware timer on this system" +#endif + + return rtc; + } + +} diff --git a/Attic/timer/cpu_counter/tm_hard.h b/Attic/timer/cpu_counter/tm_hard.h new file mode 100644 index 000000000..2e338eca8 --- /dev/null +++ b/Attic/timer/cpu_counter/tm_hard.h @@ -0,0 +1,33 @@ +/* +* Hardware Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_HARDWARE_H__ +#define BOTAN_TIMER_HARDWARE_H__ + +#include + +namespace Botan { + +/* +* Hardware Timer +*/ +class BOTAN_DLL Hardware_Timer : public Timer + { + public: + /* + @todo: Add sync(Timer& wall_clock, bool milliseconds) which busy + loops using wall_clock and tries to guess the tick rate of the + hardware counter, allowing it to be used for benchmarks, etc + */ + + std::string name() const { return "Hardware Timer"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/Attic/timer/gettimeofday/info.txt b/Attic/timer/gettimeofday/info.txt new file mode 100644 index 000000000..a58e8088d --- /dev/null +++ b/Attic/timer/gettimeofday/info.txt @@ -0,0 +1,33 @@ +realname "Unix Timer" + +define TIMER_UNIX + +load_on auto +modset unix,beos + + +tm_unix.cpp +tm_unix.h + + + +aix +beos +cygwin +darwin +freebsd +dragonfly +hpux +irix +linux +netbsd +openbsd +qnx +solaris +tru64 + + + +timer + + diff --git a/Attic/timer/gettimeofday/tm_unix.cpp b/Attic/timer/gettimeofday/tm_unix.cpp new file mode 100644 index 000000000..9d8ac4a04 --- /dev/null +++ b/Attic/timer/gettimeofday/tm_unix.cpp @@ -0,0 +1,23 @@ +/* +* Unix Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include + +namespace Botan { + +/* +* Get the timestamp +*/ +u64bit Unix_Timer::clock() const + { + struct ::timeval tv; + ::gettimeofday(&tv, 0); + return combine_timers(tv.tv_sec, tv.tv_usec, 1000000); + } + +} diff --git a/Attic/timer/gettimeofday/tm_unix.h b/Attic/timer/gettimeofday/tm_unix.h new file mode 100644 index 000000000..c304dbb5c --- /dev/null +++ b/Attic/timer/gettimeofday/tm_unix.h @@ -0,0 +1,27 @@ +/* +* Unix Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_UNIX_H__ +#define BOTAN_TIMER_UNIX_H__ + +#include + +namespace Botan { + +/* +* Unix Timer +*/ +class BOTAN_DLL Unix_Timer : public Timer + { + public: + std::string name() const { return "Unix gettimeofday"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/Attic/timer/info.txt b/Attic/timer/info.txt new file mode 100644 index 000000000..6408dca45 --- /dev/null +++ b/Attic/timer/info.txt @@ -0,0 +1,14 @@ +realname "Timer Base Class" + +define TIMER + +load_on auto + + +timer.cpp +timer.h + + + +rng + diff --git a/Attic/timer/posix_rt/info.txt b/Attic/timer/posix_rt/info.txt new file mode 100644 index 000000000..fa530ea1a --- /dev/null +++ b/Attic/timer/posix_rt/info.txt @@ -0,0 +1,29 @@ +realname "POSIX Timer" + +define TIMER_POSIX + +load_on auto + + +tm_posix.cpp +tm_posix.h + + + +linux -> rt + + +# The *BSDs put clock_gettime in sys/time.h, not time.h like POSIX says + +cygwin +linux +#freebsd +dragonfly +#netbsd +#openbsd + + + +timer + + diff --git a/Attic/timer/posix_rt/tm_posix.cpp b/Attic/timer/posix_rt/tm_posix.cpp new file mode 100644 index 000000000..96182025c --- /dev/null +++ b/Attic/timer/posix_rt/tm_posix.cpp @@ -0,0 +1,32 @@ +/* +* POSIX Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include + +#ifndef _POSIX_C_SOURCE + #define _POSIX_C_SOURCE 199309 +#endif + +#include + +#ifndef CLOCK_REALTIME + #define CLOCK_REALTIME 0 +#endif + +namespace Botan { + +/* +* Get the timestamp +*/ +u64bit POSIX_Timer::clock() const + { + struct ::timespec tv; + ::clock_gettime(CLOCK_REALTIME, &tv); + return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000); + } + +} diff --git a/Attic/timer/posix_rt/tm_posix.h b/Attic/timer/posix_rt/tm_posix.h new file mode 100644 index 000000000..8bedccfa2 --- /dev/null +++ b/Attic/timer/posix_rt/tm_posix.h @@ -0,0 +1,27 @@ +/* +* POSIX Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_POSIX_H__ +#define BOTAN_TIMER_POSIX_H__ + +#include + +namespace Botan { + +/* +* POSIX Timer +*/ +class BOTAN_DLL POSIX_Timer : public Timer + { + public: + std::string name() const { return "POSIX clock_gettime"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/Attic/timer/timer.cpp b/Attic/timer/timer.cpp new file mode 100644 index 000000000..16d7dc368 --- /dev/null +++ b/Attic/timer/timer.cpp @@ -0,0 +1,64 @@ +/** +* Timestamp Functions +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include +#include + +namespace Botan { + +/** +* Get the system clock +*/ +u64bit system_time() + { + return static_cast(std::time(0)); + } + +/* +* Convert a time_t to a struct tm +*/ +std::tm time_t_to_tm(u64bit timer) + { + std::time_t time_val = static_cast(timer); + + std::tm* tm_p = std::gmtime(&time_val); + if (tm_p == 0) + throw Encoding_Error("time_t_to_tm could not convert"); + return (*tm_p); + } + +/** +* Read the clock and return the output +*/ +void Timer::poll(Entropy_Accumulator& accum) + { + const u64bit clock_value = this->clock(); + accum.add(clock_value, 0); + } + +/** +* Combine a two time values into a single one +*/ +u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) + { + static const u64bit NANOSECONDS_UNITS = 1000000000; + + u64bit res = seconds * NANOSECONDS_UNITS; + res += parts * (NANOSECONDS_UNITS / parts_hz); + return res; + } + +/** +* ANSI Clock +*/ +u64bit ANSI_Clock_Timer::clock() const + { + return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); + } + +} diff --git a/Attic/timer/timer.h b/Attic/timer/timer.h new file mode 100644 index 000000000..603027f6d --- /dev/null +++ b/Attic/timer/timer.h @@ -0,0 +1,53 @@ +/** +* Timestamp Functions +* (C) 1999-2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMERS_H__ +#define BOTAN_TIMERS_H__ + +#include +#include + +namespace Botan { + +/* +* Time Access/Conversion Functions +*/ +BOTAN_DLL u64bit system_time(); + +BOTAN_DLL std::tm time_t_to_tm(u64bit); + +/** +* Timer Interface +*/ +class BOTAN_DLL Timer : public EntropySource + { + public: + /** + @return nanoseconds resolution timestamp, unknown epoch + */ + virtual u64bit clock() const = 0; + + void poll(Entropy_Accumulator& accum); + + virtual ~Timer() {} + protected: + static u64bit combine_timers(u32bit, u32bit, u32bit); + }; + +/** +* ANSI Clock Timer +*/ +class BOTAN_DLL ANSI_Clock_Timer : public Timer + { + public: + std::string name() const { return "ANSI clock"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/Attic/timer/win32_query_perf_ctr/info.txt b/Attic/timer/win32_query_perf_ctr/info.txt new file mode 100644 index 000000000..4bb1ddb34 --- /dev/null +++ b/Attic/timer/win32_query_perf_ctr/info.txt @@ -0,0 +1,26 @@ +realname "Win32 Timer" + +define TIMER_WIN32 +modset win32 + +load_on auto + + +tm_win32.cpp +tm_win32.h + + + +cygwin +windows +mingw + + + +windows -> user32.lib + + + +timer + + diff --git a/Attic/timer/win32_query_perf_ctr/tm_win32.cpp b/Attic/timer/win32_query_perf_ctr/tm_win32.cpp new file mode 100644 index 000000000..6b878e6e2 --- /dev/null +++ b/Attic/timer/win32_query_perf_ctr/tm_win32.cpp @@ -0,0 +1,23 @@ +/* +* Win32 Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include +#include + +namespace Botan { + +/* +* Get the timestamp +*/ +u64bit Win32_Timer::clock() const + { + LARGE_INTEGER tv; + ::QueryPerformanceCounter(&tv); + return tv.QuadPart; + } + +} diff --git a/Attic/timer/win32_query_perf_ctr/tm_win32.h b/Attic/timer/win32_query_perf_ctr/tm_win32.h new file mode 100644 index 000000000..5bcb720ab --- /dev/null +++ b/Attic/timer/win32_query_perf_ctr/tm_win32.h @@ -0,0 +1,27 @@ +/* +* Win32 Timer +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIMER_WIN32_H__ +#define BOTAN_TIMER_WIN32_H__ + +#include + +namespace Botan { + +/* +* Win32 Timer +*/ +class BOTAN_DLL Win32_Timer : public Timer + { + public: + std::string name() const { return "Win32 QueryPerformanceCounter"; } + u64bit clock() const; + }; + +} + +#endif diff --git a/checks/cvc_tests.cpp b/checks/cvc_tests.cpp index 369da4a8c..4b2ffa9a6 100644 --- a/checks/cvc_tests.cpp +++ b/checks/cvc_tests.cpp @@ -27,8 +27,8 @@ #include #include #include -#include #include +#include #define TEST_DATA_DIR "checks/ecc_testdata" diff --git a/src/asn1/asn1_tm.cpp b/src/asn1/asn1_tm.cpp index 09bc4d347..c57d1bc73 100644 --- a/src/asn1/asn1_tm.cpp +++ b/src/asn1/asn1_tm.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/cvc/asn1_eac_tm.cpp b/src/cert/cvc/asn1_eac_tm.cpp index 947b9e66d..f361e6098 100644 --- a/src/cert/cvc/asn1_eac_tm.cpp +++ b/src/cert/cvc/asn1_eac_tm.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/cvc/cvc_self.cpp b/src/cert/cvc/cvc_self.cpp index 46bf145fc..98d90d0af 100644 --- a/src/cert/cvc/cvc_self.cpp +++ b/src/cert/cvc/cvc_self.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include namespace Botan { diff --git a/src/cert/x509/crl_ent.cpp b/src/cert/x509/crl_ent.cpp index a8a989c24..42a742ebb 100644 --- a/src/cert/x509/crl_ent.cpp +++ b/src/cert/x509/crl_ent.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/x509/x509_ca.cpp b/src/cert/x509/x509_ca.cpp index c3ab2a739..4c4748065 100644 --- a/src/cert/x509/x509_ca.cpp +++ b/src/cert/x509/x509_ca.cpp @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/cert/x509/x509opt.cpp b/src/cert/x509/x509opt.cpp index 03bcd20f4..c6421d9ca 100644 --- a/src/cert/x509/x509opt.cpp +++ b/src/cert/x509/x509opt.cpp @@ -8,7 +8,7 @@ #include #include #include -#include +#include namespace Botan { diff --git a/src/cert/x509/x509stor.cpp b/src/cert/x509/x509stor.cpp index 9c6dced25..515215a21 100644 --- a/src/cert/x509/x509stor.cpp +++ b/src/cert/x509/x509stor.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/rng/auto_rng/info.txt b/src/rng/auto_rng/info.txt index 7d5d5ddcc..3c83bfb5e 100644 --- a/src/rng/auto_rng/info.txt +++ b/src/rng/auto_rng/info.txt @@ -12,5 +12,4 @@ auto_rng.cpp hmac sha2 -timer diff --git a/src/timer/cpu_counter/info.txt b/src/timer/cpu_counter/info.txt deleted file mode 100644 index 025663a84..000000000 --- a/src/timer/cpu_counter/info.txt +++ /dev/null @@ -1,36 +0,0 @@ -realname "Hardware Timer" - -define TIMER_HARDWARE - -load_on asm_ok - - -tm_hard.cpp -tm_hard.h - - - -gcc - - - -# RDTSC: Pentium and up -i586 -i686 -athlon -pentium4 -pentium-m -amd64 - -ppc # PPC timebase register -ppc64 # PPC timebase register -alpha # rpcc -sparc64 # %tick register -ia64 # ar.itc -s390x -hppa - - - -timer - diff --git a/src/timer/cpu_counter/tm_hard.cpp b/src/timer/cpu_counter/tm_hard.cpp deleted file mode 100644 index 9e31aee39..000000000 --- a/src/timer/cpu_counter/tm_hard.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* -* Hardware Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -namespace Botan { - -/* -* Get the timestamp -*/ -u64bit Hardware_Timer::clock() const - { - u64bit rtc = 0; - -#if defined(BOTAN_TARGET_ARCH_IS_IA32) || defined(BOTAN_TARGET_ARCH_IS_AMD64) - u32bit rtc_low = 0, rtc_high = 0; - asm volatile("rdtsc" : "=d" (rtc_high), "=a" (rtc_low)); - rtc = (static_cast(rtc_high) << 32) | rtc_low; - -#elif defined(BOTAN_TARGET_ARCH_IS_PPC) || defined(BOTAN_TARGET_ARCH_IS_PPC64) - u32bit rtc_low = 0, rtc_high = 0; - asm volatile("mftbu %0; mftb %1" : "=r" (rtc_high), "=r" (rtc_low)); - rtc = (static_cast(rtc_high) << 32) | rtc_low; - -#elif defined(BOTAN_TARGET_ARCH_IS_ALPHA) - asm volatile("rpcc %0" : "=r" (rtc)); - -#elif defined(BOTAN_TARGET_ARCH_IS_SPARC64) - asm volatile("rd %%tick, %0" : "=r" (rtc)); - -#elif defined(BOTAN_TARGET_ARCH_IS_IA64) - asm volatile("mov %0=ar.itc" : "=r" (rtc)); - -#elif defined(BOTAN_TARGET_ARCH_IS_S390X) - asm volatile("stck 0(%0)" : : "a" (&rtc) : "memory", "cc"); - -#elif defined(BOTAN_TARGET_ARCH_IS_HPPA) - asm volatile("mfctl 16,%0" : "=r" (rtc)); // 64-bit only? - -#else - #error "Unsure how to access hardware timer on this system" -#endif - - return rtc; - } - -} diff --git a/src/timer/cpu_counter/tm_hard.h b/src/timer/cpu_counter/tm_hard.h deleted file mode 100644 index 2e338eca8..000000000 --- a/src/timer/cpu_counter/tm_hard.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -* Hardware Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_TIMER_HARDWARE_H__ -#define BOTAN_TIMER_HARDWARE_H__ - -#include - -namespace Botan { - -/* -* Hardware Timer -*/ -class BOTAN_DLL Hardware_Timer : public Timer - { - public: - /* - @todo: Add sync(Timer& wall_clock, bool milliseconds) which busy - loops using wall_clock and tries to guess the tick rate of the - hardware counter, allowing it to be used for benchmarks, etc - */ - - std::string name() const { return "Hardware Timer"; } - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/gettimeofday/info.txt b/src/timer/gettimeofday/info.txt deleted file mode 100644 index a58e8088d..000000000 --- a/src/timer/gettimeofday/info.txt +++ /dev/null @@ -1,33 +0,0 @@ -realname "Unix Timer" - -define TIMER_UNIX - -load_on auto -modset unix,beos - - -tm_unix.cpp -tm_unix.h - - - -aix -beos -cygwin -darwin -freebsd -dragonfly -hpux -irix -linux -netbsd -openbsd -qnx -solaris -tru64 - - - -timer - - diff --git a/src/timer/gettimeofday/tm_unix.cpp b/src/timer/gettimeofday/tm_unix.cpp deleted file mode 100644 index 9d8ac4a04..000000000 --- a/src/timer/gettimeofday/tm_unix.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -* Unix Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -namespace Botan { - -/* -* Get the timestamp -*/ -u64bit Unix_Timer::clock() const - { - struct ::timeval tv; - ::gettimeofday(&tv, 0); - return combine_timers(tv.tv_sec, tv.tv_usec, 1000000); - } - -} diff --git a/src/timer/gettimeofday/tm_unix.h b/src/timer/gettimeofday/tm_unix.h deleted file mode 100644 index c304dbb5c..000000000 --- a/src/timer/gettimeofday/tm_unix.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Unix Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_TIMER_UNIX_H__ -#define BOTAN_TIMER_UNIX_H__ - -#include - -namespace Botan { - -/* -* Unix Timer -*/ -class BOTAN_DLL Unix_Timer : public Timer - { - public: - std::string name() const { return "Unix gettimeofday"; } - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/info.txt b/src/timer/info.txt deleted file mode 100644 index 6408dca45..000000000 --- a/src/timer/info.txt +++ /dev/null @@ -1,14 +0,0 @@ -realname "Timer Base Class" - -define TIMER - -load_on auto - - -timer.cpp -timer.h - - - -rng - diff --git a/src/timer/posix_rt/info.txt b/src/timer/posix_rt/info.txt deleted file mode 100644 index fa530ea1a..000000000 --- a/src/timer/posix_rt/info.txt +++ /dev/null @@ -1,29 +0,0 @@ -realname "POSIX Timer" - -define TIMER_POSIX - -load_on auto - - -tm_posix.cpp -tm_posix.h - - - -linux -> rt - - -# The *BSDs put clock_gettime in sys/time.h, not time.h like POSIX says - -cygwin -linux -#freebsd -dragonfly -#netbsd -#openbsd - - - -timer - - diff --git a/src/timer/posix_rt/tm_posix.cpp b/src/timer/posix_rt/tm_posix.cpp deleted file mode 100644 index 96182025c..000000000 --- a/src/timer/posix_rt/tm_posix.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* -* POSIX Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include - -#ifndef _POSIX_C_SOURCE - #define _POSIX_C_SOURCE 199309 -#endif - -#include - -#ifndef CLOCK_REALTIME - #define CLOCK_REALTIME 0 -#endif - -namespace Botan { - -/* -* Get the timestamp -*/ -u64bit POSIX_Timer::clock() const - { - struct ::timespec tv; - ::clock_gettime(CLOCK_REALTIME, &tv); - return combine_timers(tv.tv_sec, tv.tv_nsec, 1000000000); - } - -} diff --git a/src/timer/posix_rt/tm_posix.h b/src/timer/posix_rt/tm_posix.h deleted file mode 100644 index 8bedccfa2..000000000 --- a/src/timer/posix_rt/tm_posix.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* POSIX Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_TIMER_POSIX_H__ -#define BOTAN_TIMER_POSIX_H__ - -#include - -namespace Botan { - -/* -* POSIX Timer -*/ -class BOTAN_DLL POSIX_Timer : public Timer - { - public: - std::string name() const { return "POSIX clock_gettime"; } - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/timer.cpp b/src/timer/timer.cpp deleted file mode 100644 index 16d7dc368..000000000 --- a/src/timer/timer.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/** -* Timestamp Functions -* (C) 1999-2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include -#include - -namespace Botan { - -/** -* Get the system clock -*/ -u64bit system_time() - { - return static_cast(std::time(0)); - } - -/* -* Convert a time_t to a struct tm -*/ -std::tm time_t_to_tm(u64bit timer) - { - std::time_t time_val = static_cast(timer); - - std::tm* tm_p = std::gmtime(&time_val); - if (tm_p == 0) - throw Encoding_Error("time_t_to_tm could not convert"); - return (*tm_p); - } - -/** -* Read the clock and return the output -*/ -void Timer::poll(Entropy_Accumulator& accum) - { - const u64bit clock_value = this->clock(); - accum.add(clock_value, 0); - } - -/** -* Combine a two time values into a single one -*/ -u64bit Timer::combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) - { - static const u64bit NANOSECONDS_UNITS = 1000000000; - - u64bit res = seconds * NANOSECONDS_UNITS; - res += parts * (NANOSECONDS_UNITS / parts_hz); - return res; - } - -/** -* ANSI Clock -*/ -u64bit ANSI_Clock_Timer::clock() const - { - return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC); - } - -} diff --git a/src/timer/timer.h b/src/timer/timer.h deleted file mode 100644 index 603027f6d..000000000 --- a/src/timer/timer.h +++ /dev/null @@ -1,53 +0,0 @@ -/** -* Timestamp Functions -* (C) 1999-2009 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_TIMERS_H__ -#define BOTAN_TIMERS_H__ - -#include -#include - -namespace Botan { - -/* -* Time Access/Conversion Functions -*/ -BOTAN_DLL u64bit system_time(); - -BOTAN_DLL std::tm time_t_to_tm(u64bit); - -/** -* Timer Interface -*/ -class BOTAN_DLL Timer : public EntropySource - { - public: - /** - @return nanoseconds resolution timestamp, unknown epoch - */ - virtual u64bit clock() const = 0; - - void poll(Entropy_Accumulator& accum); - - virtual ~Timer() {} - protected: - static u64bit combine_timers(u32bit, u32bit, u32bit); - }; - -/** -* ANSI Clock Timer -*/ -class BOTAN_DLL ANSI_Clock_Timer : public Timer - { - public: - std::string name() const { return "ANSI clock"; } - u64bit clock() const; - }; - -} - -#endif diff --git a/src/timer/win32_query_perf_ctr/info.txt b/src/timer/win32_query_perf_ctr/info.txt deleted file mode 100644 index 4bb1ddb34..000000000 --- a/src/timer/win32_query_perf_ctr/info.txt +++ /dev/null @@ -1,26 +0,0 @@ -realname "Win32 Timer" - -define TIMER_WIN32 -modset win32 - -load_on auto - - -tm_win32.cpp -tm_win32.h - - - -cygwin -windows -mingw - - - -windows -> user32.lib - - - -timer - - diff --git a/src/timer/win32_query_perf_ctr/tm_win32.cpp b/src/timer/win32_query_perf_ctr/tm_win32.cpp deleted file mode 100644 index 6b878e6e2..000000000 --- a/src/timer/win32_query_perf_ctr/tm_win32.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* -* Win32 Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#include -#include - -namespace Botan { - -/* -* Get the timestamp -*/ -u64bit Win32_Timer::clock() const - { - LARGE_INTEGER tv; - ::QueryPerformanceCounter(&tv); - return tv.QuadPart; - } - -} diff --git a/src/timer/win32_query_perf_ctr/tm_win32.h b/src/timer/win32_query_perf_ctr/tm_win32.h deleted file mode 100644 index 5bcb720ab..000000000 --- a/src/timer/win32_query_perf_ctr/tm_win32.h +++ /dev/null @@ -1,27 +0,0 @@ -/* -* Win32 Timer -* (C) 1999-2007 Jack Lloyd -* -* Distributed under the terms of the Botan license -*/ - -#ifndef BOTAN_TIMER_WIN32_H__ -#define BOTAN_TIMER_WIN32_H__ - -#include - -namespace Botan { - -/* -* Win32 Timer -*/ -class BOTAN_DLL Win32_Timer : public Timer - { - public: - std::string name() const { return "Win32 QueryPerformanceCounter"; } - u64bit clock() const; - }; - -} - -#endif diff --git a/src/utils/time.h b/src/utils/time.h new file mode 100644 index 000000000..3052aec44 --- /dev/null +++ b/src/utils/time.h @@ -0,0 +1,39 @@ +/* +* Time Functions +* (C) 2009 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_TIME_OPS_H__ +#define BOTAN_TIME_OPS_H__ + +#include + +namespace Botan { + +/* +* Convert a time_t value to a struct tm +*/ +inline std::tm time_t_to_tm(u64bit time_int) + { + std::time_t time_val = static_cast(time_int); + + std::tm* tm_p = std::gmtime(&time_val); + if (tm_p == 0) + throw Encoding_Error("time_t_to_tm could not convert"); + return (*tm_p); + } + +/** +* Get the system clock +*/ +inline u64bit system_time() + { + return static_cast(std::time(0)); + } + +} + + +#endif -- cgit v1.2.3