diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2013-11-01 01:00:37 +0100 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2013-11-01 01:07:49 +0100 |
commit | 1dffbf0060912674df2b045de1c2f3691787298a (patch) | |
tree | b56d0e7ff47f434f7fd3799f9b0777bd6e12d917 /src/util.cpp | |
parent | ede3ee3348ecaeed04dec587171e732ebc0830fd (diff) | |
parent | a616206865d62106944300d7b912e3af8d357610 (diff) |
Merge pull request #3114
a616206 Give peer time-adjustment data an own lock (Pieter Wuille)
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) |