Skip to content

Commit fae0db5

Browse files
author
MarcoFalke
committed
refactor: Use chrono type for g_mock_time
This avoids verbose casts in the lines where the symbol is used.
1 parent fa382d3 commit fae0db5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/util/time.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); }
1818

19-
static std::atomic<int64_t> nMockTime(0); //!< For testing
19+
static std::atomic<std::chrono::seconds> g_mock_time{}; //!< For testing
2020

2121
NodeClock::time_point NodeClock::now() noexcept
2222
{
23-
const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)};
23+
const auto mocktime{g_mock_time.load(std::memory_order_relaxed)};
2424
const auto ret{
2525
mocktime.count() ?
2626
mocktime :
@@ -33,12 +33,12 @@ void SetMockTime(int64_t nMockTimeIn) { SetMockTime(std::chrono::seconds{nMockTi
3333
void SetMockTime(std::chrono::seconds mock_time_in)
3434
{
3535
Assert(mock_time_in >= 0s);
36-
nMockTime.store(mock_time_in.count(), std::memory_order_relaxed);
36+
g_mock_time.store(mock_time_in, std::memory_order_relaxed);
3737
}
3838

3939
std::chrono::seconds GetMockTime()
4040
{
41-
return std::chrono::seconds(nMockTime.load(std::memory_order_relaxed));
41+
return g_mock_time.load(std::memory_order_relaxed);
4242
}
4343

4444
int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); }

0 commit comments

Comments
 (0)