diff options
author | Adam <Adam@anope.org> | 2014-04-02 14:24:32 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2014-04-02 14:25:13 -0400 |
commit | 8020b411cdd534a6cf6df60880f6c0980d428365 (patch) | |
tree | 26c25de0d3431a1d7117f1c6a2460bed0289ebf1 /include/threadengine.h | |
parent | 52bc8e4bc799d38e92d38d497a2bd055950841bb (diff) |
Use std::thread for the threadengine
Diffstat (limited to 'include/threadengine.h')
-rw-r--r-- | include/threadengine.h | 54 |
1 files changed, 11 insertions, 43 deletions
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 <thread> +#include <mutex> +#include <condition_variable> -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(); }; |