annotate src/thread/pth/SDL_sysmutex.c @ 1338:604d73db6802

Removed uses of stdlib.h and string.h
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 09:29:18 +0000
parents 3692456e7b0f
children c71e05b4dc2e
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
1338
604d73db6802 Removed uses of stdlib.h and string.h
Sam Lantinga <slouken@libsdl.org>
parents: 1336
diff changeset
9 #include "SDL_stdlib.h"
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #include "SDL_error.h"
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #include "SDL_mutex.h"
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 #include "SDL_sysmutex_c.h"
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14 /* Create a mutex */
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 SDL_mutex *SDL_CreateMutex(void)
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 SDL_mutex *mutex;
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 /* Allocate mutex memory */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 329
diff changeset
20 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 if ( mutex ) {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 /* Create the mutex, with initial value signaled */
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 if (!pth_mutex_init(&(mutex->mutexpth_p))) {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 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
25 SDL_free(mutex);
329
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 mutex = NULL;
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 }
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 } else {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 SDL_OutOfMemory();
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 return(mutex);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 }
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 /* Free the mutex */
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 void SDL_DestroyMutex(SDL_mutex *mutex)
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 if ( mutex ) {
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 329
diff changeset
38 SDL_free(mutex);
329
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 }
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 /* Lock the mutex */
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 int SDL_mutexP(SDL_mutex *mutex)
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 if ( mutex == NULL ) {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 SDL_SetError("Passed a NULL mutex");
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 return -1;
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 }
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 pth_mutex_acquire(&(mutex->mutexpth_p), FALSE, NULL);
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 return(0);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 }
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 /* Unlock the mutex */
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 int SDL_mutexV(SDL_mutex *mutex)
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 if ( mutex == NULL ) {
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 SDL_SetError("Passed a NULL mutex");
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 return -1;
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 }
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 pth_mutex_release(&(mutex->mutexpth_p));
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 return(0);
1d74ddc90cb2 Patrice's fixes for GNU Pthread support
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 }