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