refactor: Use chrono type for g_mock_time

This avoids verbose casts in the lines where the symbol is used.
pull/29872/head
MarcoFalke 7 months ago
parent fa382d3dd0
commit fae0db555c
No known key found for this signature in database

@ -16,11 +16,11 @@
void UninterruptibleSleep(const std::chrono::microseconds& n) { std::this_thread::sleep_for(n); }
static std::atomic<int64_t> nMockTime(0); //!< For testing
static std::atomic<std::chrono::seconds> g_mock_time{}; //!< For testing
NodeClock::time_point NodeClock::now() noexcept
{
const std::chrono::seconds mocktime{nMockTime.load(std::memory_order_relaxed)};
const auto mocktime{g_mock_time.load(std::memory_order_relaxed)};
const auto ret{
mocktime.count() ?
mocktime :
@ -33,12 +33,12 @@ void SetMockTime(int64_t nMockTimeIn) { SetMockTime(std::chrono::seconds{nMockTi
void SetMockTime(std::chrono::seconds mock_time_in)
{
Assert(mock_time_in >= 0s);
nMockTime.store(mock_time_in.count(), std::memory_order_relaxed);
g_mock_time.store(mock_time_in, std::memory_order_relaxed);
}
std::chrono::seconds GetMockTime()
{
return std::chrono::seconds(nMockTime.load(std::memory_order_relaxed));
return g_mock_time.load(std::memory_order_relaxed);
}
int64_t GetTime() { return GetTime<std::chrono::seconds>().count(); }

Loading…
Cancel
Save