comparison src/cdrom/macosx/SDLOSXCAGuard.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
90 /*============================================================================= 90 /*=============================================================================
91 SDLOSXCAGuard 91 SDLOSXCAGuard
92 =============================================================================*/ 92 =============================================================================*/
93 93
94 static int 94 static int
95 SDLOSXCAGuard_Lock (SDLOSXCAGuard * cag) 95 SDLOSXCAGuard_Lock(SDLOSXCAGuard * cag)
96 { 96 {
97 int theAnswer = 0; 97 int theAnswer = 0;
98 98
99 if (pthread_self () != cag->mOwner) { 99 if (pthread_self() != cag->mOwner) {
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 110 static void
111 SDLOSXCAGuard_Unlock (SDLOSXCAGuard * cag) 111 SDLOSXCAGuard_Unlock(SDLOSXCAGuard * cag)
112 { 112 {
113 OSStatus theError; 113 OSStatus theError;
114 assert (pthread_self () == cag->mOwner); 114 assert(pthread_self() == cag->mOwner);
115 115
116 cag->mOwner = 0; 116 cag->mOwner = 0;
117 theError = pthread_mutex_unlock (&cag->mMutex); 117 theError = pthread_mutex_unlock(&cag->mMutex);
118 (void) theError; 118 (void) theError;
119 assert (theError == 0); 119 assert(theError == 0);
120 } 120 }
121 121
122 static int 122 static int
123 SDLOSXCAGuard_Try (SDLOSXCAGuard * cag, int *outWasLocked) 123 SDLOSXCAGuard_Try(SDLOSXCAGuard * cag, int *outWasLocked)
124 { 124 {
125 int theAnswer = 0; 125 int theAnswer = 0;
126 *outWasLocked = 0; 126 *outWasLocked = 0;
127 127
128 if (pthread_self () == cag->mOwner) { 128 if (pthread_self() == cag->mOwner) {
129 theAnswer = 1; 129 theAnswer = 1;
130 *outWasLocked = 0; 130 *outWasLocked = 0;
131 } else { 131 } else {
132 OSStatus theError = pthread_mutex_trylock (&cag->mMutex); 132 OSStatus theError = pthread_mutex_trylock(&cag->mMutex);
133 if (theError == 0) { 133 if (theError == 0) {
134 cag->mOwner = pthread_self (); 134 cag->mOwner = pthread_self();
135 theAnswer = 1; 135 theAnswer = 1;
136 *outWasLocked = 1; 136 *outWasLocked = 1;
137 } 137 }
138 } 138 }
139 139
140 return theAnswer; 140 return theAnswer;
141 } 141 }
142 142
143 static void 143 static void
144 SDLOSXCAGuard_Wait (SDLOSXCAGuard * cag) 144 SDLOSXCAGuard_Wait(SDLOSXCAGuard * cag)
145 { 145 {
146 OSStatus theError; 146 OSStatus theError;
147 assert (pthread_self () == cag->mOwner); 147 assert(pthread_self() == cag->mOwner);
148 148
149 cag->mOwner = 0; 149 cag->mOwner = 0;
150 150
151 theError = pthread_cond_wait (&cag->mCondVar, &cag->mMutex); 151 theError = pthread_cond_wait(&cag->mCondVar, &cag->mMutex);
152 (void) theError; 152 (void) theError;
153 assert (theError == 0); 153 assert(theError == 0);
154 cag->mOwner = pthread_self (); 154 cag->mOwner = pthread_self();
155 } 155 }
156 156
157 static void 157 static void
158 SDLOSXCAGuard_Notify (SDLOSXCAGuard * cag) 158 SDLOSXCAGuard_Notify(SDLOSXCAGuard * cag)
159 { 159 {
160 OSStatus theError = pthread_cond_signal (&cag->mCondVar); 160 OSStatus theError = pthread_cond_signal(&cag->mCondVar);
161 (void) theError; 161 (void) theError;
162 assert (theError == 0); 162 assert(theError == 0);
163 } 163 }
164 164
165 165
166 SDLOSXCAGuard * 166 SDLOSXCAGuard *
167 new_SDLOSXCAGuard (void) 167 new_SDLOSXCAGuard(void)
168 { 168 {
169 OSStatus theError; 169 OSStatus theError;
170 SDLOSXCAGuard *cag = 170 SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof(SDLOSXCAGuard));
171 (SDLOSXCAGuard *) SDL_malloc (sizeof (SDLOSXCAGuard));
172 if (cag == NULL) 171 if (cag == NULL)
173 return NULL; 172 return NULL;
174 SDL_memset (cag, '\0', sizeof (*cag)); 173 SDL_memset(cag, '\0', sizeof(*cag));
175 174
176 #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m 175 #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m
177 SET_SDLOSXCAGUARD_METHOD (Lock); 176 SET_SDLOSXCAGUARD_METHOD(Lock);
178 SET_SDLOSXCAGUARD_METHOD (Unlock); 177 SET_SDLOSXCAGUARD_METHOD(Unlock);
179 SET_SDLOSXCAGUARD_METHOD (Try); 178 SET_SDLOSXCAGUARD_METHOD(Try);
180 SET_SDLOSXCAGUARD_METHOD (Wait); 179 SET_SDLOSXCAGUARD_METHOD(Wait);
181 SET_SDLOSXCAGUARD_METHOD (Notify); 180 SET_SDLOSXCAGUARD_METHOD(Notify);
182 #undef SET_SDLOSXCAGUARD_METHOD 181 #undef SET_SDLOSXCAGUARD_METHOD
183 182
184 theError = pthread_mutex_init (&cag->mMutex, NULL); 183 theError = pthread_mutex_init(&cag->mMutex, NULL);
185 (void) theError; 184 (void) theError;
186 assert (theError == 0); 185 assert(theError == 0);
187 186
188 theError = pthread_cond_init (&cag->mCondVar, NULL); 187 theError = pthread_cond_init(&cag->mCondVar, NULL);
189 (void) theError; 188 (void) theError;
190 assert (theError == 0); 189 assert(theError == 0);
191 190
192 cag->mOwner = 0; 191 cag->mOwner = 0;
193 return cag; 192 return cag;
194 } 193 }
195 194
196 void 195 void
197 delete_SDLOSXCAGuard (SDLOSXCAGuard * cag) 196 delete_SDLOSXCAGuard(SDLOSXCAGuard * cag)
198 { 197 {
199 if (cag != NULL) { 198 if (cag != NULL) {
200 pthread_mutex_destroy (&cag->mMutex); 199 pthread_mutex_destroy(&cag->mMutex);
201 pthread_cond_destroy (&cag->mCondVar); 200 pthread_cond_destroy(&cag->mCondVar);
202 SDL_free (cag); 201 SDL_free(cag);
203 } 202 }
204 } 203 }
205 204
206 /* vi: set ts=4 sw=4 expandtab: */ 205 /* vi: set ts=4 sw=4 expandtab: */