summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-07-23 14:40:22 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2019-07-23 15:23:27 +0300
commitd653db32f295e4a9d5fd53961f384ea427989dd5 (patch)
tree2e5a0b292c4c4bc1cf310470c6a692f3c432403e
parent61b5e244d6a2079a35d76092be132dd625aafc02 (diff)
downloadmariadb-git-d653db32f295e4a9d5fd53961f384ea427989dd5.tar.gz
MDEV-14154: Make ut_time_ms(), ut_time_us() monotonic
This is motivated by PS-5221 in percona/percona-server@2817c561fce9e20a83b13272ac45fd333467715d The coarser-precision ut_time() will still refer to the system clock, meaning that bad things can happen if the real time clock is adjusted backwards.
-rw-r--r--storage/innobase/ut/ut0ut.cc14
-rw-r--r--storage/xtradb/ut/ut0ut.cc14
2 files changed, 6 insertions, 22 deletions
diff --git a/storage/innobase/ut/ut0ut.cc b/storage/innobase/ut/ut0ut.cc
index b108fd7002e..92250bf0ebf 100644
--- a/storage/innobase/ut/ut0ut.cc
+++ b/storage/innobase/ut/ut0ut.cc
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -165,12 +166,7 @@ ut_time_us(
/*=======*/
ullint* tloc) /*!< out: us since epoch, if non-NULL */
{
- struct timeval tv;
- ullint us;
-
- ut_gettimeofday(&tv, NULL);
-
- us = (ullint) tv.tv_sec * 1000000 + tv.tv_usec;
+ ullint us = my_interval_timer() / 1000;
if (tloc != NULL) {
*tloc = us;
@@ -189,11 +185,7 @@ ulint
ut_time_ms(void)
/*============*/
{
- struct timeval tv;
-
- ut_gettimeofday(&tv, NULL);
-
- return((ulint) tv.tv_sec * 1000 + tv.tv_usec / 1000);
+ return static_cast<ulint>(my_interval_timer() / 1000000);
}
#endif /* !UNIV_HOTBACKUP */
diff --git a/storage/xtradb/ut/ut0ut.cc b/storage/xtradb/ut/ut0ut.cc
index 7b76d968e28..eda3921c5de 100644
--- a/storage/xtradb/ut/ut0ut.cc
+++ b/storage/xtradb/ut/ut0ut.cc
@@ -1,6 +1,7 @@
/*****************************************************************************
Copyright (c) 1994, 2017, Oracle and/or its affiliates. All Rights Reserved.
+Copyright (c) 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -189,12 +190,7 @@ ut_time_us(
/*=======*/
ullint* tloc) /*!< out: us since epoch, if non-NULL */
{
- struct timeval tv;
- ullint us;
-
- ut_gettimeofday(&tv, NULL);
-
- us = (ullint) tv.tv_sec * 1000000 + tv.tv_usec;
+ ullint us = my_interval_timer() / 1000;
if (tloc != NULL) {
*tloc = us;
@@ -213,11 +209,7 @@ ulint
ut_time_ms(void)
/*============*/
{
- struct timeval tv;
-
- ut_gettimeofday(&tv, NULL);
-
- return((ulint) tv.tv_sec * 1000 + tv.tv_usec / 1000);
+ return static_cast<ulint>(my_interval_timer() / 1000000);
}
#endif /* !UNIV_HOTBACKUP */