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.
voidngx_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}