[9478] Reimplement Aura::IsNeedVisibleSlot
[getmangos.git] / src / shared / Threading.h
blob0684616aafc77fc96cb098b6821484d926826b46
1 /*
2 * Copyright (C) 2009-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef THREADING_H
20 #define THREADING_H
22 #include <ace/Thread.h>
23 #include <ace/TSS_T.h>
24 #include "ace/Atomic_Op.h"
25 #include <assert.h>
27 namespace ACE_Based
30 class Runnable
32 public:
33 virtual ~Runnable() {}
34 virtual void run() = 0;
36 void incReference() { ++m_refs; }
37 void decReference()
39 if(!--m_refs)
40 delete this;
42 private:
43 ACE_Atomic_Op<ACE_Thread_Mutex, int> m_refs;
46 enum Priority
48 Idle,
49 Lowest,
50 Low,
51 Normal,
52 High,
53 Highest,
54 Realtime,
57 #define MAXPRIORITYNUM (Realtime + 1)
59 class ThreadPriority
61 public:
62 ThreadPriority();
63 int getPriority(Priority p) const;
65 private:
66 int m_priority[MAXPRIORITYNUM];
69 class Thread
71 public:
72 Thread();
73 explicit Thread(Runnable* instance);
74 ~Thread();
76 bool start();
77 bool wait();
78 void destroy();
80 void suspend();
81 void resume();
83 void setPriority(Priority type);
85 static void Sleep(unsigned long msecs);
86 static ACE_thread_t currentId();
87 static ACE_hthread_t currentHandle();
88 static Thread * current();
90 private:
91 Thread(const Thread&);
92 Thread& operator=(const Thread&);
94 static ACE_THR_FUNC_RETURN ThreadTask(void * param);
96 ACE_thread_t m_iThreadId;
97 ACE_hthread_t m_hThreadHandle;
98 Runnable * m_task;
100 typedef ACE_TSS<Thread> ThreadStorage;
101 //global object - container for Thread class representation of every thread
102 static ThreadStorage m_ThreadStorage;
103 //use this object to determine current OS thread priority values mapped to enum Priority{}
104 static ThreadPriority m_TpEnum;
108 #endif