From 39d2e9e0cb4b0f3448b5fa2104b766202a211897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20Gr=C3=B6n?= Date: Sun, 14 Jan 2018 17:23:05 +0100 Subject: [PATCH] Make some globals static that can be External linkage does not help and just encourages sloppy dependencies and can lead to weird issues when there are name collisions. --- src/asyncrpcoperation.cpp | 2 +- src/crypto/equihash.cpp | 2 +- src/main.cpp | 11 ++++++----- src/metrics.cpp | 16 ++++++++-------- src/net.cpp | 10 +++++----- src/snark/libsnark/common/profiling.cpp | 22 ++++++++++++---------- src/util.cpp | 2 +- src/zcash/JoinSplit.cpp | 3 +-- src/zcash/Proof.cpp | 2 +- 9 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/asyncrpcoperation.cpp b/src/asyncrpcoperation.cpp index f32e8d716..ff5c4cb9f 100644 --- a/src/asyncrpcoperation.cpp +++ b/src/asyncrpcoperation.cpp @@ -16,7 +16,7 @@ using namespace std; static boost::uuids::random_generator uuidgen; -std::map OperationStatusMap = { +static std::map OperationStatusMap = { {OperationStatus::READY, "queued"}, {OperationStatus::EXECUTING, "executing"}, {OperationStatus::CANCELLED, "cancelled"}, diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index d98389861..97eea42e3 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -26,7 +26,7 @@ #include -EhSolverCancelledException solver_cancelled; +static EhSolverCancelledException solver_cancelled; template int Equihash::InitialiseState(eh_HashState& base_state) diff --git a/src/main.cpp b/src/main.cpp index d8e47caac..a553a31cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ CCriticalSection cs_main; BlockMap mapBlockIndex; CChain chainActive; CBlockIndex *pindexBestHeader = NULL; -int64_t nTimeBestReceived = 0; +static int64_t nTimeBestReceived = 0; CWaitableCriticalSection csBestBlock; CConditionVariable cvBlockChange; int nScriptCheckThreads = 0; @@ -1436,9 +1436,10 @@ bool IsInitialBlockDownload() return state; } -bool fLargeWorkForkFound = false; -bool fLargeWorkInvalidChainFound = false; -CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL; +static bool fLargeWorkForkFound = false; +static bool fLargeWorkInvalidChainFound = false; +static CBlockIndex *pindexBestForkTip = NULL; +static CBlockIndex *pindexBestForkBase = NULL; void CheckForkWarningConditions() { @@ -5578,7 +5579,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle) -class CMainCleanup +static class CMainCleanup { public: CMainCleanup() {} diff --git a/src/metrics.cpp b/src/metrics.cpp index 1bac2c9c0..23f005a3e 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -64,21 +64,21 @@ double AtomicTimer::rate(const AtomicCounter& count) return duration > 0 ? (double)count.get() / duration : 0; } -CCriticalSection cs_metrics; +static CCriticalSection cs_metrics; -boost::synchronized_value nNodeStartTime; -boost::synchronized_value nNextRefresh; +static boost::synchronized_value nNodeStartTime; +static boost::synchronized_value nNextRefresh; AtomicCounter transactionsValidated; AtomicCounter ehSolverRuns; AtomicCounter solutionTargetChecks; -AtomicCounter minedBlocks; +static AtomicCounter minedBlocks; AtomicTimer miningTimer; -boost::synchronized_value> trackedBlocks; +static boost::synchronized_value> trackedBlocks; -boost::synchronized_value> messageBox; -boost::synchronized_value initMessage; -bool loaded = false; +static boost::synchronized_value> messageBox; +static boost::synchronized_value initMessage; +static bool loaded = false; extern int64_t GetNetworkHashPS(int lookup, int height); diff --git a/src/net.cpp b/src/net.cpp index 05f427707..f8ac41785 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -81,10 +81,10 @@ CCriticalSection cs_mapRelay; limitedmap mapAlreadyAskedFor(MAX_INV_SZ); static deque vOneShots; -CCriticalSection cs_vOneShots; +static CCriticalSection cs_vOneShots; -set setservAddNodeAddresses; -CCriticalSection cs_setservAddNodeAddresses; +static set setservAddNodeAddresses; +static CCriticalSection cs_setservAddNodeAddresses; vector vAddedNodes; CCriticalSection cs_vAddedNodes; @@ -93,7 +93,7 @@ NodeId nLastNodeId = 0; CCriticalSection cs_nLastNodeId; static CSemaphore *semOutbound = NULL; -boost::condition_variable messageHandlerCondition; +static boost::condition_variable messageHandlerCondition; // Signals for message handling static CNodeSignals g_signals; @@ -1779,7 +1779,7 @@ bool StopNode() return true; } -class CNetCleanup +static class CNetCleanup { public: CNetCleanup() {} diff --git a/src/snark/libsnark/common/profiling.cpp b/src/snark/libsnark/common/profiling.cpp index d227203a0..def5bc9d6 100644 --- a/src/snark/libsnark/common/profiling.cpp +++ b/src/snark/libsnark/common/profiling.cpp @@ -45,8 +45,10 @@ long long get_nsec_cpu_time() return ts.tv_sec * 1000000000ll + ts.tv_nsec; } -long long start_time, last_time; -long long start_cpu_time, last_cpu_time; +static long long start_time; +static long long last_time; +static long long start_cpu_time; +static long long last_cpu_time; void start_profiling() { @@ -57,20 +59,20 @@ void start_profiling() } std::map invocation_counts; -std::map enter_times; +static std::map enter_times; std::map last_times; std::map cumulative_times; //TODO: Instead of analogous maps for time and cpu_time, use a single struct-valued map -std::map enter_cpu_times; -std::map last_cpu_times; -std::map, long long> op_counts; -std::map, long long> cumulative_op_counts; // ((msg, data_point), value) +static std::map enter_cpu_times; +static std::map last_cpu_times; +static std::map, long long> op_counts; +static std::map, long long> cumulative_op_counts; // ((msg, data_point), value) // TODO: Convert op_counts and cumulative_op_counts from pair to structs -size_t indentation = 0; +static size_t indentation = 0; -std::vector block_names; +static std::vector block_names; -std::list > op_data_points = { +static std::list > op_data_points = { #ifdef PROFILE_OP_COUNTS std::make_pair("Fradd", &Fr::add_cnt), std::make_pair("Frsub", &Fr::sub_cnt), diff --git a/src/util.cpp b/src/util.cpp index 19c400631..1565cd8f3 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -124,7 +124,7 @@ void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAF } // Init -class CInit +static class CInit { public: CInit() diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 2685569d3..1d40813a6 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -24,8 +24,7 @@ namespace libzcash { #include "zcash/circuit/gadget.tcc" -CCriticalSection cs_ParamsIO; -CCriticalSection cs_LoadKeys; +static CCriticalSection cs_ParamsIO; template void saveToFile(const std::string path, T& obj) { diff --git a/src/zcash/Proof.cpp b/src/zcash/Proof.cpp index e7264e684..3e7e5110c 100644 --- a/src/zcash/Proof.cpp +++ b/src/zcash/Proof.cpp @@ -216,7 +216,7 @@ ZCProof ZCProof::random_invalid() return p; } -std::once_flag init_public_params_once_flag; +static std::once_flag init_public_params_once_flag; void initialize_curve_params() {