forked from mangoszero/server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreading.h
More file actions
213 lines (196 loc) · 4.6 KB
/
Threading.h
File metadata and controls
213 lines (196 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/**
* MaNGOS is a full featured server for World of Warcraft, supporting
* the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8
*
* Copyright (C) 2005-2019 MaNGOS project <https://getmangos.eu>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* World of Warcraft, and all World of Warcraft or Warcraft art, images,
* and lore are copyrighted by Blizzard Entertainment, Inc.
*/
#ifndef THREADING_H
#define THREADING_H
#include <ace/Thread.h>
#include <ace/TSS_T.h>
#include <ace/Atomic_Op.h>
#include <assert.h>
namespace ACE_Based
{
/**
* @brief
*
*/
class Runnable
{
public:
/**
* @brief
*
*/
virtual ~Runnable() {}
/**
* @brief
*
*/
virtual void run() = 0;
/**
* @brief
*
*/
void incReference() { ++m_refs; }
/**
* @brief
*
*/
void decReference()
{
if (!--m_refs)
{ delete this; }
}
private:
ACE_Atomic_Op<ACE_Thread_Mutex, long> m_refs; /**< TODO */
};
/**
* @brief
*
*/
enum Priority
{
Idle,
Lowest,
Low,
Normal,
High,
Highest,
Realtime
};
#define MAXPRIORITYNUM (Realtime + 1)
/**
* @brief
*
*/
class ThreadPriority
{
public:
/**
* @brief
*
*/
ThreadPriority();
/**
* @brief
*
* @param p
* @return int
*/
int getPriority(Priority p) const;
private:
int m_priority[MAXPRIORITYNUM]; /**< TODO */
};
/**
* @brief
*
*/
class Thread
{
public:
/**
* @brief
*
*/
Thread();
/**
* @brief
*
* @param instance
*/
explicit Thread(Runnable* instance);
/**
* @brief
*
*/
~Thread();
/**
* @brief
*
* @return bool
*/
bool start();
/**
* @brief
*
* @return bool
*/
bool wait();
/**
* @brief
*
*/
void destroy();
/**
* @brief
*
*/
void suspend();
/**
* @brief
*
*/
void resume();
/**
* @brief
*
* @param type
*/
void setPriority(Priority type);
/**
* @brief
*
* @param msecs
*/
static void Sleep(unsigned long msecs);
private:
/**
* @brief
*
* @param
*/
Thread(const Thread&);
/**
* @brief
*
* @param
* @return Thread &operator
*/
Thread& operator=(const Thread&);
/**
* @brief
*
* @param param
* @return ACE_THR_FUNC_RETURN
*/
static ACE_THR_FUNC_RETURN ThreadTask(void* param);
ACE_thread_t m_iThreadId; /**< TODO */
ACE_hthread_t m_hThreadHandle; /**< TODO */
Runnable* m_task; /**< TODO */
/**
* @brief
*
*/
static ThreadPriority m_TpEnum; /**< use this object to determine current OS thread priority values mapped to enum Priority{} */
};
}
#endif