Mercurial > hg > dmlib
annotate dmlib.c @ 294:dd9809a93425
Improve mutex debugging facilities.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 11 Oct 2012 16:04:02 +0300 |
parents | 32250b436bca |
children | 3c5ebe88e52f |
rev | line source |
---|---|
0 | 1 #include "dmlib.h" |
2 #include <errno.h> | |
3 | |
4 | |
5 int dmVerbosity = 0; | |
6 char *dmProgName = NULL, | |
7 *dmProgDesc = NULL, | |
8 *dmProgVersion = NULL, | |
9 *dmProgAuthor = NULL, | |
10 *dmProgLicense = NULL; | |
11 | |
12 | |
13 void dmInitProg(char *name, char *desc, char *version, char *author, char *license) | |
14 { | |
15 dmProgName = name; | |
16 dmProgDesc = desc; | |
17 dmProgVersion = version; | |
18 | |
19 if (author) | |
20 dmProgAuthor = author; | |
21 else | |
22 dmProgAuthor = DM_PROG_AUTHOR; | |
23 | |
24 if (license) | |
25 dmProgLicense = license; | |
26 else | |
27 dmProgLicense = DM_PROG_LICENSE; | |
28 | |
29 } | |
30 | |
31 | |
32 void dmPrintBanner(FILE *outFile, const char *name, const char *usage) | |
33 { | |
34 fprintf(outFile, | |
35 "\n%s v%s (%s)\n" | |
36 "%s\n" | |
37 "%s\n" | |
38 "Usage: %s %s\n", | |
39 dmProgName, dmProgVersion, dmProgDesc, | |
40 dmProgAuthor, dmProgLicense, name, usage); | |
41 } | |
42 | |
43 | |
44 void dmMsgVA(int level, const char *fmt, va_list ap) | |
45 { | |
46 if (dmVerbosity >= level) | |
47 { | |
48 fprintf(stderr, "%s: ", dmProgName); | |
49 vfprintf(stderr, fmt, ap); | |
50 } | |
51 } | |
52 | |
53 | |
54 void dmPrintVA(int level, const char *fmt, va_list ap) | |
55 { | |
56 if (dmVerbosity >= level) | |
57 { | |
58 vfprintf(stderr, fmt, ap); | |
59 } | |
60 } | |
61 | |
62 | |
63 void dmErrorVA(const char *fmt, va_list ap) | |
64 { | |
65 fprintf(stderr, "%s: ", dmProgName); | |
66 vfprintf(stderr, fmt, ap); | |
67 } | |
68 | |
69 | |
70 void dmError(const char *fmt, ...) | |
71 { | |
72 va_list ap; | |
73 | |
74 va_start(ap, fmt); | |
75 dmErrorVA(fmt, ap); | |
76 va_end(ap); | |
77 } | |
78 | |
79 | |
80 void dmMsg(int level, const char *fmt, ...) | |
81 { | |
82 va_list ap; | |
83 | |
84 va_start(ap, fmt); | |
85 dmMsgVA(level, fmt, ap); | |
86 va_end(ap); | |
87 } | |
88 | |
89 | |
90 void dmPrint(int level, const char *fmt, ...) | |
91 { | |
92 va_list ap; | |
93 | |
94 va_start(ap, fmt); | |
95 dmPrintVA(level, fmt, ap); | |
96 va_end(ap); | |
97 } | |
98 | |
99 | |
100 /* Memory handling routines | |
101 */ | |
102 void *dmMalloc(size_t l) | |
103 { | |
104 return malloc(l); | |
105 } | |
106 | |
107 | |
108 void *dmMalloc0(size_t l) | |
109 { | |
110 return calloc(1, l); | |
111 } | |
112 | |
113 | |
114 void *dmCalloc(size_t n, size_t l) | |
115 { | |
116 return calloc(n, l); | |
117 } | |
118 | |
119 | |
120 void *dmRealloc(void *p, size_t l) | |
121 { | |
122 return realloc(p, l); | |
123 } | |
124 | |
125 | |
126 void dmFree(void *p) | |
127 { | |
128 /* Check for NULL pointers for portability due to some libc | |
129 * implementations not handling free(NULL) too well. | |
130 */ | |
131 if (p) free(p); | |
132 } | |
133 | |
134 | |
135 BOOL dmGetIntVal(const char *s, int *i) | |
136 { | |
137 if (s[0] == '$') | |
138 { | |
139 if (sscanf(&s[1], "%x", i) < 1) | |
140 return FALSE; | |
141 } | |
142 else if (s[0] == '0' && s[1] == 'x') | |
143 { | |
144 if (sscanf(&s[2], "%x", i) < 1) | |
145 return FALSE; | |
146 } | |
147 else | |
148 { | |
149 if (sscanf(s, "%u", i) < 1) | |
150 return FALSE; | |
151 } | |
152 return TRUE; | |
153 } | |
154 | |
155 | |
156 /* Error handling | |
157 */ | |
158 #define DM_SYSTEM_ERRORS 100000 | |
159 | |
160 int dmGetErrno() | |
161 { | |
162 return DM_SYSTEM_ERRORS + errno; | |
163 } | |
164 | |
165 | |
166 const char *dmErrorStr(int error) | |
167 { | |
168 if (error >= DM_SYSTEM_ERRORS) | |
169 return strerror(error - DM_SYSTEM_ERRORS); | |
170 | |
171 switch (error) | |
172 { | |
173 case DMERR_OK: return "No error"; | |
174 case DMERR_FOPEN: return "File open error"; | |
175 case DMERR_FREAD: return "Read error"; | |
176 case DMERR_FWRITE: return "Write error"; | |
177 case DMERR_FSEEK: return "Seek error"; | |
178 case DMERR_NOT_FOUND: return "Resource not found"; | |
179 | |
180 case DMERR_INVALID_DATA: return "Invalid data"; | |
181 case DMERR_MALLOC: return "Memory allocation failure"; | |
182 case DMERR_ALREADY_INIT: return "Already initialized"; | |
183 case DMERR_INIT_FAIL: return "Initialization failed"; | |
184 case DMERR_INVALID_ARGS: return "Invalid arguments"; | |
185 | |
186 case DMERR_NULLPTR: return "NULL pointer"; | |
187 case DMERR_NOT_SUPPORTED: return "Operation not supported"; | |
188 case DMERR_OUT_OF_DATA: return "Out of data"; | |
189 case DMERR_EXTRA_DATA: return "Extra data"; | |
190 case DMERR_BOUNDS: return "Bounds check failed"; | |
191 | |
192 case DMERR_NOTPACK: return "File is not a PACK"; | |
193 case DMERR_VERSION: return "Unsupported PACK version"; | |
194 case DMERR_INVALID: return "Invalid data, corrupted file"; | |
195 case DMERR_COMPRESSION: return "Error in compression"; | |
196 | |
197 default: return "Unknown error"; | |
198 } | |
199 } | |
294
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
200 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
201 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
202 #ifdef DM_MUTEX_DEBUG |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
203 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
204 static DMMutexLock * dmGetMutexThreadIDLock(DMMutex *mutex) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
205 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
206 Uint32 id = SDL_ThreadID(); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
207 int i; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
208 for (i = 0; i < 8; i++) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
209 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
210 DMMutexLock *lock = &(mutex->locks[i]); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
211 if (lock->used && lock->id == id) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
212 return lock; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
213 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
214 return NULL; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
215 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
216 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
217 static void dmPrintMutexLocks(DMMutex *mutex, const char *state, const char *file, const int line) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
218 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
219 int i; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
220 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
221 fprintf(stderr, |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
222 "----------------------\n" |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
223 "%s --> %p @ %s:%d\n" |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
224 "Current thread: %d\n" |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
225 "Mutex : %p (created @ %s:%d)\n", |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
226 state, mutex, file, line, |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
227 SDL_ThreadID(), mutex, mutex->cr_file, mutex->cr_line); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
228 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
229 for (i = 0; i < 8; i++) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
230 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
231 DMMutexLock *lock = &(mutex->locks[i]); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
232 if (lock->used) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
233 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
234 fprintf(stderr, |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
235 "Lock #%d: thread=%d, state=%d\n", |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
236 i, lock->id, lock->state); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
237 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
238 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
239 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
240 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
241 int dmDOMutexLock(DMMutex *mutex, const char *file, const int line) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
242 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
243 if (mutex != NULL) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
244 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
245 dmPrintMutexLocks(mutex, "LOCKING", file, line); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
246 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
247 DMMutexLock *lock = dmGetMutexThreadIDLock(mutex); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
248 if (lock != NULL) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
249 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
250 int res; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
251 if (lock->state == 0) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
252 res = SDL_mutexP(mutex->m); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
253 else |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
254 res = 1; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
255 lock->state++; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
256 fprintf(stderr, "LOCKING %p @ thread=%d done [1].\n", mutex, SDL_ThreadID()); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
257 return res; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
258 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
259 else |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
260 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
261 int i; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
262 for (i = 0; i < 8; i++) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
263 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
264 DMMutexLock *lock = &(mutex->locks[i]); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
265 if (!lock->used) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
266 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
267 int res; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
268 lock->used = TRUE; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
269 lock->id = SDL_ThreadID(); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
270 lock->state++; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
271 res = SDL_mutexP(mutex->m); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
272 fprintf(stderr, "LOCKING %p @ thread=%d done [2].\n", mutex, SDL_ThreadID()); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
273 return res; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
274 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
275 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
276 return -2; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
277 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
278 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
279 return -1; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
280 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
281 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
282 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
283 int dmDOMutexUnlock(DMMutex *mutex, const char *file, const int line) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
284 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
285 if (mutex != NULL) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
286 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
287 dmPrintMutexLocks(mutex, "UN-LOCKING", file, line); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
288 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
289 DMMutexLock *lock = dmGetMutexThreadIDLock(mutex); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
290 if (lock != NULL) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
291 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
292 int res; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
293 lock->state--; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
294 if (lock->state == 0) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
295 res = SDL_mutexV(mutex->m); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
296 else |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
297 res = lock->state; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
298 return res; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
299 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
300 else |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
301 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
302 return -2; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
303 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
304 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
305 return -1; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
306 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
307 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
308 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
309 DMMutex * dmDOCreateMutex(const char *file, const int line) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
310 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
311 DMMutex *mutex = dmMalloc0(sizeof(DMMutex)); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
312 if (mutex == NULL) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
313 return NULL; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
314 mutex->cr_file = dm_strdup(file); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
315 mutex->cr_line = line; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
316 mutex->m = SDL_CreateMutex(); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
317 return mutex; |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
318 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
319 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
320 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
321 void dmDestroyMutex(DMMutex *mutex) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
322 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
323 if (mutex != NULL) |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
324 { |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
325 SDL_DestroyMutex(mutex->m); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
326 dmFree(mutex); |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
327 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
328 } |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
329 |
dd9809a93425
Improve mutex debugging facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
330 #endif |