File tree Expand file tree Collapse file tree 1 file changed +5
-0
lines changed
include/cpp-statsd-client Expand file tree Collapse file tree 1 file changed +5
-0
lines changed Original file line number Diff line number Diff line change 66#include < cstdio>
77#include < iomanip>
88#include < memory>
9+ #include < mutex>
910#include < random>
1011#include < sstream>
1112#include < string>
@@ -165,6 +166,9 @@ class StatsdClient {
165166 // ! The buffer string format our stats before sending them
166167 mutable std::string m_buffer;
167168
169+ // ! The mutex to lock m_buffer
170+ mutable std::mutex m_buffer_mutex;
171+
168172 // ! Fixed floating point precision of gauges
169173 int m_gaugePrecision;
170174};
@@ -291,6 +295,7 @@ inline void StatsdClient::send(const std::string& key,
291295 std::stringstream valueStream;
292296 valueStream << std::fixed << std::setprecision (m_gaugePrecision) << value;
293297
298+ std::lock_guard<std::mutex> buffer_lock (m_buffer_mutex);
294299 m_buffer.clear ();
295300
296301 m_buffer.append (m_prefix);
You can’t perform that action at this time.
0 commit comments