3

I am porting some vxWorks code to Linux.

I looked at this answer and it recommends CLOCK_MONOTONIC. Is that a suitable replacement for the following define:

#define GetTickCount()    ((1000.0 * (double)tickGet())/((double)sysClkRateGet())))

?

Community
  • 1
  • 1

1 Answers1

11

GetTickCount is a windows API described thus:

Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days

Yes, CLOCK_MONOTONIC is the correct POSIX clock to use. Here is untested code for you:

double GetTickCount(void) 
{
  struct timespec now;
  if (clock_gettime(CLOCK_MONOTONIC, &now))
    return 0;
  return now.tv_sec * 1000.0 + now.tv_nsec / 1000000.0;
}
caf
  • 233,326
  • 40
  • 323
  • 462
Robᵩ
  • 163,533
  • 20
  • 239
  • 308