Convert GetTickCount() vxWorks to Linux
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;
}
精彩评论