我正在将一些 vxWorks 代码移植到 Linux。
我看了这个answer它推荐 CLOCK_MONOTONIC .这是以下定义的合适替代品吗:
#define GetTickCount() ((1000.0 * (double)tickGet())/((double)sysClkRateGet())))
?
最佳答案
GetTickCount是这样描述的 Windows API:
Retrieves the number of milliseconds that have elapsed since the system was started, up to 49.7 days
是的,CLOCK_MONOTONIC是要使用的正确 POSIX 时钟。这是未经测试的代码:
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;
}
关于c++ - 将 GetTickCount() vxWorks 转换为 Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7729686/