From 366574d921bf39a356d558ef8d61d78181a7af9b Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Thu, 23 Nov 2006 19:54:51 +0000 Subject: Use gettimeofday() to increase accuracy of GetCurrentBoxTime() on platforms which support it. Fixes busy waits for 1 second in backup client when time for next backup is not on a 1 second boundary (which it never is). (refs #3) --- configure.ac | 2 +- lib/common/BoxTime.cpp | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 8b6221a2..99165a38 100644 --- a/configure.ac +++ b/configure.ac @@ -158,7 +158,7 @@ AC_FUNC_CLOSEDIR_VOID AC_FUNC_ERROR_AT_LINE AC_TYPE_SIGNAL AC_FUNC_STAT -AC_CHECK_FUNCS([getpeereid lchown setproctitle getpid]) +AC_CHECK_FUNCS([getpeereid lchown setproctitle getpid gettimeofday]) # NetBSD implements kqueue too differently for us to get it fixed by 0.10 # TODO: Remove this when NetBSD kqueue implementation is working netbsd_hack=`echo $target_os | sed 's/netbsd.*/netbsd/'` diff --git a/lib/common/BoxTime.cpp b/lib/common/BoxTime.cpp index 960fc329..eafb244f 100644 --- a/lib/common/BoxTime.cpp +++ b/lib/common/BoxTime.cpp @@ -9,7 +9,17 @@ #include "Box.h" -#include +#ifdef HAVE_SYS_TIME_H + #include +#endif +#ifdef HAVE_TIME_H + #include +#endif +#ifdef HAVE_SYSLOG_H + #include +#endif +#include +#include #include "BoxTime.h" @@ -19,13 +29,27 @@ // // Function // Name: GetCurrentBoxTime() -// Purpose: Returns the current time as a box time. (1 sec precision) +// Purpose: Returns the current time as a box time. +// (1 sec precision, or better if supported by system) // Created: 2003/10/08 // // -------------------------------------------------------------------------- box_time_t GetCurrentBoxTime() { + #ifdef HAVE_GETTIMEOFDAY + struct timeval tv; + if (gettimeofday(&tv, NULL) != 0) + { + ::syslog(LOG_ERR, "gettimeofday() failed (%s), " + "dropping precision", strerror(errno)); + } + else + { + box_time_t timeNow = (tv.tv_sec * MICRO_SEC_IN_SEC_LL) + + tv.tv_usec; + return timeNow; + } + #endif + return SecondsToBoxTime(time(0)); } - - -- cgit v1.2.3