Mercurial > sdl-ios-xcode
comparison src/thread/pth/SDL_sysmutex.c @ 329:1d74ddc90cb2
Patrice's fixes for GNU Pthread support
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 01 Apr 2002 15:35:28 +0000 |
parents | |
children | 3692456e7b0f |
comparison
equal
deleted
inserted
replaced
328:dc21fa30faa9 | 329:1d74ddc90cb2 |
---|---|
1 /* | |
2 * GNU pth mutexes | |
3 * | |
4 * Patrice Mandin | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <pth.h> | |
10 | |
11 #include "SDL_error.h" | |
12 #include "SDL_mutex.h" | |
13 #include "SDL_sysmutex_c.h" | |
14 | |
15 /* Create a mutex */ | |
16 SDL_mutex *SDL_CreateMutex(void) | |
17 { | |
18 SDL_mutex *mutex; | |
19 | |
20 /* Allocate mutex memory */ | |
21 mutex = (SDL_mutex *)malloc(sizeof(*mutex)); | |
22 if ( mutex ) { | |
23 /* Create the mutex, with initial value signaled */ | |
24 if (!pth_mutex_init(&(mutex->mutexpth_p))) { | |
25 SDL_SetError("Couldn't create mutex"); | |
26 free(mutex); | |
27 mutex = NULL; | |
28 } | |
29 } else { | |
30 SDL_OutOfMemory(); | |
31 } | |
32 return(mutex); | |
33 } | |
34 | |
35 /* Free the mutex */ | |
36 void SDL_DestroyMutex(SDL_mutex *mutex) | |
37 { | |
38 if ( mutex ) { | |
39 free(mutex); | |
40 } | |
41 } | |
42 | |
43 /* Lock the mutex */ | |
44 int SDL_mutexP(SDL_mutex *mutex) | |
45 { | |
46 if ( mutex == NULL ) { | |
47 SDL_SetError("Passed a NULL mutex"); | |
48 return -1; | |
49 } | |
50 | |
51 pth_mutex_acquire(&(mutex->mutexpth_p), FALSE, NULL); | |
52 | |
53 return(0); | |
54 } | |
55 | |
56 /* Unlock the mutex */ | |
57 int SDL_mutexV(SDL_mutex *mutex) | |
58 { | |
59 if ( mutex == NULL ) { | |
60 SDL_SetError("Passed a NULL mutex"); | |
61 return -1; | |
62 } | |
63 | |
64 pth_mutex_release(&(mutex->mutexpth_p)); | |
65 | |
66 return(0); | |
67 } |