开发者

Convert GetTickCount() vxWorks to Linux

开发者 https://www.devze.com 2023-04-12 12:40 出处:网络
I am porting some vxWorks code to Linux. I looked at this answer an开发者_如何学Pythond it recommends CLOCK_MONOTONIC. Is that a suitable replacement for the following define:

I am porting some vxWorks code to Linux.

I looked at this answer an开发者_如何学Pythond it recommends CLOCK_MONOTONIC. Is that a suitable replacement for the following define:

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

?


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号