From 8020b411cdd534a6cf6df60880f6c0980d428365 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 2 Apr 2014 14:24:32 -0400 Subject: Use std::thread for the threadengine --- include/threadengine.h | 54 ++++++++++---------------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) (limited to 'include') diff --git a/include/threadengine.h b/include/threadengine.h index 61e8822d2..1f5c5468c 100644 --- a/include/threadengine.h +++ b/include/threadengine.h @@ -14,8 +14,11 @@ #include "sockets.h" #include "extensible.h" +#include +#include +#include -class CoreExport Thread : public Pipe, public Extensible +class CoreExport Thread : public Pipe { private: /* Set to true to tell the thread to finish and we are waiting for it */ @@ -23,7 +26,7 @@ class CoreExport Thread : public Pipe, public Extensible public: /* Handle for this thread */ - pthread_t handle; + std::thread handle; /** Threads constructor */ @@ -41,10 +44,6 @@ class CoreExport Thread : public Pipe, public Extensible */ void SetExitState(); - /** Exit the thread. Note that the thread still must be joined to free resources! - */ - void Exit(); - /** Launch the thread */ void Start(); @@ -63,57 +62,26 @@ class CoreExport Thread : public Pipe, public Extensible virtual void Run() = 0; }; -class CoreExport Mutex +class Mutex { protected: - /* A mutex, used to keep threads in sync */ - pthread_mutex_t mutex; + std::mutex m; public: - /** Constructor - */ - Mutex(); - - /** Destructor - */ - ~Mutex(); - - /** Attempt to lock the mutex, will hang until a lock can be achieved - */ void Lock(); - /** Unlock the mutex, it must be locked first - */ - void Unlock(); - - /** Attempt to lock the mutex, will return true on success and false on fail - * Does not block - * @return true or false - */ bool TryLock(); + + void Unlock(); }; -class CoreExport Condition : public Mutex +class Condition : public Mutex { - private: - /* A condition */ - pthread_cond_t cond; + std::condition_variable_any cv; public: - /** Constructor - */ - Condition(); - - /** Destructor - */ - ~Condition(); - - /** Called to wakeup the waiter - */ void Wakeup(); - /** Called to wait for a Wakeup() call - */ void Wait(); }; -- cgit