Skip to content

Commit 516940f

Browse files
thughescopybara-github
authored andcommitted
Fall back to the system clock when building with newlib on a system without a monotonic clock.
PiperOrigin-RevId: 493917905 Change-Id: I20137cfcda3671ffc8edcda2b6554aa392e3a00a
1 parent d454936 commit 516940f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

googletest/src/gtest.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,17 +1123,24 @@ std::string UnitTestImpl::CurrentOsStackTraceExceptTop(int skip_count) {
11231123
// A helper class for measuring elapsed times.
11241124
class Timer {
11251125
public:
1126-
Timer() : start_(std::chrono::steady_clock::now()) {}
1126+
Timer() : start_(clock::now()) {}
11271127

11281128
// Return time elapsed in milliseconds since the timer was created.
11291129
TimeInMillis Elapsed() {
11301130
return std::chrono::duration_cast<std::chrono::milliseconds>(
1131-
std::chrono::steady_clock::now() - start_)
1131+
clock::now() - start_)
11321132
.count();
11331133
}
11341134

11351135
private:
1136-
std::chrono::steady_clock::time_point start_;
1136+
// Fall back to the system_clock when building with newlib on a system
1137+
// without a monotonic clock.
1138+
#if defined(_NEWLIB_VERSION) && !defined(CLOCK_MONOTONIC)
1139+
using clock = std::chrono::system_clock;
1140+
#else
1141+
using clock = std::chrono::steady_clock;
1142+
#endif
1143+
clock::time_point start_;
11371144
};
11381145

11391146
// Returns a timestamp as milliseconds since the epoch. Note this time may jump

0 commit comments

Comments
 (0)