wxSemaError wxSemaphoreInternal::WaitTimeout(unsigned long milliseconds) { wxMutexLocker locker(m_mutex); wxLongLong startTime = wxGetLocalTimeMillis(); while ( m_count == 0 ) { wxLongLong elapsed = wxGetLocalTimeMillis() - startTime; long remainingTime = (long)milliseconds - (long)elapsed.GetLo(); if ( remainingTime <= 0 ) { // timeout return wxSEMA_TIMEOUT; } switch ( m_cond.WaitTimeout(remainingTime) ) { case wxCOND_TIMEOUT: return wxSEMA_TIMEOUT; default: return wxSEMA_MISC_ERROR; case wxCOND_NO_ERROR: ; } } m_count--; return wxSEMA_NO_ERROR; }
Job *JobPoolWorker::GetJob() { wxMutexLocker mutLock(*lock); Job *req(NULL); if (queue->empty()) { idleThreads++; signal->WaitTimeout(100); idleThreads--; } if ( !queue->empty() ) { req = queue->front(); queue->pop_front(); } return req; }