-
Notifications
You must be signed in to change notification settings - Fork 1
/
sdlthread.hpp
184 lines (184 loc) · 2.97 KB
/
sdlthread.hpp
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
#include <SDL2/SDL.h>
#include "sdlthread.h"
#ifdef __SDLGUI_THREAD_HEAD__
//--------------------------------------------------
//
//
//
//
//
//
//
//
//--------------------------------------------------
def_dll sdl_semaphore::sdl_semaphore()
{
init();
}
def_dll sdl_semaphore::sdl_semaphore(int d)
{
init(d);
}
def_dll sdl_semaphore::~sdl_semaphore()
{
destroy();
}
def_dll int sdl_semaphore::init()
{
_semaphore = NULL;
return 0;
}
def_dll int sdl_semaphore::init(int d)
{
destroy();
_semaphore = SDL_CreateSemaphore(d);
if(_semaphore)return 0;
return -1;
}
def_dll int sdl_semaphore::destroy()
{
if(_semaphore)
{
SDL_DestroySemaphore(_semaphore);
_semaphore = NULL;
return 0;
}
return -1;
}
def_dll int sdl_semaphore::wait()
{
return SDL_SemWait(_semaphore);
}
def_dll int sdl_semaphore::post()
{
return SDL_SemPost(_semaphore);
}
def_dll Uint32 sdl_semaphore::value()
{
return SDL_SemValue(_semaphore);
}
def_dll int sdl_semaphore::try_wait()
{
return SDL_SemTryWait(_semaphore);
}
def_dll int sdl_semaphore::wait_timeout(Uint32 ms)
{
return SDL_SemWaitTimeout(_semaphore,ms);
}
//-----------------------------------------------------------------
//
//
//
//
//
// 互斥体对象实现
//
//
//
///
//-----------------------------------------------------------------
def_dll sdl_mutex::sdl_mutex()
{
_mutex = NULL;
create();
}
def_dll sdl_mutex::~sdl_mutex()
{
destroy();
}
def_dll int sdl_mutex::create()
{
destroy();
_mutex = SDL_CreateMutex();
if(_mutex)return 0;
return -1;
}
def_dll int sdl_mutex::destroy()
{
if(_mutex)
{
SDL_DestroyMutex(_mutex);
_mutex = NULL;
}
return 0;
}
def_dll int sdl_mutex::lock()
{
return SDL_LockMutex(_mutex);
}
def_dll int sdl_mutex::unlock()
{
return SDL_UnlockMutex(_mutex);
}
def_dll int sdl_mutex::try_lock()
{
return SDL_TryLockMutex(_mutex);
}
//----------------------------------------------------------
//
//
//
//
// 条件变量
//
//
//
//------------------------------------------------------------
def_dll sdl_condition::sdl_condition()
{
_condition = NULL;
create();
}
def_dll sdl_condition::~sdl_condition()
{
destroy();
}
def_dll int sdl_condition::create()
{
destroy();
_condition = SDL_CreateCond();
if(_condition)return 0;
return -1;
}
def_dll int sdl_condition::destroy()
{
if(_condition)
{
SDL_DestroyCond(_condition);
return 0;
}
return -1;
}
def_dll int sdl_condition::wait(sdl_mutex* p)
{
if(p)
{
return SDL_CondWait(_condition,p->_mutex);
}
return -1;
}
def_dll int sdl_condition::wait(sdl_mutex& p)
{
return SDL_CondWait(_condition,p._mutex);
}
def_dll int sdl_condition::wait_timeout(sdl_mutex* p,Uint32 t)
{
if(p)
{
return SDL_CondWaitTimeout(_condition,p->_mutex,t);
}
return -1;
}
def_dll int sdl_condition::wait_timeout(sdl_mutex& p,Uint32 t)
{
return SDL_CondWaitTimeout(_condition,p._mutex,t);
}
def_dll int sdl_condition::signal()
{
return SDL_CondSignal(_condition);
}
def_dll int sdl_condition::broadcast()
{
return SDL_CondBroadcast(_condition);
}
#endif //__SDLGUI_THREAD_HEAD__