Protect access to create_stream() with a mutex

Multiple threads may access create_stream() for the same session
simultaneously which can cause problems if the access is not protected.
This commit is contained in:
Aaro Altonen 2020-11-18 08:39:53 +02:00
parent 2d44980384
commit d61a6cf4dc
2 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
@ -47,5 +48,7 @@ namespace uvg_rtp {
/* All media streams of this session */ /* All media streams of this session */
std::unordered_map<uint32_t, uvg_rtp::media_stream *> streams_; std::unordered_map<uint32_t, uvg_rtp::media_stream *> streams_;
std::mutex session_mtx_;
}; };
}; };

View File

@ -30,6 +30,8 @@ uvg_rtp::session::~session()
uvg_rtp::media_stream *uvg_rtp::session::create_stream(int r_port, int s_port, rtp_format_t fmt, int flags) uvg_rtp::media_stream *uvg_rtp::session::create_stream(int r_port, int s_port, rtp_format_t fmt, int flags)
{ {
std::lock_guard<std::mutex> m(session_mtx_);
uvg_rtp::media_stream *stream = nullptr; uvg_rtp::media_stream *stream = nullptr;
if (flags & RCE_SYSTEM_CALL_DISPATCHER) { if (flags & RCE_SYSTEM_CALL_DISPATCHER) {