comparison src/thread/win32/SDL_sysmutex.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents bb6839704ed6
children 99210400e8b9
comparison
equal deleted inserted replaced
1894:c69cee13dd76 1895:c121d94672cb
27 #include <windows.h> 27 #include <windows.h>
28 28
29 #include "SDL_mutex.h" 29 #include "SDL_mutex.h"
30 30
31 31
32 struct SDL_mutex { 32 struct SDL_mutex
33 HANDLE id; 33 {
34 HANDLE id;
34 }; 35 };
35 36
36 /* Create a mutex */ 37 /* Create a mutex */
37 SDL_mutex *SDL_CreateMutex(void) 38 SDL_mutex *
39 SDL_CreateMutex(void)
38 { 40 {
39 SDL_mutex *mutex; 41 SDL_mutex *mutex;
40 42
41 /* Allocate mutex memory */ 43 /* Allocate mutex memory */
42 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); 44 mutex = (SDL_mutex *) SDL_malloc(sizeof(*mutex));
43 if ( mutex ) { 45 if (mutex) {
44 /* Create the mutex, with initial value signaled */ 46 /* Create the mutex, with initial value signaled */
45 mutex->id = CreateMutex(NULL, FALSE, NULL); 47 mutex->id = CreateMutex(NULL, FALSE, NULL);
46 if ( ! mutex->id ) { 48 if (!mutex->id) {
47 SDL_SetError("Couldn't create mutex"); 49 SDL_SetError("Couldn't create mutex");
48 SDL_free(mutex); 50 SDL_free(mutex);
49 mutex = NULL; 51 mutex = NULL;
50 } 52 }
51 } else { 53 } else {
52 SDL_OutOfMemory(); 54 SDL_OutOfMemory();
53 } 55 }
54 return(mutex); 56 return (mutex);
55 } 57 }
56 58
57 /* Free the mutex */ 59 /* Free the mutex */
58 void SDL_DestroyMutex(SDL_mutex *mutex) 60 void
61 SDL_DestroyMutex(SDL_mutex * mutex)
59 { 62 {
60 if ( mutex ) { 63 if (mutex) {
61 if ( mutex->id ) { 64 if (mutex->id) {
62 CloseHandle(mutex->id); 65 CloseHandle(mutex->id);
63 mutex->id = 0; 66 mutex->id = 0;
64 } 67 }
65 SDL_free(mutex); 68 SDL_free(mutex);
66 } 69 }
67 } 70 }
68 71
69 /* Lock the mutex */ 72 /* Lock the mutex */
70 int SDL_mutexP(SDL_mutex *mutex) 73 int
74 SDL_mutexP(SDL_mutex * mutex)
71 { 75 {
72 if ( mutex == NULL ) { 76 if (mutex == NULL) {
73 SDL_SetError("Passed a NULL mutex"); 77 SDL_SetError("Passed a NULL mutex");
74 return -1; 78 return -1;
75 } 79 }
76 if ( WaitForSingleObject(mutex->id, INFINITE) == WAIT_FAILED ) { 80 if (WaitForSingleObject(mutex->id, INFINITE) == WAIT_FAILED) {
77 SDL_SetError("Couldn't wait on mutex"); 81 SDL_SetError("Couldn't wait on mutex");
78 return -1; 82 return -1;
79 } 83 }
80 return(0); 84 return (0);
81 } 85 }
82 86
83 /* Unlock the mutex */ 87 /* Unlock the mutex */
84 int SDL_mutexV(SDL_mutex *mutex) 88 int
89 SDL_mutexV(SDL_mutex * mutex)
85 { 90 {
86 if ( mutex == NULL ) { 91 if (mutex == NULL) {
87 SDL_SetError("Passed a NULL mutex"); 92 SDL_SetError("Passed a NULL mutex");
88 return -1; 93 return -1;
89 } 94 }
90 if ( ReleaseMutex(mutex->id) == FALSE ) { 95 if (ReleaseMutex(mutex->id) == FALSE) {
91 SDL_SetError("Couldn't release mutex"); 96 SDL_SetError("Couldn't release mutex");
92 return -1; 97 return -1;
93 } 98 }
94 return(0); 99 return (0);
95 } 100 }
101
102 /* vi: set ts=4 sw=4 expandtab: */