Skip to content

Commit

Permalink
* [Core] Fix race condition in CSampleSender::Send() #1332 (#1333)
Browse files Browse the repository at this point in the history
This PR protects the m_payload member variable and thus makes the Send() function reentrant, as it may be called simultaneously from different threads.

Co-authored-by: Florian Reimold <11774314+FlorianReimold@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 26, 2024
1 parent 480d104 commit c0d3b8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions ecal/core/src/io/snd_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace eCAL
{
if (!m_udp_sender) return(0);

std::lock_guard<std::mutex> const send_lock(m_payload_mutex);
// return value
size_t sent_sum(0);

Expand Down
2 changes: 2 additions & 0 deletions ecal/core/src/io/snd_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#pragma once

#include <memory>
#include <mutex>

#include "udp_sender.h"

Expand All @@ -47,6 +48,7 @@ namespace eCAL
SSenderAttr m_attr;

std::shared_ptr<eCAL::CUDPSender> m_udp_sender;
std::mutex m_payload_mutex;
std::vector<char> m_payload;
};
}

0 comments on commit c0d3b8f

Please sign in to comment.