[7833] Implement levelup spells for non-hunter pets.
[getmangos.git] / src / shared / Threading.h
blobeac3c0e8efb0c20cf58fda0b4152108466da3ccd
1 /*
2 * Copyright (C) 2009 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 <assert.h>
25 #include "Errors.h"
27 namespace ACE_Based
30 class Runnable
32 public:
33 virtual ~Runnable() {}
34 virtual void run() = 0;
37 enum Priority
39 Idle,
40 Lowest,
41 Low,
42 Normal,
43 High,
44 Highest,
45 Realtime,
48 #define MAXPRIORITYNUM (Realtime + 1)
50 class ThreadPriority
52 public:
53 ThreadPriority();
54 int getPriority(Priority p) const;
56 private:
57 int m_priority[MAXPRIORITYNUM];
60 class Thread
62 public:
63 Thread();
64 Thread(Runnable& instance);
65 ~Thread();
67 bool start();
68 bool wait();
69 void destroy();
71 void suspend();
72 void resume();
74 void setPriority(Priority type);
76 static void Sleep(unsigned long msecs);
77 static ACE_thread_t currentId();
78 static ACE_hthread_t currentHandle();
79 static Thread * current();
81 private:
82 Thread(const Thread&);
83 Thread& operator=(const Thread&);
85 static ACE_THR_FUNC_RETURN ThreadTask(void * param);
87 ACE_thread_t m_iThreadId;
88 ACE_hthread_t m_hThreadHandle;
89 Runnable * m_task;
91 typedef ACE_TSS<Thread> ThreadStorage;
92 //global object - container for Thread class representation of every thread
93 static ThreadStorage m_ThreadStorage;
94 //use this object to determine current OS thread priority values mapped to enum Priority{}
95 static ThreadPriority m_TpEnum;
99 #endif