ngnix 时钟 ngx_gettimeofday 更新时间
2012-11-02 09:51
260 查看
ngxin 项目,有 windows 版本,之前为了优化性能,用 timeGetTime(); 获取时间。
这样导致了时钟不稳定,时钟正常跑一段时间后就不跑了,或者超时。
用 timeGetTime(); 获取返回的数值不定时出现问题。按 msdn 说,这个函数不能单独直接使用于代码运算。
http://msdn.microsoft.com/en-us/library/ms713418.aspx
timeGetTime
This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values
in computations.
这样导致了时钟不稳定,时钟正常跑一段时间后就不跑了,或者超时。
用 timeGetTime(); 获取返回的数值不定时出现问题。按 msdn 说,这个函数不能单独直接使用于代码运算。
http://msdn.microsoft.com/en-us/library/ms713418.aspx
timeGetTime
This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values
in computations.
void ngx_gettimeofday(struct timeval *tp) { #ifdef NGX_WIN32 DWORD dt = timeGetTime(); // 错误代码项 tp->tv_sec = (long) (dt / 1000); tp->tv_usec = (long) (dt*1000); #else ULONGLONG usec; FILETIME ft; SYSTEMTIME st; GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); usec = ft.dwHighDateTime; usec <<= 32; usec |= ft.dwLowDateTime; usec /= 10; usec -= 11644473600000000LL; tp->tv_sec = (long) (usec / 1000000); tp->tv_usec = (long) (usec % 1000000); #endif // NGX_WIN32 }
相关文章推荐
- linux墙上时间xtime与高精度时钟gettimeofday
- linux下得时间函数time 与gettimeofday
- php使用gettimeofday函数返回当前时间并存放在关联数组里
- 真实时间与时间间隔-gettimeofday,
- Linux时间操作(time、gettimeofday)
- Linux时间函数之gettimeofday()函数之使用方法
- Linux内核中获取时间函数do_gettimeofday
- Linux时间函数之gettimeofday()函数之使用方法
- Linux下时间输出格式精确到微秒-gettimeofday
- gettimeofday() -- 获取当前时间(保存在结构体timeval中)
- 时间编程:time(),localtime(),gmtime(),asctime(),ctime(),gettimeofday(),settimeofday()
- linux gettimeofday 时间转换成标准格式
- gettimeofday() -- 获取当前时间
- 【转】Linux时间函数之gettimeofday()函数之使用方法
- Linux 时间函数之 gettimeofday() 函数之使用方法
- 浅谈时间函数gettimeofday的成本 ——gettimeofday是由底层do_gettimeofday返回的?!
- Linux时间函数之gettimeofday()函数之使用方法
- 时间相关 time() ctime time_t localtime() gettimeofday
- 浅谈时间函数gettimeofday的成本
- C语言gettimeofday()函数:获取当前时间