Skip to content

Commit 7212db4

Browse files
author
MarcoFalke
committed
Merge #20602: util: Allow use of C++14 chrono literals
fa11110 util: Allow use of C++14 chrono literals (MarcoFalke) Pull request description: I think we should allow the use of chrono literals for new code to make it less verbose. Obviously old code can stay as-is. This patch pulls in the needed namespace and replaces some lines for illustrative purposes. ACKs for top commit: vasild: ACK fa11110 jonatack: ACK fa11110 Tree-SHA512: ee2b72c8f28dee07b33b9a8ee8f7c87c0bc43b05c56a17b786cf9803ef204c7628e01b02de1af1a4eb01f5cdf6fc336f69c2833e17acd606ebda20ac6917e6bb
2 parents 42ed7f5 + fa11110 commit 7212db4

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

src/net.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,7 @@ class CNode
10161016
// Used for BIP35 mempool sending
10171017
bool fSendMempool GUARDED_BY(cs_tx_inventory){false};
10181018
// Last time a "MEMPOOL" request was serviced.
1019-
std::atomic<std::chrono::seconds> m_last_mempool_req{std::chrono::seconds{0}};
1019+
std::atomic<std::chrono::seconds> m_last_mempool_req{0s};
10201020
std::chrono::microseconds nNextInvSend{0};
10211021

10221022
RecursiveMutex cs_feeFilter;
@@ -1049,7 +1049,7 @@ class CNode
10491049
// The pong reply we're expecting, or 0 if no pong expected.
10501050
std::atomic<uint64_t> nPingNonceSent{0};
10511051
/** When the last ping was sent, or 0 if no ping was ever sent */
1052-
std::atomic<std::chrono::microseconds> m_ping_start{std::chrono::microseconds{0}};
1052+
std::atomic<std::chrono::microseconds> m_ping_start{0us};
10531053
// Last measured round-trip time.
10541054
std::atomic<int64_t> nPingUsecTime{0};
10551055
// Best measured round-trip time.

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4057,7 +4057,7 @@ bool PeerManager::SendMessages(CNode* pto)
40574057
// over since our last self-announcement, but there is only a small
40584058
// bandwidth cost that we can incur by doing this (which happens
40594059
// once a day on average).
4060-
if (pto->m_next_local_addr_send != std::chrono::microseconds::zero()) {
4060+
if (pto->m_next_local_addr_send != 0us) {
40614061
pto->m_addr_known->reset();
40624062
}
40634063
AdvertiseLocal(pto);

src/randomenv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void RandAddSeedPerfmon(CSHA512& hasher)
6969

7070
// This can take up to 2 seconds, so only do it every 10 minutes.
7171
// Initialize last_perfmon to 0 seconds, we don't skip the first call.
72-
static std::atomic<std::chrono::seconds> last_perfmon{std::chrono::seconds{0}};
72+
static std::atomic<std::chrono::seconds> last_perfmon{0s};
7373
auto last_time = last_perfmon.load();
7474
auto current_time = GetTime<std::chrono::seconds>();
7575
if (current_time < last_time + std::chrono::minutes{10}) return;

src/util/time.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
#ifndef BITCOIN_UTIL_TIME_H
77
#define BITCOIN_UTIL_TIME_H
88

9+
#include <chrono>
910
#include <stdint.h>
1011
#include <string>
11-
#include <chrono>
12+
13+
using namespace std::chrono_literals;
1214

1315
void UninterruptibleSleep(const std::chrono::microseconds& n);
1416

0 commit comments

Comments
 (0)