aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2013-10-19 15:55:08 +0200
committerPieter Wuille <pieter.wuille@gmail.com>2013-10-26 14:43:26 +0200
commita616206865d62106944300d7b912e3af8d357610 (patch)
tree18e4c06383c1f3ce6a2bda72857afe787fadaeef /src/util.cpp
parent0d09b3e8b0218169ab7ad2aa787c43ea11bc7060 (diff)
Give peer time-adjustment data an own lock
Instead of relying on cs_main (defined in a different module) to prevent concurrent access to it.
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 71994587cf..e098ee56c9 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -81,7 +81,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
@@ -1296,10 +1295,12 @@ void SetMockTime(int64 nMockTimeIn)
nMockTime = nMockTimeIn;
}
+static CCriticalSection cs_nTimeOffset;
static int64 nTimeOffset = 0;
int64 GetTimeOffset()
{
+ LOCK(cs_nTimeOffset);
return nTimeOffset;
}
@@ -1312,12 +1313,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)