• Home
  • Raw
  • Download

Lines Matching refs:cond

171 static void impl_cond_do_signal(cnd_t *cond, int broadcast)  in impl_cond_do_signal()  argument
175 EnterCriticalSection(&cond->monitor); in impl_cond_do_signal()
176 if (cond->to_unblock != 0) { in impl_cond_do_signal()
177 if (cond->blocked == 0) { in impl_cond_do_signal()
178 LeaveCriticalSection(&cond->monitor); in impl_cond_do_signal()
182 cond->to_unblock += nsignal = cond->blocked; in impl_cond_do_signal()
183 cond->blocked = 0; in impl_cond_do_signal()
186 cond->to_unblock++; in impl_cond_do_signal()
187 cond->blocked--; in impl_cond_do_signal()
189 } else if (cond->blocked > cond->gone) { in impl_cond_do_signal()
190 WaitForSingleObject(cond->sem_gate, INFINITE); in impl_cond_do_signal()
191 if (cond->gone != 0) { in impl_cond_do_signal()
192 cond->blocked -= cond->gone; in impl_cond_do_signal()
193 cond->gone = 0; in impl_cond_do_signal()
196 nsignal = cond->to_unblock = cond->blocked; in impl_cond_do_signal()
197 cond->blocked = 0; in impl_cond_do_signal()
199 nsignal = cond->to_unblock = 1; in impl_cond_do_signal()
200 cond->blocked--; in impl_cond_do_signal()
203 LeaveCriticalSection(&cond->monitor); in impl_cond_do_signal()
206 ReleaseSemaphore(cond->sem_queue, nsignal, NULL); in impl_cond_do_signal()
209 static int impl_cond_do_wait(cnd_t *cond, mtx_t *mtx, const xtime *xt) in impl_cond_do_wait() argument
216 WaitForSingleObject(cond->sem_gate, INFINITE); in impl_cond_do_wait()
217 cond->blocked++; in impl_cond_do_wait()
218 ReleaseSemaphore(cond->sem_gate, 1, NULL); in impl_cond_do_wait()
222 w = WaitForSingleObject(cond->sem_queue, xt ? impl_xtime2msec(xt) : INFINITE); in impl_cond_do_wait()
225 EnterCriticalSection(&cond->monitor); in impl_cond_do_wait()
226 if ((nleft = cond->to_unblock) != 0) { in impl_cond_do_wait()
228 if (cond->blocked != 0) { in impl_cond_do_wait()
229 cond->blocked--; in impl_cond_do_wait()
231 cond->gone++; in impl_cond_do_wait()
234 if (--cond->to_unblock == 0) { in impl_cond_do_wait()
235 if (cond->blocked != 0) { in impl_cond_do_wait()
236 ReleaseSemaphore(cond->sem_gate, 1, NULL); in impl_cond_do_wait()
239 else if ((ngone = cond->gone) != 0) { in impl_cond_do_wait()
240 cond->gone = 0; in impl_cond_do_wait()
243 } else if (++cond->gone == INT_MAX/2) { in impl_cond_do_wait()
244 WaitForSingleObject(cond->sem_gate, INFINITE); in impl_cond_do_wait()
245 cond->blocked -= cond->gone; in impl_cond_do_wait()
246 ReleaseSemaphore(cond->sem_gate, 1, NULL); in impl_cond_do_wait()
247 cond->gone = 0; in impl_cond_do_wait()
249 LeaveCriticalSection(&cond->monitor); in impl_cond_do_wait()
253 WaitForSingleObject(cond->sem_queue, INFINITE); in impl_cond_do_wait()
254 ReleaseSemaphore(cond->sem_gate, 1, NULL); in impl_cond_do_wait()
323 cnd_broadcast(cnd_t *cond) in cnd_broadcast() argument
325 if (!cond) return thrd_error; in cnd_broadcast()
327 WakeAllConditionVariable(&cond->condvar); in cnd_broadcast()
329 impl_cond_do_signal(cond, 1); in cnd_broadcast()
336 cnd_destroy(cnd_t *cond) in cnd_destroy() argument
338 assert(cond); in cnd_destroy()
342 CloseHandle(cond->sem_queue); in cnd_destroy()
343 CloseHandle(cond->sem_gate); in cnd_destroy()
344 DeleteCriticalSection(&cond->monitor); in cnd_destroy()
350 cnd_init(cnd_t *cond) in cnd_init() argument
352 if (!cond) return thrd_error; in cnd_init()
354 InitializeConditionVariable(&cond->condvar); in cnd_init()
356 cond->blocked = 0; in cnd_init()
357 cond->gone = 0; in cnd_init()
358 cond->to_unblock = 0; in cnd_init()
359 cond->sem_queue = CreateSemaphore(NULL, 0, LONG_MAX, NULL); in cnd_init()
360 cond->sem_gate = CreateSemaphore(NULL, 1, 1, NULL); in cnd_init()
361 InitializeCriticalSection(&cond->monitor); in cnd_init()
368 cnd_signal(cnd_t *cond) in cnd_signal() argument
370 if (!cond) return thrd_error; in cnd_signal()
372 WakeConditionVariable(&cond->condvar); in cnd_signal()
374 impl_cond_do_signal(cond, 0); in cnd_signal()
381 cnd_timedwait(cnd_t *cond, mtx_t *mtx, const xtime *xt) in cnd_timedwait() argument
383 if (!cond || !mtx || !xt) return thrd_error; in cnd_timedwait()
385 if (SleepConditionVariableCS(&cond->condvar, mtx, impl_xtime2msec(xt))) in cnd_timedwait()
389 return impl_cond_do_wait(cond, mtx, xt); in cnd_timedwait()
395 cnd_wait(cnd_t *cond, mtx_t *mtx) in cnd_wait() argument
397 if (!cond || !mtx) return thrd_error; in cnd_wait()
399 SleepConditionVariableCS(&cond->condvar, mtx, INFINITE); in cnd_wait()
401 impl_cond_do_wait(cond, mtx, NULL); in cnd_wait()