void removeThread(Thread *pthread) { Mutex::Locker lock(&ThreadMutex); ThreadSet.Remove(pthread); if (ThreadSet.GetSize() == 0) ThreadsEmpty.Notify(); }
void finishAllThreads() { // Only original root thread can call this. OVR_ASSERT(pthread_self() == RootThreadId); Mutex::Locker lock(&ThreadMutex); while (ThreadSet.GetSize() != 0) ThreadsEmpty.Wait(&ThreadMutex); }
void WatcherThread::waitForStarted() { MutexLocker locker(&mutex); if (flags & Start) return; do { waiter.wait(&mutex); } while (!(flags & Start)); }
void WatcherThread::run() { { MutexLocker locker(&mutex); loop = CFRunLoopGetCurrent(); CFRunLoopAddSource(loop, source, kCFRunLoopCommonModes); flags |= Start; waiter.wakeOne(); } CFRunLoopRun(); }
void BBLogReplayThread::loop() { if (__logfile->has_next()) { // check if there is time left to wait __now.stamp(); __loopdiff = __now - __last_loop; if ((__offsetdiff.in_sec() - __loopdiff.in_sec()) > __cfg_grace_period) { if (__cfg_non_blocking) { // need to keep waiting before posting, but in non-blocking mode // just wait for next loop return; } else { __waittime = __offsetdiff - __loopdiff; __waittime.wait(); } } __interface->write(); __logfile->read_next(); __last_loop.stamp(); __offsetdiff = __logfile->entry_offset() - __last_offset; __last_offset = __logfile->entry_offset(); } else { if(__cfg_loop_replay){ logger->log_info(name(), "replay finished, looping"); __logfile->rewind(); } else { if (opmode() == OPMODE_CONTINUOUS) { // block logger->log_info(name(), "replay finished, sleeping"); WaitCondition waitcond; waitcond.wait(); } // else wait will just run once per loop } } }
void QuickLock::SignalAndUnlock(WaitCondition &condition) { if (!LogVerify(m_initialized)) return; condition.Signal(); // Unlocking after is safer, but may be more expensive. In the simple case it // could be unlocked before the signal. There are more complicated cases // involving multiple waiters with different expectations, where this could be a // problems. For now we err on the side of safety. UnLock(); }
wait_result ShowAndWait (const WaitCondition& waitObj, unsigned timeOutSec, const CStdString& line1) { unsigned timeOutMs = timeOutSec * 1000; if (m_dialog) { m_dialog->SetLine(1, line1); m_dialog->SetPercentage(1); // avoid flickering by starting at 1% .. } XbmcThreads::EndTime end_time (timeOutMs); while (!end_time.IsTimePast()) { if (waitObj.SuccessWaiting()) return Success; if (m_dialog) { if (!m_dialog->IsActive()) m_dialog->StartModal(); if (m_dialog->IsCanceled()) return Canceled; m_dialog->Progress(); unsigned ms_passed = timeOutMs - end_time.MillisLeft(); int percentage = (ms_passed * 100) / timeOutMs; m_dialog->SetPercentage(max(percentage, 1)); // avoid flickering , keep minimum 1% } Sleep (m_dialog ? 20 : 200); } return TimedOut; }
int QuickLock::LockWait(WaitCondition &condition, uint32_t msTimeout) { if (!LogVerify(m_initialized)) return -1; return condition.Wait(&m_Lock, msTimeout); }