Mercurial > sdl-ios-xcode
annotate src/thread/pth/SDL_sysmutex.c @ 1358:c71e05b4dc2e
More header massaging... works great on Windows. ;-)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Fri, 10 Feb 2006 06:48:43 +0000 |
parents | 604d73db6802 |
children | d910939febfa |
rev | line source |
---|---|
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
1 /* |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
2 * GNU pth mutexes |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
3 * |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
4 * Patrice Mandin |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
5 */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
6 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
7 #include <pth.h> |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
8 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
9 #include "SDL_mutex.h" |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
10 #include "SDL_sysmutex_c.h" |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
11 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
12 /* Create a mutex */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
13 SDL_mutex *SDL_CreateMutex(void) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
14 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
15 SDL_mutex *mutex; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
16 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
17 /* Allocate mutex memory */ |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
329
diff
changeset
|
18 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
19 if ( mutex ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
20 /* Create the mutex, with initial value signaled */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
21 if (!pth_mutex_init(&(mutex->mutexpth_p))) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
22 SDL_SetError("Couldn't create mutex"); |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
329
diff
changeset
|
23 SDL_free(mutex); |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
24 mutex = NULL; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
25 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
26 } else { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
27 SDL_OutOfMemory(); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
28 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
29 return(mutex); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
30 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
31 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
32 /* Free the mutex */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
33 void SDL_DestroyMutex(SDL_mutex *mutex) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
34 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
35 if ( mutex ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
329
diff
changeset
|
36 SDL_free(mutex); |
329
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
37 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
38 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
39 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
40 /* Lock the mutex */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
41 int SDL_mutexP(SDL_mutex *mutex) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
42 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
43 if ( mutex == NULL ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
44 SDL_SetError("Passed a NULL mutex"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
45 return -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
46 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
47 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
48 pth_mutex_acquire(&(mutex->mutexpth_p), FALSE, NULL); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
49 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
50 return(0); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
51 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
52 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
53 /* Unlock the mutex */ |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
54 int SDL_mutexV(SDL_mutex *mutex) |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
55 { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
56 if ( mutex == NULL ) { |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
57 SDL_SetError("Passed a NULL mutex"); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
58 return -1; |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
59 } |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
60 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
61 pth_mutex_release(&(mutex->mutexpth_p)); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
62 |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
63 return(0); |
1d74ddc90cb2
Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff
changeset
|
64 } |