From 926cd384a1f6c34b6ea62d9b078d6fad38b92758 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Thu, 2 Aug 2018 19:21:56 +0300 Subject: [PATCH] [trackink] Fix race. --- tracking/reporter.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tracking/reporter.cpp b/tracking/reporter.cpp index 77799bdd98..80250be806 100644 --- a/tracking/reporter.cpp +++ b/tracking/reporter.cpp @@ -19,6 +19,8 @@ double constexpr kRequiredHorizontalAccuracy = 10.0; double constexpr kMinDelaySeconds = 1.0; double constexpr kReconnectDelaySeconds = 40.0; double constexpr kNotChargingEventPeriod = 5 * 60.0; + +static_assert(kMinDelaySeconds != 0, ""); } // namespace namespace tracking @@ -28,18 +30,15 @@ const char Reporter::kEnableTrackingKey[] = "StatisticsEnabled"; // static milliseconds const Reporter::kPushDelayMs = milliseconds(20000); +// Set m_points size to be enough to keep all points even if one reconnect attempt failed. Reporter::Reporter(unique_ptr socket, string const & host, uint16_t port, milliseconds pushDelay) : m_allowSendingPoints(true) , m_realtimeSender(move(socket), host, port, false) , m_pushDelay(pushDelay) + , m_points(ceil(duration_cast(pushDelay).count() + kReconnectDelaySeconds) / kMinDelaySeconds) , m_thread([this] { Run(); }) { - CHECK_NOT_EQUAL(kMinDelaySeconds, 0.0, ()); - // Set buffer size to be enough to keep all points even if one reconnect attempt failed. - auto const realTimeBufferSize = - (duration_cast(m_pushDelay).count() + kReconnectDelaySeconds) / kMinDelaySeconds; - m_points.set_capacity(ceil(realTimeBufferSize)); } Reporter::~Reporter()