Mercurial > sdl-ios-xcode
comparison src/thread/os2/SDL_sysmutex.c @ 1662:782fd950bd46 SDL-1.3
Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid.
The code is now run through a consistent indent format:
indent -i4 -nut -nsc -br -ce
The headers are being converted to automatically generate doxygen documentation.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 28 May 2006 13:04:16 +0000 |
parents | d910939febfa |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
28 #include <os2.h> | 28 #include <os2.h> |
29 | 29 |
30 #include "SDL_mutex.h" | 30 #include "SDL_mutex.h" |
31 | 31 |
32 | 32 |
33 struct SDL_mutex { | 33 struct SDL_mutex |
34 HMTX hmtxID; | 34 { |
35 HMTX hmtxID; | |
35 }; | 36 }; |
36 | 37 |
37 /* Create a mutex */ | 38 /* Create a mutex */ |
38 DECLSPEC SDL_mutex * SDLCALL SDL_CreateMutex(void) | 39 DECLSPEC SDL_mutex *SDLCALL |
40 SDL_CreateMutex (void) | |
39 { | 41 { |
40 SDL_mutex *mutex; | 42 SDL_mutex *mutex; |
41 APIRET ulrc; | 43 APIRET ulrc; |
42 | 44 |
43 /* Allocate mutex memory */ | 45 /* Allocate mutex memory */ |
44 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex)); | 46 mutex = (SDL_mutex *) SDL_malloc (sizeof (*mutex)); |
45 if (mutex) | 47 if (mutex) { |
46 { | 48 /* Create the mutex, with initial value signaled */ |
47 /* Create the mutex, with initial value signaled */ | 49 ulrc = DosCreateMutexSem (NULL, // Create unnamed semaphore |
48 ulrc = DosCreateMutexSem(NULL, // Create unnamed semaphore | 50 &(mutex->hmtxID), // Pointer to handle |
49 &(mutex->hmtxID), // Pointer to handle | 51 0L, // Flags: create it private (not shared) |
50 0L, // Flags: create it private (not shared) | 52 FALSE); // Initial value: unowned |
51 FALSE); // Initial value: unowned | 53 if (ulrc != NO_ERROR) { |
52 if (ulrc!=NO_ERROR) | 54 SDL_SetError ("Couldn't create mutex"); |
53 { | 55 SDL_free (mutex); |
54 SDL_SetError("Couldn't create mutex"); | 56 mutex = NULL; |
55 SDL_free(mutex); | 57 } |
56 mutex = NULL; | 58 } else { |
59 SDL_OutOfMemory (); | |
57 } | 60 } |
58 } else { | 61 return (mutex); |
59 SDL_OutOfMemory(); | |
60 } | |
61 return(mutex); | |
62 } | 62 } |
63 | 63 |
64 /* Free the mutex */ | 64 /* Free the mutex */ |
65 DECLSPEC void SDLCALL SDL_DestroyMutex(SDL_mutex *mutex) | 65 DECLSPEC void SDLCALL |
66 SDL_DestroyMutex (SDL_mutex * mutex) | |
66 { | 67 { |
67 if ( mutex ) | 68 if (mutex) { |
68 { | 69 if (mutex->hmtxID) { |
69 if ( mutex->hmtxID ) | 70 DosCloseMutexSem (mutex->hmtxID); |
70 { | 71 mutex->hmtxID = 0; |
71 DosCloseMutexSem(mutex->hmtxID); | 72 } |
72 mutex->hmtxID = 0; | 73 SDL_free (mutex); |
73 } | 74 } |
74 SDL_free(mutex); | |
75 } | |
76 } | 75 } |
77 | 76 |
78 /* Lock the mutex */ | 77 /* Lock the mutex */ |
79 DECLSPEC int SDLCALL SDL_mutexP(SDL_mutex *mutex) | 78 DECLSPEC int SDLCALL |
79 SDL_mutexP (SDL_mutex * mutex) | |
80 { | 80 { |
81 if ( mutex == NULL ) | 81 if (mutex == NULL) { |
82 { | 82 SDL_SetError ("Passed a NULL mutex"); |
83 SDL_SetError("Passed a NULL mutex"); | 83 return -1; |
84 return -1; | 84 } |
85 } | 85 if (DosRequestMutexSem (mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR) { |
86 if ( DosRequestMutexSem(mutex->hmtxID, SEM_INDEFINITE_WAIT) != NO_ERROR ) | 86 SDL_SetError ("Couldn't wait on mutex"); |
87 { | 87 return -1; |
88 SDL_SetError("Couldn't wait on mutex"); | 88 } |
89 return -1; | 89 return (0); |
90 } | |
91 return(0); | |
92 } | 90 } |
93 | 91 |
94 /* Unlock the mutex */ | 92 /* Unlock the mutex */ |
95 DECLSPEC int SDLCALL SDL_mutexV(SDL_mutex *mutex) | 93 DECLSPEC int SDLCALL |
94 SDL_mutexV (SDL_mutex * mutex) | |
96 { | 95 { |
97 if ( mutex == NULL ) | 96 if (mutex == NULL) { |
98 { | 97 SDL_SetError ("Passed a NULL mutex"); |
99 SDL_SetError("Passed a NULL mutex"); | 98 return -1; |
100 return -1; | 99 } |
101 } | 100 if (DosReleaseMutexSem (mutex->hmtxID) != NO_ERROR) { |
102 if ( DosReleaseMutexSem(mutex->hmtxID) != NO_ERROR ) | 101 SDL_SetError ("Couldn't release mutex"); |
103 { | 102 return -1; |
104 SDL_SetError("Couldn't release mutex"); | 103 } |
105 return -1; | 104 return (0); |
106 } | |
107 return(0); | |
108 } | 105 } |
106 | |
107 /* vi: set ts=4 sw=4 expandtab: */ |