Commit d653db32 authored by Marko Mäkelä's avatar Marko Mäkelä

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.
parent 61b5e244
/*****************************************************************************
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 */
......
/*****************************************************************************
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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment