Mercurial > sdl-ios-xcode
comparison src/cdrom/macosx/SDLOSXCAGuard.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 | dc6b59e925a2 |
children | 4da1ee79c9af |
comparison
equal
deleted
inserted
replaced
1661:281d3f4870e5 | 1662:782fd950bd46 |
---|---|
89 /*#warning Need a try-based Locker too*/ | 89 /*#warning Need a try-based Locker too*/ |
90 /*============================================================================= | 90 /*============================================================================= |
91 SDLOSXCAGuard | 91 SDLOSXCAGuard |
92 =============================================================================*/ | 92 =============================================================================*/ |
93 | 93 |
94 static int SDLOSXCAGuard_Lock(SDLOSXCAGuard *cag) | 94 static int |
95 SDLOSXCAGuard_Lock (SDLOSXCAGuard * cag) | |
95 { | 96 { |
96 int theAnswer = 0; | 97 int theAnswer = 0; |
97 | 98 |
98 if(pthread_self() != cag->mOwner) | 99 if (pthread_self () != cag->mOwner) { |
99 { | 100 OSStatus theError = pthread_mutex_lock (&cag->mMutex); |
100 OSStatus theError = pthread_mutex_lock(&cag->mMutex); | 101 (void) theError; |
101 (void)theError; | 102 assert (theError == 0); |
102 assert(theError == 0); | 103 cag->mOwner = pthread_self (); |
103 cag->mOwner = pthread_self(); | |
104 theAnswer = 1; | 104 theAnswer = 1; |
105 } | 105 } |
106 | 106 |
107 return theAnswer; | 107 return theAnswer; |
108 } | 108 } |
109 | 109 |
110 static void SDLOSXCAGuard_Unlock(SDLOSXCAGuard *cag) | 110 static void |
111 SDLOSXCAGuard_Unlock (SDLOSXCAGuard * cag) | |
111 { | 112 { |
112 OSStatus theError; | 113 OSStatus theError; |
113 assert(pthread_self() == cag->mOwner); | 114 assert (pthread_self () == cag->mOwner); |
114 | 115 |
115 cag->mOwner = 0; | 116 cag->mOwner = 0; |
116 theError = pthread_mutex_unlock(&cag->mMutex); | 117 theError = pthread_mutex_unlock (&cag->mMutex); |
117 (void)theError; | 118 (void) theError; |
118 assert(theError == 0); | 119 assert (theError == 0); |
119 } | 120 } |
120 | 121 |
121 static int SDLOSXCAGuard_Try (SDLOSXCAGuard *cag, int *outWasLocked) | 122 static int |
123 SDLOSXCAGuard_Try (SDLOSXCAGuard * cag, int *outWasLocked) | |
122 { | 124 { |
123 int theAnswer = 0; | 125 int theAnswer = 0; |
124 *outWasLocked = 0; | 126 *outWasLocked = 0; |
125 | 127 |
126 if (pthread_self() == cag->mOwner) { | 128 if (pthread_self () == cag->mOwner) { |
127 theAnswer = 1; | 129 theAnswer = 1; |
128 *outWasLocked = 0; | 130 *outWasLocked = 0; |
129 } else { | 131 } else { |
130 OSStatus theError = pthread_mutex_trylock(&cag->mMutex); | 132 OSStatus theError = pthread_mutex_trylock (&cag->mMutex); |
131 if (theError == 0) { | 133 if (theError == 0) { |
132 cag->mOwner = pthread_self(); | 134 cag->mOwner = pthread_self (); |
133 theAnswer = 1; | 135 theAnswer = 1; |
134 *outWasLocked = 1; | 136 *outWasLocked = 1; |
135 } | 137 } |
136 } | 138 } |
137 | 139 |
138 return theAnswer; | 140 return theAnswer; |
139 } | 141 } |
140 | 142 |
141 static void SDLOSXCAGuard_Wait(SDLOSXCAGuard *cag) | 143 static void |
144 SDLOSXCAGuard_Wait (SDLOSXCAGuard * cag) | |
142 { | 145 { |
143 OSStatus theError; | 146 OSStatus theError; |
144 assert(pthread_self() == cag->mOwner); | 147 assert (pthread_self () == cag->mOwner); |
145 | 148 |
146 cag->mOwner = 0; | 149 cag->mOwner = 0; |
147 | 150 |
148 theError = pthread_cond_wait(&cag->mCondVar, &cag->mMutex); | 151 theError = pthread_cond_wait (&cag->mCondVar, &cag->mMutex); |
149 (void)theError; | 152 (void) theError; |
150 assert(theError == 0); | 153 assert (theError == 0); |
151 cag->mOwner = pthread_self(); | 154 cag->mOwner = pthread_self (); |
152 } | 155 } |
153 | 156 |
154 static void SDLOSXCAGuard_Notify(SDLOSXCAGuard *cag) | 157 static void |
155 { | 158 SDLOSXCAGuard_Notify (SDLOSXCAGuard * cag) |
156 OSStatus theError = pthread_cond_signal(&cag->mCondVar); | 159 { |
157 (void)theError; | 160 OSStatus theError = pthread_cond_signal (&cag->mCondVar); |
158 assert(theError == 0); | 161 (void) theError; |
159 } | 162 assert (theError == 0); |
160 | 163 } |
161 | 164 |
162 SDLOSXCAGuard *new_SDLOSXCAGuard(void) | 165 |
166 SDLOSXCAGuard * | |
167 new_SDLOSXCAGuard (void) | |
163 { | 168 { |
164 OSStatus theError; | 169 OSStatus theError; |
165 SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof (SDLOSXCAGuard)); | 170 SDLOSXCAGuard *cag = |
171 (SDLOSXCAGuard *) SDL_malloc (sizeof (SDLOSXCAGuard)); | |
166 if (cag == NULL) | 172 if (cag == NULL) |
167 return NULL; | 173 return NULL; |
168 SDL_memset(cag, '\0', sizeof (*cag)); | 174 SDL_memset (cag, '\0', sizeof (*cag)); |
169 | 175 |
170 #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m | 176 #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m |
171 SET_SDLOSXCAGUARD_METHOD(Lock); | 177 SET_SDLOSXCAGUARD_METHOD (Lock); |
172 SET_SDLOSXCAGUARD_METHOD(Unlock); | 178 SET_SDLOSXCAGUARD_METHOD (Unlock); |
173 SET_SDLOSXCAGUARD_METHOD(Try); | 179 SET_SDLOSXCAGUARD_METHOD (Try); |
174 SET_SDLOSXCAGUARD_METHOD(Wait); | 180 SET_SDLOSXCAGUARD_METHOD (Wait); |
175 SET_SDLOSXCAGUARD_METHOD(Notify); | 181 SET_SDLOSXCAGUARD_METHOD (Notify); |
176 #undef SET_SDLOSXCAGUARD_METHOD | 182 #undef SET_SDLOSXCAGUARD_METHOD |
177 | 183 |
178 theError = pthread_mutex_init(&cag->mMutex, NULL); | 184 theError = pthread_mutex_init (&cag->mMutex, NULL); |
179 (void)theError; | 185 (void) theError; |
180 assert(theError == 0); | 186 assert (theError == 0); |
181 | 187 |
182 theError = pthread_cond_init(&cag->mCondVar, NULL); | 188 theError = pthread_cond_init (&cag->mCondVar, NULL); |
183 (void)theError; | 189 (void) theError; |
184 assert(theError == 0); | 190 assert (theError == 0); |
185 | 191 |
186 cag->mOwner = 0; | 192 cag->mOwner = 0; |
187 return cag; | 193 return cag; |
188 } | 194 } |
189 | 195 |
190 void delete_SDLOSXCAGuard(SDLOSXCAGuard *cag) | 196 void |
191 { | 197 delete_SDLOSXCAGuard (SDLOSXCAGuard * cag) |
192 if (cag != NULL) | 198 { |
193 { | 199 if (cag != NULL) { |
194 pthread_mutex_destroy(&cag->mMutex); | 200 pthread_mutex_destroy (&cag->mMutex); |
195 pthread_cond_destroy(&cag->mCondVar); | 201 pthread_cond_destroy (&cag->mCondVar); |
196 SDL_free(cag); | 202 SDL_free (cag); |
197 } | 203 } |
198 } | 204 } |
199 | 205 |
206 /* vi: set ts=4 sw=4 expandtab: */ |