Esempio n. 1
0
/**
 * Timed Wait
 * @param mutex the mutex that is locked
 * @param wake_up_time the time to wait up.
 * @returns true if we received a signal, false if the timeout expired.
 */
bool ConditionVariable::TimedWait(Mutex *mutex, const TimeStamp &wake_up_time) {
  struct timespec ts = {
    wake_up_time.Seconds(),
    wake_up_time.MicroSeconds() * ONE_THOUSAND
  };
  int i = pthread_cond_timedwait(&m_condition, &mutex->m_mutex, &ts);
  return i == 0;
}
Esempio n. 2
0
void InitRandom() {
  Clock clock;
  TimeStamp now;
  clock.CurrentTime(&now);

  uint64_t seed = (static_cast<uint64_t>(now.MicroSeconds()) << 32) +
                   static_cast<uint64_t>(getpid());
#ifdef HAVE_RANDOM
  generator_.seed(seed);
#elif defined(_WIN32)
  srand(seed);
#else
  srandom(seed);
#endif
}