/** * Exception-throwing version of waitForTimeRelative(), called simply * wait(int64) for historical reasons. Timeout is in milliseconds. * * If the condition occurs, this function returns cleanly; on timeout or * error an exception is thrown. */ void wait(int64_t timeout_ms) { int result = waitForTimeRelative(timeout_ms); if (result == THRIFT_ETIMEDOUT) { throw TimedOutException(); } else if (result != 0) { throw TException("Monitor::wait() failed"); } }
void wait(int64_t timeout) const { // XXX Need to assert that caller owns mutex assert(timeout >= 0LL); if (timeout == 0LL) { int iret = pthread_cond_wait(&pthread_cond_, &pthread_mutex_); assert(iret == 0); } else { struct timespec abstime; int64_t now = Util::currentTime(); Util::toTimespec(abstime, now + timeout); int result = pthread_cond_timedwait(&pthread_cond_, &pthread_mutex_, &abstime); if (result == ETIMEDOUT) { // pthread_cond_timedwait has been observed to return early on // various platforms, so comment out this assert. //assert(Util::currentTime() >= (now + timeout)); throw TimedOutException(); } } }