void XLockDisplay( register Display* dpy) { #ifdef XTHREADS LockDisplay(dpy); if (dpy->lock) (*dpy->lock->user_lock_display)(dpy); /* * We want the threads in the reply queue to all get out before * XLockDisplay returns, in case they have any side effects the * caller of XLockDisplay was trying to protect against. * XLockDisplay puts itself at the head of the event waiters queue * to wait for all the replies to come in. */ if (dpy->lock && dpy->lock->reply_awaiters) { struct _XCVList *cvl; cvl = (*dpy->lock->create_cvl)(dpy); /* stuff ourselves on the head of the queue */ cvl->next = dpy->lock->event_awaiters; dpy->lock->event_awaiters = cvl; while (dpy->lock->reply_awaiters) ConditionWait(dpy, cvl->cv); UnlockNextEventReader(dpy); /* pass the signal on */ } UnlockDisplay(dpy); #endif }
void GBASyncProduceAudio(struct GBASync* sync, bool wait) { if (!sync) { return; } if (sync->audioWait && wait) { // TODO loop properly in event of spurious wakeups ConditionWait(&sync->audioRequiredCond, &sync->audioBufferMutex); } MutexUnlock(&sync->audioBufferMutex); }
void GBASyncPostFrame(struct GBASync* sync) { if (!sync) { return; } MutexLock(&sync->videoFrameMutex); ++sync->videoFramePending; --sync->videoFrameSkip; if (sync->videoFrameSkip < 0) { do { ConditionWake(&sync->videoFrameAvailableCond); if (sync->videoFrameWait) { ConditionWait(&sync->videoFrameRequiredCond, &sync->videoFrameMutex); } } while (sync->videoFrameWait && sync->videoFramePending); } MutexUnlock(&sync->videoFrameMutex); }
void WorkerThread::Idle() { // decrease the active worker count AtomicDecrement(&Pool_->ActiveWorkers_); // were we the last active worker? if(AtomicRead(&Pool_->ActiveWorkers_) == 1) // notify the pool that everyone is now idle ConditionWakeAll(Pool_->AllWorkersIdle_); // wait until we get woken up by the pool, immediately unlock our locked local mutex MutexLock(TaskMutex_); ConditionWait(Pool_->WakeupNotifiction_, TaskMutex_); MutexUnlock(TaskMutex_); // increase the number of active workers AtomicIncrement(&Pool_->ActiveWorkers_); }