コード例 #1
0
ファイル: examsgd.c プロジェクト: alban/OpenExanodes
/**
 * Reset ping settings.
 *
 * \param[in,out] pi  Ping info
 */
static inline void
reset_ping(ping_info_t *pi)
{
  pi->delay.tv_sec  = (long)EXAMSG_BASE_KEEPALIVE_PERIOD_SEC;
  pi->delay.tv_usec =
    (EXAMSG_BASE_KEEPALIVE_PERIOD_SEC - pi->delay.tv_sec) * 1.0e6;

  EXA_ASSERT(TIMEVAL_IS_VALID(&pi->delay));
  pi->factor = 1;
}
コード例 #2
0
ファイル: examsgd.c プロジェクト: alban/OpenExanodes
/**
 * Adjust ping settings.
 *
 * \param[in,out] pi  Ping info
 */
static void
adjust_ping(ping_info_t *pi)
{
  unsigned new_factor;
  float time;

  /* Adjust the delay factor in order to slow down when no network
   * messages are sent. The check on new_factor is to ensure there
   * is no overflow */
  new_factor = pi->factor * 2;
  if (new_factor > pi->factor)
    pi->factor = new_factor;

  time = EXAMSG_BASE_KEEPALIVE_PERIOD_SEC * pi->factor;
  time = (time > EXAMSG_MAX_KEEPALIVE_PERIOD_SEC
         ? EXAMSG_MAX_KEEPALIVE_PERIOD_SEC : time);

  pi->delay.tv_sec  = time;
  pi->delay.tv_usec = (time - pi->delay.tv_sec) * 1.0e6;
  EXA_ASSERT(TIMEVAL_IS_VALID(&pi->delay));
}
コード例 #3
0
ファイル: os_semaphore.c プロジェクト: OznOg/OpenExanodes
int os_sem_waittimeout(os_sem_t * sem, int timeout_ms)
{
    struct timeval tv;
    struct timespec time;

    gettimeofday(&tv,NULL);

    tv.tv_usec += (timeout_ms % 1000) * 1000;
    tv.tv_sec += timeout_ms / 1000;
    if (tv.tv_usec >= 1000000)
    {
        tv.tv_usec -= 1000000;
        tv.tv_sec++;
    }

    OS_ASSERT(TIMEVAL_IS_VALID(&tv));

    time.tv_nsec = tv.tv_usec * 1000;
    time.tv_sec = tv.tv_sec;

    OS_ASSERT(TIMESPEC_IS_VALID(&time));

    return sem_timedwait(sem, &time) == 0 ? 0 : -errno;
}