Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert GetTickCount() vxWorks to Linux

Tags:

c++

linux

vxworks

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())))

?


1 Answers

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;
}
like image 191
Robᵩ Avatar answered Feb 04 '26 16:02

Robᵩ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!