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.
This commit is contained in:
Per Grön 2018-01-14 17:23:05 +01:00
parent 38246ea461
commit 39d2e9e0cb
9 changed files with 36 additions and 34 deletions

View File

@ -16,7 +16,7 @@ using namespace std;
static boost::uuids::random_generator uuidgen; static boost::uuids::random_generator uuidgen;
std::map<OperationStatus, std::string> OperationStatusMap = { static std::map<OperationStatus, std::string> OperationStatusMap = {
{OperationStatus::READY, "queued"}, {OperationStatus::READY, "queued"},
{OperationStatus::EXECUTING, "executing"}, {OperationStatus::EXECUTING, "executing"},
{OperationStatus::CANCELLED, "cancelled"}, {OperationStatus::CANCELLED, "cancelled"},

View File

@ -26,7 +26,7 @@
#include <boost/optional.hpp> #include <boost/optional.hpp>
EhSolverCancelledException solver_cancelled; static EhSolverCancelledException solver_cancelled;
template<unsigned int N, unsigned int K> template<unsigned int N, unsigned int K>
int Equihash<N,K>::InitialiseState(eh_HashState& base_state) int Equihash<N,K>::InitialiseState(eh_HashState& base_state)

View File

@ -54,7 +54,7 @@ CCriticalSection cs_main;
BlockMap mapBlockIndex; BlockMap mapBlockIndex;
CChain chainActive; CChain chainActive;
CBlockIndex *pindexBestHeader = NULL; CBlockIndex *pindexBestHeader = NULL;
int64_t nTimeBestReceived = 0; static int64_t nTimeBestReceived = 0;
CWaitableCriticalSection csBestBlock; CWaitableCriticalSection csBestBlock;
CConditionVariable cvBlockChange; CConditionVariable cvBlockChange;
int nScriptCheckThreads = 0; int nScriptCheckThreads = 0;
@ -1436,9 +1436,10 @@ bool IsInitialBlockDownload()
return state; return state;
} }
bool fLargeWorkForkFound = false; static bool fLargeWorkForkFound = false;
bool fLargeWorkInvalidChainFound = false; static bool fLargeWorkInvalidChainFound = false;
CBlockIndex *pindexBestForkTip = NULL, *pindexBestForkBase = NULL; static CBlockIndex *pindexBestForkTip = NULL;
static CBlockIndex *pindexBestForkBase = NULL;
void CheckForkWarningConditions() void CheckForkWarningConditions()
{ {
@ -5578,7 +5579,7 @@ bool SendMessages(CNode* pto, bool fSendTrickle)
class CMainCleanup static class CMainCleanup
{ {
public: public:
CMainCleanup() {} CMainCleanup() {}

View File

@ -64,21 +64,21 @@ double AtomicTimer::rate(const AtomicCounter& count)
return duration > 0 ? (double)count.get() / duration : 0; return duration > 0 ? (double)count.get() / duration : 0;
} }
CCriticalSection cs_metrics; static CCriticalSection cs_metrics;
boost::synchronized_value<int64_t> nNodeStartTime; static boost::synchronized_value<int64_t> nNodeStartTime;
boost::synchronized_value<int64_t> nNextRefresh; static boost::synchronized_value<int64_t> nNextRefresh;
AtomicCounter transactionsValidated; AtomicCounter transactionsValidated;
AtomicCounter ehSolverRuns; AtomicCounter ehSolverRuns;
AtomicCounter solutionTargetChecks; AtomicCounter solutionTargetChecks;
AtomicCounter minedBlocks; static AtomicCounter minedBlocks;
AtomicTimer miningTimer; AtomicTimer miningTimer;
boost::synchronized_value<std::list<uint256>> trackedBlocks; static boost::synchronized_value<std::list<uint256>> trackedBlocks;
boost::synchronized_value<std::list<std::string>> messageBox; static boost::synchronized_value<std::list<std::string>> messageBox;
boost::synchronized_value<std::string> initMessage; static boost::synchronized_value<std::string> initMessage;
bool loaded = false; static bool loaded = false;
extern int64_t GetNetworkHashPS(int lookup, int height); extern int64_t GetNetworkHashPS(int lookup, int height);

View File

@ -81,10 +81,10 @@ CCriticalSection cs_mapRelay;
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ); limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
static deque<string> vOneShots; static deque<string> vOneShots;
CCriticalSection cs_vOneShots; static CCriticalSection cs_vOneShots;
set<CNetAddr> setservAddNodeAddresses; static set<CNetAddr> setservAddNodeAddresses;
CCriticalSection cs_setservAddNodeAddresses; static CCriticalSection cs_setservAddNodeAddresses;
vector<std::string> vAddedNodes; vector<std::string> vAddedNodes;
CCriticalSection cs_vAddedNodes; CCriticalSection cs_vAddedNodes;
@ -93,7 +93,7 @@ NodeId nLastNodeId = 0;
CCriticalSection cs_nLastNodeId; CCriticalSection cs_nLastNodeId;
static CSemaphore *semOutbound = NULL; static CSemaphore *semOutbound = NULL;
boost::condition_variable messageHandlerCondition; static boost::condition_variable messageHandlerCondition;
// Signals for message handling // Signals for message handling
static CNodeSignals g_signals; static CNodeSignals g_signals;
@ -1779,7 +1779,7 @@ bool StopNode()
return true; return true;
} }
class CNetCleanup static class CNetCleanup
{ {
public: public:
CNetCleanup() {} CNetCleanup() {}

View File

@ -45,8 +45,10 @@ long long get_nsec_cpu_time()
return ts.tv_sec * 1000000000ll + ts.tv_nsec; return ts.tv_sec * 1000000000ll + ts.tv_nsec;
} }
long long start_time, last_time; static long long start_time;
long long start_cpu_time, last_cpu_time; static long long last_time;
static long long start_cpu_time;
static long long last_cpu_time;
void start_profiling() void start_profiling()
{ {
@ -57,20 +59,20 @@ void start_profiling()
} }
std::map<std::string, size_t> invocation_counts; std::map<std::string, size_t> invocation_counts;
std::map<std::string, long long> enter_times; static std::map<std::string, long long> enter_times;
std::map<std::string, long long> last_times; std::map<std::string, long long> last_times;
std::map<std::string, long long> cumulative_times; std::map<std::string, long long> cumulative_times;
//TODO: Instead of analogous maps for time and cpu_time, use a single struct-valued map //TODO: Instead of analogous maps for time and cpu_time, use a single struct-valued map
std::map<std::string, long long> enter_cpu_times; static std::map<std::string, long long> enter_cpu_times;
std::map<std::string, long long> last_cpu_times; static std::map<std::string, long long> last_cpu_times;
std::map<std::pair<std::string, std::string>, long long> op_counts; static std::map<std::pair<std::string, std::string>, long long> op_counts;
std::map<std::pair<std::string, std::string>, long long> cumulative_op_counts; // ((msg, data_point), value) static std::map<std::pair<std::string, std::string>, long long> cumulative_op_counts; // ((msg, data_point), value)
// TODO: Convert op_counts and cumulative_op_counts from pair to structs // TODO: Convert op_counts and cumulative_op_counts from pair to structs
size_t indentation = 0; static size_t indentation = 0;
std::vector<std::string> block_names; static std::vector<std::string> block_names;
std::list<std::pair<std::string, long long*> > op_data_points = { static std::list<std::pair<std::string, long long*> > op_data_points = {
#ifdef PROFILE_OP_COUNTS #ifdef PROFILE_OP_COUNTS
std::make_pair("Fradd", &Fr<default_ec_pp>::add_cnt), std::make_pair("Fradd", &Fr<default_ec_pp>::add_cnt),
std::make_pair("Frsub", &Fr<default_ec_pp>::sub_cnt), std::make_pair("Frsub", &Fr<default_ec_pp>::sub_cnt),

View File

@ -124,7 +124,7 @@ void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAF
} }
// Init // Init
class CInit static class CInit
{ {
public: public:
CInit() CInit()

View File

@ -24,8 +24,7 @@ namespace libzcash {
#include "zcash/circuit/gadget.tcc" #include "zcash/circuit/gadget.tcc"
CCriticalSection cs_ParamsIO; static CCriticalSection cs_ParamsIO;
CCriticalSection cs_LoadKeys;
template<typename T> template<typename T>
void saveToFile(const std::string path, T& obj) { void saveToFile(const std::string path, T& obj) {

View File

@ -216,7 +216,7 @@ ZCProof ZCProof::random_invalid()
return p; return p;
} }
std::once_flag init_public_params_once_flag; static std::once_flag init_public_params_once_flag;
void initialize_curve_params() void initialize_curve_params()
{ {