#if defined SYS_WINNT || defined SYS_CYGWIN32
static long last_Adj = 0;
+extern DWORD units_per_tick;
/*long adj_precision = (long)(HZ * 0.1); */ /* adj precision in usec (tickadj) */
#endif /* SYS_WINNT */
* and leave the remainder in dtemp */
dwTimeAdjustment = dtemp / 10;
dtemp += (double) -dwTimeAdjustment * 10.0;
- dwTimeAdjustment += PRESET_TICK;
+ dwTimeAdjustment += units_per_tick;
/* only adjust the clock if adjustment changes */
if (last_Adj != dwTimeAdjustment) {
/*
* If the clock is way off, don't tempt fate by correcting it.
*/
+#ifndef SYS_WINNT
if (fabs(fp_offset) >= clock_panic && !correct_any) {
- msyslog(LOG_ERR,
+ msyslog(LOG_ERR,
"time error %.0f over %d seconds; set clock manually)",
fp_offset, (int)clock_panic);
return (-1);
}
-
+#endif
/*
* If the clock has never been set, set it and initialize the
* discipline parameters. We then switch to frequency mode to
int status
)
{
- /* restore the clock frequency back to its original value */
- if (!SetSystemTimeAdjustment((DWORD)0, TRUE)) {
- msyslog(LOG_ERR, "Failed to reset clock frequency, SetSystemTimeAdjustment(): %m");
- }
-
if (!debug) { /* did not become a service, simply exit */
/* service mode, need to have the service_main routine
* register with the service control manager that the
-
-
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
char * set_tod_using = "SetSystemTime";
extern double drift_comp;
+DWORD units_per_tick;
+static DWORD initial_units_per_tick;
/* Windows NT versions of gettimeofday and settimeofday
*
}
else {
TicksElapsed = NowCount + 1 + ~Count; /* tick counter has wrapped around - I don't think this will ever happen*/
- msyslog(LOG_INFO, "Wraparound %m");
+ msyslog(LOG_INFO, "Wraparound %d -> %d%m", Count, NowCount);
}
DWORD WINAPI ClockThread(void *arg)
{
+
LARGE_INTEGER DueTime;
HANDLE WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL);
(void) arg; /* not used */
- /* Reset the Clock to a reasonable increment */
- SetSystemTimeAdjustment(PRESET_TICK, FALSE);
if (WaitableTimerHandle != NULL) {
DueTime.QuadPart = 0i64;
DWORD tid;
FILETIME StartTime;
LARGE_INTEGER Freq = { 0, 0 };
+ DWORD every;
+ BOOL noslew;
+ /* Reset the Clock to a reasonable increment */
+ if (!GetSystemTimeAdjustment(&initial_units_per_tick, &every, &noslew)) {
+ msyslog(LOG_ERR, "GetSystemTimeAdjustment failed: %m\n");
+ exit (-1);
+ }
+
+ units_per_tick = initial_units_per_tick;
+
+ msyslog(LOG_INFO, "Initial Clock increment %d\n",
+ units_per_tick);
/* get the performance counter freq*/
- if (QueryPerformanceFrequency(&Freq)) {
- PerfFrequency = Freq.QuadPart;
+ if (!QueryPerformanceFrequency(&Freq)) {
+ msyslog(LOG_ERR, "QueryPerformanceFrequency failed: %m\n");
+ exit (-1);
}
+ PerfFrequency = Freq.QuadPart;
+
/* init variables with the time now */
GetSystemTimeAsFileTime(&StartTime);
LastTimerTime = (((ULONGLONG) StartTime.dwHighDateTime) << 32) + (ULONGLONG) StartTime.dwLowDateTime;
DeleteCriticalSection(&TimerCritialSection);
}
+
+ /* restore the clock frequency back to its original value */
+ if (!SetSystemTimeAdjustment(initial_units_per_tick, TRUE)) {
+ msyslog(LOG_ERR, "Failed to reset clock frequency, SetSystemTimeAdjustment(): %m");
+ }
}
typedef void (__cdecl *CRuntimeFunction)(void);