bool QMutexPrivate::wait(int timeout) { report_error(pthread_mutex_lock(&mutex), "QMutex::lock", "mutex lock"); int errorCode = 0; while (!wakeup) { if (timeout < 0) { errorCode = pthread_cond_wait(&cond, &mutex); } else { timespec ti; qt_abstime_for_timeout(&ti, timeout); errorCode = pthread_cond_timedwait(&cond, &mutex, &ti); } if (errorCode) { if (errorCode == ETIMEDOUT) { if (wakeup) errorCode = 0; break; } report_error(errorCode, "QMutex::lock()", "cv wait"); } } bool ret = wakeup; wakeup = false; report_error(pthread_mutex_unlock(&mutex), "QMutex::lock", "mutex unlock"); return ret; }
int wait_relative(unsigned long time) { timespec ti; #ifdef Q_OS_ANDROID if (local_cond_timedwait_relative) { ti.tv_sec = time / 1000; ti.tv_nsec = time % 1000 * Q_UINT64_C(1000) * 1000; return local_cond_timedwait_relative(&cond, &mutex, &ti); } #endif qt_abstime_for_timeout(&ti, time); return pthread_cond_timedwait(&cond, &mutex, &ti); }