From 01f5bdec5baa2ddaf6bfc222aee3e22796c3651c Mon Sep 17 00:00:00 2001 From: Akiko Date: Wed, 20 May 2015 07:14:53 +0200 Subject: [PATCH] - kicked Boost dependency - removed Mutex, Semaphore and Thread class (we don't need this, C++11 has it own) --- CMakeLists.txt | 1 - TinNS/Source/Common/Mutex.hxx | 43 ---------- TinNS/Source/Common/Semaphore.hxx | 49 ----------- TinNS/Source/Common/Thread.hxx | 166 -------------------------------------- 4 files changed, 259 deletions(-) delete mode 100644 TinNS/Source/Common/Mutex.hxx delete mode 100644 TinNS/Source/Common/Semaphore.hxx delete mode 100644 TinNS/Source/Common/Thread.hxx diff --git a/CMakeLists.txt b/CMakeLists.txt index eb7bde2..c11b6bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,6 @@ FIND_PACKAGE (SQLITE3 REQUIRED) FIND_PACKAGE (PCRE REQUIRED) FIND_PACKAGE (ZLIB REQUIRED) FIND_PACKAGE (Lua53 REQUIRED) # the lua distributions are a nightmare, here is my finder for 5.3 -FIND_PACKAGE (Boost REQUIRED) # includes and outputs SET (CMAKE_INCLUDE_CURRENT_DIR on) diff --git a/TinNS/Source/Common/Mutex.hxx b/TinNS/Source/Common/Mutex.hxx deleted file mode 100644 index a2ca8c8..0000000 --- a/TinNS/Source/Common/Mutex.hxx +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include - -class Mutex { -private: - mutable pthread_mutex_t mut; - - void operator = (Mutex &mut) {} - - Mutex(const Mutex &mut) {} - -public: - Mutex() - { - pthread_mutexattr_t attr; - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - pthread_mutex_init(&mut, &attr); - pthread_mutexattr_destroy(&attr); - } - - virtual ~Mutex() - { - pthread_mutex_unlock(&mut); - pthread_mutex_destroy(&mut); - } - - int Lock() const - { - return (pthread_mutex_lock(&mut)); - } - - int TryLock() const - { - return (pthread_mutex_trylock(&mut)); - } - - int Unlock() const - { - return (pthread_mutex_unlock(&mut)); - } -}; diff --git a/TinNS/Source/Common/Semaphore.hxx b/TinNS/Source/Common/Semaphore.hxx deleted file mode 100644 index 89f71b6..0000000 --- a/TinNS/Source/Common/Semaphore.hxx +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -class Semaphore { -private: - sem_t sem; - -public: - Semaphore(int init = 0) - { - sem_init(&sem, 0, init); - } - - virtual ~Semaphore() - { - sem_destroy(&sem); - } - - void Wait() const - { - sem_wait((sem_t *)&sem); - } - - int TryWait() const - { - return (sem_trywait((sem_t *)&sem) ? errno : 0); - } - - int Post() const - { - return (sem_post((sem_t *)&sem) ? errno : 0); - } - - int GetValue() const - { - int val = -1; - - sem_getvalue((sem_t *)&sem, &val); - - return (val); - } - - void Reset(int init = 0) - { - sem_destroy(&sem); - sem_init(&sem, 0, init); - } -}; diff --git a/TinNS/Source/Common/Thread.hxx b/TinNS/Source/Common/Thread.hxx deleted file mode 100644 index 5ddb652..0000000 --- a/TinNS/Source/Common/Thread.hxx +++ /dev/null @@ -1,166 +0,0 @@ -#pragma once - -#include -#include -#include - -#define INVALID_HANDLE 0 - -typedef void *(*pthread_fn)(void*); - -template -class Thread { - private: - typedef struct Instance; - - public: - typedef Thread_T &Thread_; - typedef const Thread_T &Thread__; - typedef pthread_t Handle; - typedef void (*Handler)(Thread_); - - protected: - Thread() { - } - - virtual void ThreadMain(Thread_) = 0; - - static void Exit() { - pthread_exit(0); - } - - static void TestCancel() { - pthread_testcancel(); - } - - static Handle Self() { - return(Handle)pthread_self(); - } - - public: - static int Create(const Handler &Func, Thread__ Param, Handle *const &H = 0, - const bool &CreateDetached = false, const unsigned int &StackSize = 0, - const bool &CancelEnable = false, const bool &CancelAsync = false) { - M_Create().Lock(); - pthread_attr_t attr; - pthread_attr_init(&attr); - - if(CreateDetached) - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - if(StackSize) - pthread_attr_setstacksize(&attr, StackSize); - - Instance I(Param, 0, Func, CancelEnable, CancelAsync); - - Handle h = INVALID_HANDLE; - int run = pthread_create((pthread_t *)&h, &attr, (pthread_fn)ThreadMainHandler, (void *)&I); - - pthread_attr_destroy(&attr); - - if(H) - *H = h; - if(!run) - S_Create().Wait(); - - M_Create().Unlock(); - - return(errno); - } - - int Create(Thread__ Param, Handle *const &H = 0, const bool &CreateDetached = false, - const unsigned int &StackSize = 0, const bool &CancelEnable = false, - const bool &CancelAsync = false ) const { - M_Create().Lock(); - pthread_attr_t attr; - pthread_attr_init(&attr); - - if(CreateDetached) - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - if(StackSize) - pthread_attr_setstacksize(&attr, StackSize); - - Instance I(Param, const_cast(this), 0, CancelEnable, CancelAsync); - - Handle h = INVALID_HANDLE; - int run = pthread_create((pthread_t *)&h, &attr, (pthread_fn)ThreadMainHandler, (void *)&I); - - pthread_attr_destroy(&attr); - - if(H) - *H = h; - if(!run) - S_Create().Wait(); - - M_Create().Unlock(); - - return(errno); - } - - static int Join(Handle H) { - return(pthread_join(H, 0)); - } - - static int Kill(Handle H) { - return(pthread_cancel(H)); - } - - static int Detach(Handle H) { - return(pthread_detach(H)); - } - - private: - static const Mutex &M_Create() { - static Mutex M; - - return(M); - } - - static const Semaphore &S_Create() { - static Semaphore S; - - return(S); - } - - static void ThreadMainHandler(Instance *Param) { - Instance I(*Param); - Thread_T Data(I.Data); - - S_Create().Post(); - - if(I.Flags & 1) { - pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); - - if(I.Flags & 2) - pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - else - pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); - } - else - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); - - if(I.Owner) - I.Owner->ThreadMain(Data); - else - I.pFN(Data); - - return(0); - } - - struct Instance { - Instance(Thread__ P, Thread *const &O, const Thread::Handler &pH = 0, - const bool &CE = false, const bool &CA = false) : Data(P), Owner(O), pFN(pH), - Flags(0) { - if(CE) - Flags |= 1; - if(CA) - Flags |= 2; - } - - Thread__ Data; - Thread *Owner; - Handler pFN; - unsigned char Flags; - }; -}; -- 2.15.1