Exemple #1
0
void
NdbCondition_ComputeAbsTime(struct timespec * abstime, unsigned msecs)
{
  int secs = 0;
#ifndef NDB_WIN
#ifdef HAVE_CLOCK_GETTIME
  clock_gettime(clock_id, abstime);
#else
  {
    struct timeval tick_time;
    gettimeofday(&tick_time, 0);
    abstime->tv_sec  = tick_time.tv_sec;
    abstime->tv_nsec = tick_time.tv_usec * 1000;
  }
#endif

  if(msecs >= 1000){
    secs  = msecs / 1000;
    msecs = msecs % 1000;
  }

  abstime->tv_sec  += secs;
  abstime->tv_nsec += msecs * 1000000;
  if (abstime->tv_nsec >= 1000000000) {
    abstime->tv_sec  += 1;
    abstime->tv_nsec -= 1000000000;
  }
#else
  set_timespec_nsec(abstime,msecs*1000000ULL);
#endif
}
static DWORD get_milliseconds(const struct timespec *abstime)
{
  struct timespec current_time;
  long long ms;

  if (abstime == NULL)
    return INFINITE;

  set_timespec_nsec(current_time, 0);
  ms= (abstime->tv_sec - current_time.tv_sec)*1000LL +
    (abstime->tv_nsec - current_time.tv_nsec)/1000000LL;
  if(ms < 0 )
    ms= 0;
  if(ms > UINT_MAX)
    ms= INFINITE;
  return (DWORD)ms;
}