Lines Matching refs:cond

44 	SDL_cond *cond;
46 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
47 if ( cond ) {
48 cond->lock = SDL_CreateMutex();
49 cond->wait_sem = SDL_CreateSemaphore(0);
50 cond->wait_done = SDL_CreateSemaphore(0);
51 cond->waiting = cond->signals = 0;
52 if ( ! cond->lock || ! cond->wait_sem || ! cond->wait_done ) {
53 SDL_DestroyCond(cond);
54 cond = NULL;
59 return(cond);
63 DECLSPEC void SDLCALL SDL_DestroyCond(SDL_cond *cond)
65 if ( cond ) {
66 if ( cond->wait_sem ) {
67 SDL_DestroySemaphore(cond->wait_sem);
69 if ( cond->wait_done ) {
70 SDL_DestroySemaphore(cond->wait_done);
72 if ( cond->lock ) {
73 SDL_DestroyMutex(cond->lock);
75 SDL_free(cond);
80 DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond *cond)
82 if ( ! cond ) {
90 SDL_LockMutex(cond->lock);
91 if ( cond->waiting > cond->signals ) {
92 ++cond->signals;
93 SDL_SemPost(cond->wait_sem);
94 SDL_UnlockMutex(cond->lock);
95 SDL_SemWait(cond->wait_done);
97 SDL_UnlockMutex(cond->lock);
104 DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond)
106 if ( ! cond ) {
114 SDL_LockMutex(cond->lock);
115 if ( cond->waiting > cond->signals ) {
118 num_waiting = (cond->waiting - cond->signals);
119 cond->signals = cond->waiting;
121 SDL_SemPost(cond->wait_sem);
126 SDL_UnlockMutex(cond->lock);
128 SDL_SemWait(cond->wait_done);
131 SDL_UnlockMutex(cond->lock);
146 SDL_CondWait(cond);
157 DECLSPEC int SDLCALL SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
161 if ( ! cond ) {
170 SDL_LockMutex(cond->lock);
171 ++cond->waiting;
172 SDL_UnlockMutex(cond->lock);
179 retval = SDL_SemWait(cond->wait_sem);
181 retval = SDL_SemWaitTimeout(cond->wait_sem, ms);
190 SDL_LockMutex(cond->lock);
191 if ( cond->signals > 0 ) {
194 SDL_SemWait(cond->wait_sem);
197 SDL_SemPost(cond->wait_done);
200 --cond->signals;
202 --cond->waiting;
203 SDL_UnlockMutex(cond->lock);
212 DECLSPEC int SDLCALL SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
214 return SDL_CondWaitTimeout(cond, mutex, SDL_MUTEX_MAXWAIT);