我的代码今天突然不能工作了,可能是什么问题?以下是部分代码:
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
int32_t tnow = tp.tv_sec * 1000 + tp.tv_nsec / 1000000;
if (tnow - decoder->last_dumped >= 300) {
decoder->last_dumped = tnow;
// it was working before
...
}
tv_sec是一个有符号整数,表示秒数,所以1000 * tv_sec会溢出int32_t。使用int64_t。
在(1 <<31)毫秒,即约24.8天。