diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2025-09-29 14:48:05 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2025-09-29 14:48:05 +0200 |
commit | 2cbf5fdbe6ee5b12c30aee7ece7375a37448546f (patch) | |
tree | 00ed2df8f7bf2211a11f9b9d92fe6e91c84c2e45 | |
parent | cd93ca37c7a9688e1a1273d62623b2b9e17b36ca (diff) | |
download | ODR-AudioEnc-2cbf5fdbe6ee5b12c30aee7ece7375a37448546f.tar.gz ODR-AudioEnc-2cbf5fdbe6ee5b12c30aee7ece7375a37448546f.tar.bz2 ODR-AudioEnc-2cbf5fdbe6ee5b12c30aee7ece7375a37448546f.zip |
common 53fdfd2: Fix race condition in TCPDataDispatcher get_statsnext
-rw-r--r-- | contrib/Socket.cpp | 1 | ||||
-rw-r--r-- | contrib/Socket.h | 2 | ||||
-rw-r--r-- | contrib/ThreadsafeQueue.h | 2 |
3 files changed, 3 insertions, 2 deletions
diff --git a/contrib/Socket.cpp b/contrib/Socket.cpp index 5c920d7..33c9c73 100644 --- a/contrib/Socket.cpp +++ b/contrib/Socket.cpp @@ -1152,6 +1152,7 @@ void TCPDataDispatcher::process() std::vector<TCPConnection::stats_t> TCPDataDispatcher::get_stats() const { std::vector<TCPConnection::stats_t> s; + auto lock = unique_lock<mutex>(m_mutex); for (const auto& conn : m_connections) { s.push_back(conn.get_stats()); } diff --git a/contrib/Socket.h b/contrib/Socket.h index 29b618a..b9a40ee 100644 --- a/contrib/Socket.h +++ b/contrib/Socket.h @@ -298,7 +298,7 @@ class TCPDataDispatcher std::thread m_listener_thread; TCPSocket m_listener_socket; - std::mutex m_mutex; + mutable std::mutex m_mutex; std::deque<std::vector<uint8_t> > m_preroll_queue; std::list<TCPConnection> m_connections; }; diff --git a/contrib/ThreadsafeQueue.h b/contrib/ThreadsafeQueue.h index 13bc19e..a8d2e85 100644 --- a/contrib/ThreadsafeQueue.h +++ b/contrib/ThreadsafeQueue.h @@ -31,7 +31,7 @@ #include <functional> #include <mutex> #include <condition_variable> -#include <queue> +#include <deque> #include <utility> #include <cassert> |