summaryrefslogtreecommitdiff
path: root/src/common/Threading/Threading.h
diff options
context:
space:
mode:
authorYehonal <yehonal.azeroth@gmail.com>2017-12-20 20:48:35 +0100
committerYehonal <yehonal.azeroth@gmail.com>2017-12-21 00:20:29 +0100
commit17332304fdf129076d0196010602350d5750c808 (patch)
treed161f8845df9e5c8ec0b149bd846646c2b112d49 /src/common/Threading/Threading.h
parent0fc4a6a153ca3a09ccb6e1311131b12a59c6cba3 (diff)
Using TC structure allowing easier patches importing
Diffstat (limited to 'src/common/Threading/Threading.h')
-rw-r--r--src/common/Threading/Threading.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/common/Threading/Threading.h b/src/common/Threading/Threading.h
new file mode 100644
index 0000000000..ad6d52639c
--- /dev/null
+++ b/src/common/Threading/Threading.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: http://github.com/azerothcore/azerothcore-wotlk/LICENSE-GPL2
+ * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ */
+
+#ifndef THREADING_H
+#define THREADING_H
+
+#include <thread>
+#include <atomic>
+
+#include <thread>
+#include <atomic>
+
+namespace ACORE
+{
+ class Runnable
+ {
+ public:
+ virtual ~Runnable() {}
+ virtual void run() = 0;
+
+ void incReference() { ++m_refs; }
+ void decReference()
+ {
+ if (!--m_refs)
+ delete this;
+ }
+ private:
+ std::atomic_long m_refs;
+ };
+
+ enum Priority
+ {
+ Priority_Idle,
+ Priority_Lowest,
+ Priority_Low,
+ Priority_Normal,
+ Priority_High,
+ Priority_Highest,
+ Priority_Realtime,
+ };
+
+ class Thread
+ {
+ public:
+ Thread();
+ explicit Thread(Runnable* instance);
+ ~Thread();
+
+ bool wait();
+ void destroy();
+
+ void setPriority(Priority type);
+
+ static void Sleep(unsigned long msecs);
+ static std::thread::id currentId();
+
+ private:
+ Thread(const Thread&);
+ Thread& operator=(const Thread&);
+
+ static void ThreadTask(void* param);
+
+ Runnable* const m_task;
+ std::thread::id m_iThreadId;
+ std::thread m_ThreadImp;
+ };
+}
+#endif