Lines Matching refs:cag
94 static int SDLOSXCAGuard_Lock(SDLOSXCAGuard *cag)
98 if(pthread_self() != cag->mOwner)
100 OSStatus theError = pthread_mutex_lock(&cag->mMutex);
103 cag->mOwner = pthread_self();
110 static void SDLOSXCAGuard_Unlock(SDLOSXCAGuard *cag)
113 assert(pthread_self() == cag->mOwner);
115 cag->mOwner = 0;
116 theError = pthread_mutex_unlock(&cag->mMutex);
121 static int SDLOSXCAGuard_Try (SDLOSXCAGuard *cag, int *outWasLocked)
126 if (pthread_self() == cag->mOwner) {
130 OSStatus theError = pthread_mutex_trylock(&cag->mMutex);
132 cag->mOwner = pthread_self();
141 static void SDLOSXCAGuard_Wait(SDLOSXCAGuard *cag)
144 assert(pthread_self() == cag->mOwner);
146 cag->mOwner = 0;
148 theError = pthread_cond_wait(&cag->mCondVar, &cag->mMutex);
151 cag->mOwner = pthread_self();
154 static void SDLOSXCAGuard_Notify(SDLOSXCAGuard *cag)
156 OSStatus theError = pthread_cond_signal(&cag->mCondVar);
165 SDLOSXCAGuard *cag = (SDLOSXCAGuard *) SDL_malloc(sizeof (SDLOSXCAGuard));
166 if (cag == NULL)
168 SDL_memset(cag, '\0', sizeof (*cag));
170 #define SET_SDLOSXCAGUARD_METHOD(m) cag->m = SDLOSXCAGuard_##m
178 theError = pthread_mutex_init(&cag->mMutex, NULL);
182 theError = pthread_cond_init(&cag->mCondVar, NULL);
186 cag->mOwner = 0;
187 return cag;
190 void delete_SDLOSXCAGuard(SDLOSXCAGuard *cag)
192 if (cag != NULL)
194 pthread_mutex_destroy(&cag->mMutex);
195 pthread_cond_destroy(&cag->mCondVar);
196 SDL_free(cag);