summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsueloverso <sue@mongodb.com>2017-05-23 14:03:20 -0400
committerAlex Gorrod <alexander.gorrod@mongodb.com>2017-06-19 17:19:59 +0000
commit89049da5f36d57585cccac275382f7fe8fc472e2 (patch)
tree450d1971e0da7245cfe4ad71ef68cbfeafe57307
parent0300f6d56cb098e22ad791b970ad4b9f968bdf77 (diff)
downloadmongo-89049da5f36d57585cccac275382f7fe8fc472e2.tar.gz
WT-3331 Get time into a local variable so we can read and use a consistent time (#3430)
-rw-r--r--src/os_posix/os_time.c21
-rw-r--r--src/os_win/os_time.c8
2 files changed, 21 insertions, 8 deletions
diff --git a/src/os_posix/os_time.c b/src/os_posix/os_time.c
index 357f12376bf..fe337fea7cf 100644
--- a/src/os_posix/os_time.c
+++ b/src/os_posix/os_time.c
@@ -16,6 +16,7 @@ void
__wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp)
WT_GCC_FUNC_ATTRIBUTE((visibility("default")))
{
+ struct timespec tmp;
WT_DECL_RET;
/*
@@ -27,24 +28,34 @@ __wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp)
tsp->tv_sec = 0;
tsp->tv_nsec = 0;
+ /*
+ * Read into a local variable so that we're comparing the correct
+ * value when we check for monotonic increasing time. There are
+ * many places we read into an unlocked global variable.
+ */
#if defined(HAVE_CLOCK_GETTIME)
- WT_SYSCALL_RETRY(clock_gettime(CLOCK_REALTIME, tsp), ret);
+ WT_SYSCALL_RETRY(clock_gettime(CLOCK_REALTIME, &tmp), ret);
if (ret == 0) {
- __wt_time_check_monotonic(session, tsp);
+ __wt_time_check_monotonic(session, &tmp);
+ tsp->tv_sec = tmp.tv_sec;
+ tsp->tv_nsec = tmp.tv_nsec;
return;
}
WT_PANIC_MSG(session, ret, "clock_gettime");
#elif defined(HAVE_GETTIMEOFDAY)
+ {
struct timeval v;
WT_SYSCALL_RETRY(gettimeofday(&v, NULL), ret);
if (ret == 0) {
- tsp->tv_sec = v.tv_sec;
- tsp->tv_nsec = v.tv_usec * WT_THOUSAND;
- __wt_time_check_monotonic(session, tsp);
+ tmp.tv_sec = v.tv_sec;
+ tmp.tv_nsec = v.tv_usec * WT_THOUSAND;
+ __wt_time_check_monotonic(session, &tmp);
+ *tsp = tmp;
return;
}
WT_PANIC_MSG(session, ret, "gettimeofday");
+ }
#else
NO TIME-OF-DAY IMPLEMENTATION: see src/os_posix/os_time.c
#endif
diff --git a/src/os_win/os_time.c b/src/os_win/os_time.c
index b070e9d7ec2..ba71341ab22 100644
--- a/src/os_win/os_time.c
+++ b/src/os_win/os_time.c
@@ -15,6 +15,7 @@
void
__wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp)
{
+ struct timespec tmp;
FILETIME time;
uint64_t ns100;
@@ -22,9 +23,10 @@ __wt_epoch(WT_SESSION_IMPL *session, struct timespec *tsp)
ns100 = (((int64_t)time.dwHighDateTime << 32) + time.dwLowDateTime)
- 116444736000000000LL;
- tsp->tv_sec = ns100 / 10000000;
- tsp->tv_nsec = (long)((ns100 % 10000000) * 100);
- __wt_time_check_monotonic(session, tsp);
+ tmp.tv_sec = ns100 / 10000000;
+ tmp.tv_nsec = (long)((ns100 % 10000000) * 100);
+ __wt_time_check_monotonic(session, &tmp);
+ *tsp = tmp;
}
/*