diff options
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp index 9ee1ad5f52..085df8a7d5 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -80,7 +80,6 @@ bool fServer = false; string strMiscWarning; bool fNoListen = false; bool fLogTimestamps = false; -CMedianFilter<int64> vTimeOffsets(200,0); volatile bool fReopenDebugLog = false; // Init OpenSSL library multithreading support @@ -1305,10 +1304,12 @@ void SetMockTime(int64 nMockTimeIn) nMockTime = nMockTimeIn; } +static CCriticalSection cs_nTimeOffset; static int64 nTimeOffset = 0; int64 GetTimeOffset() { + LOCK(cs_nTimeOffset); return nTimeOffset; } @@ -1321,12 +1322,14 @@ void AddTimeData(const CNetAddr& ip, int64 nTime) { int64 nOffsetSample = nTime - GetTime(); + LOCK(cs_nTimeOffset); // Ignore duplicates static set<CNetAddr> setKnown; if (!setKnown.insert(ip).second) return; // Add data + static CMedianFilter<int64> vTimeOffsets(200,0); vTimeOffsets.input(nOffsetSample); LogPrintf("Added time data, samples %d, offset %+"PRI64d" (%+"PRI64d" minutes)\n", vTimeOffsets.size(), nOffsetSample, nOffsetSample/60); if (vTimeOffsets.size() >= 5 && vTimeOffsets.size() % 2 == 1) |