From 0a4f3a3df0d12b5f44e29690bfa45ea01e588f8f Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Thu, 14 Jul 2022 16:30:55 -0600 Subject: [PATCH] Apply suggestions from code review Co-authored-by: str4d Co-authored-by: Daira Hopwood --- src/rpc/misc.cpp | 3 +-- src/util/time.cpp | 2 ++ src/util/time.h | 16 ++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index cf3759c2c..f55eab30e 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -500,8 +500,7 @@ UniValue setmocktime(const UniValue& params, bool fHelp) "\nSet the local time to given timestamp (-regtest only).\n" "The node must be started with `-mocktime` in order to use this API.\n" "\nArguments:\n" - "1. timestamp (integer, required) Unix seconds-since-epoch timestamp\n" - " Pass 0 to go back to using the system time." + "1. timestamp (integer, required) Unix seconds-since-epoch timestamp." ); if (!Params().MineBlocksOnDemand()) diff --git a/src/util/time.cpp b/src/util/time.cpp index e755720e9..983d99d68 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -15,7 +15,9 @@ #include #include +// This guards accesses to FixedClock and OffsetClock. RecursiveMutex cs_clock; + static CClock* zcashdClock = SystemClock::Instance(); const CClock* GetNodeClock() { diff --git a/src/util/time.h b/src/util/time.h index 83a50d948..b0439bbbd 100644 --- a/src/util/time.h +++ b/src/util/time.h @@ -24,8 +24,8 @@ class SystemClock: public CClock { private: SystemClock() {} ~SystemClock() {} - SystemClock(SystemClock const&) = delete; - SystemClock& operator=(const SystemClock&)= delete; + SystemClock(SystemClock const&) = delete; + SystemClock& operator=(const SystemClock&) = delete; public: static SystemClock* Instance() { static SystemClock instance; @@ -33,8 +33,8 @@ public: } /** - * Sets the clock used by zcashd to the system clock. This must only be - * called by `init()`, or in tests. + * Sets the clock used by zcashd to the system clock. This is not thread-safe, + * and must only be called in a single-threaded context such as `init`. */ static void SetGlobal(); @@ -56,8 +56,8 @@ public: } /** - * Sets the clock used by zcashd to a fixed clock. This must only be used - * by `init()`, or in tests. + * Sets the clock used by zcashd to a fixed clock. This is not thread-safe + * and must only be called in a single-threaded context such as `init`. */ static void SetGlobal(); @@ -81,8 +81,8 @@ public: /** * Sets the clock used by zcashd to a clock that returns the current system - * time modified by the specified offset. This must only be called by - * `init()`, or in tests. + * time modified by the specified offset. This is not thread-safe and must + * only be called in a single-threaded context such as `init`. */ static void SetGlobal();