예제 #1
0
  int WaitCondition::Wait(pthread_mutex_t *lock, uint32_t msTimeout)
  {
    int ret;

    if (!m_initDone)
    {
      LogAssertFalse("waiting on uninitialized signal");
      return -1;
    }

    if (msTimeout)
    {
      struct timespec waitTime;
      clock_gettime(CLOCK_REALTIME, &waitTime);
      timespecAddMs(waitTime, msTimeout);
      ret = pthread_cond_timedwait(&m_condition, lock, &waitTime);
    }
    else
      ret = pthread_cond_wait(&m_condition, lock);

    if (ret == 0)
      return 0;
    if (ret == ETIMEDOUT)
      return 1;
    else
    {
      LogVerifyFalse("pthread_cond_wait failed");
      return -1;
    }
  }
예제 #2
0
  void WaitCondition::Signal()
  {
    if (!m_initDone)
    {
      LogAssertFalse("signaling on uninitialized signal");
      return;
    }

    LogVerify(!pthread_cond_signal(&m_condition));
  }
예제 #3
0
파일: utils.cpp 프로젝트: Lennie/OpenBFDD
  bool GetRealTime(struct timespec &now)
  {
    if (0 == clock_gettime( CLOCK_REALTIME, &now))
      return true;

    LogAssertFalse("clock_gettime failed");
    gLog.Optional(Log::Critical, "clock_gettime failed.%s", strerror(errno));
    now.tv_sec = 0;
    now.tv_nsec = 0;
    return false;
  }
예제 #4
0
파일: utils.cpp 프로젝트: JakeMont/OpenBFDD
  bool GetMonolithicTime(struct timespec &now)
  {
    if (0 == clock_gettime(CLOCK_MONOTONIC, &now))
      return true;

    LogAssertFalse("clock_gettime failed");
    gLog.Optional(Log::Critical, "clock_gettime failed.%s", ErrnoToString());
    now.tv_sec = 0;
    now.tv_nsec = 0;
    return false;
  }
예제 #5
0
TimeSpec TimeSpec::RealNow()
{
  struct TimeSpec now;

  if (0 == clock_gettime(CLOCK_REALTIME, &now))
    return now;

  gLog.Optional(Log::Critical, "clock_gettime(CLOCK_REALTIME) failed.%s", ErrnoToString());
  LogAssertFalse("clock_gettime(CLOCK_REALTIME) failed");
  return TimeSpec();
}
예제 #6
0
TimeSpec TimeSpec::MonoNow()
{
  struct TimeSpec now;

  if (0 == clock_gettime(CLOCK_MONOTONIC, &now))
    return now;

  gLog.Optional(Log::Critical, "clock_gettime(CLOCK_MONOTONIC) failed.%s", ErrnoToString());
  LogAssertFalse("clock_gettime(CLOCK_MONOTONIC) failed");
  return TimeSpec();
}
예제 #7
0
  bool QuickLock::Create()
  {
    if (!LogVerify(!m_initialized))
      return false;

    if (pthread_mutex_init(&m_Lock, NULL))
    {
      LogAssertFalse("pthread_mutex_init failed");
      return false;
    }
    m_initialized = true;
    return true;
  }
예제 #8
0
  bool ReadWriteLock::Create()
  {
    if (!LogVerify(!m_initialized))
      return false;

    if (pthread_rwlock_init(&m_Lock, NULL))
    {
      LogAssertFalse("pthread_rwlock_init failed");
      return false;
    }
    m_initialized = true;
    return true;
  }
예제 #9
0
  bool WaitCondition::Init()
  {
    if (m_initDone)
    {
      LogAssertFalse("WaitCondition::Init called more than once.");
      return true;
    }

    if (LogVerify(!pthread_cond_init(&m_condition, NULL)))
      m_initDone = true;

    return m_initDone;
  }