mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-06-25 22:52:52 +00:00
Fix data race conditions detected by Coverity Scan
This commit is contained in:
parent
15c6108fe4
commit
9034ce44cb
@ -164,6 +164,7 @@ bool Gr_Complex_Ip_Packet_Source::start()
|
|||||||
// open the ethernet device
|
// open the ethernet device
|
||||||
if (open() == true)
|
if (open() == true)
|
||||||
{
|
{
|
||||||
|
gr::thread::scoped_lock guard(d_setlock);
|
||||||
// start pcap capture thread
|
// start pcap capture thread
|
||||||
d_pcap_thread = new boost::thread(
|
d_pcap_thread = new boost::thread(
|
||||||
#if HAS_GENERIC_LAMBDA
|
#if HAS_GENERIC_LAMBDA
|
||||||
@ -181,6 +182,7 @@ bool Gr_Complex_Ip_Packet_Source::start()
|
|||||||
bool Gr_Complex_Ip_Packet_Source::stop()
|
bool Gr_Complex_Ip_Packet_Source::stop()
|
||||||
{
|
{
|
||||||
std::cout << "gr_complex_ip_packet_source STOP\n";
|
std::cout << "gr_complex_ip_packet_source STOP\n";
|
||||||
|
gr::thread::scoped_lock guard(d_setlock);
|
||||||
if (descr != nullptr)
|
if (descr != nullptr)
|
||||||
{
|
{
|
||||||
pcap_breakloop(descr);
|
pcap_breakloop(descr);
|
||||||
@ -294,11 +296,11 @@ void Gr_Complex_Ip_Packet_Source::pcap_callback(__attribute__((unused)) u_char *
|
|||||||
const u_char *udp_payload = (reinterpret_cast<const u_char *>(uh) + sizeof(gr_udp_header));
|
const u_char *udp_payload = (reinterpret_cast<const u_char *>(uh) + sizeof(gr_udp_header));
|
||||||
if (fifo_items <= (FIFO_SIZE - payload_length_bytes))
|
if (fifo_items <= (FIFO_SIZE - payload_length_bytes))
|
||||||
{
|
{
|
||||||
|
gr::thread::scoped_lock guard(d_setlock);
|
||||||
int aligned_write_items = FIFO_SIZE - fifo_write_ptr;
|
int aligned_write_items = FIFO_SIZE - fifo_write_ptr;
|
||||||
if (aligned_write_items >= payload_length_bytes)
|
if (aligned_write_items >= payload_length_bytes)
|
||||||
{
|
{
|
||||||
// write all in a single memcpy
|
// write all in a single memcpy
|
||||||
gr::thread::scoped_lock guard(d_setlock);
|
|
||||||
memcpy(&fifo_buff[fifo_write_ptr], &udp_payload[0], payload_length_bytes); // size in bytes
|
memcpy(&fifo_buff[fifo_write_ptr], &udp_payload[0], payload_length_bytes); // size in bytes
|
||||||
fifo_write_ptr += payload_length_bytes;
|
fifo_write_ptr += payload_length_bytes;
|
||||||
if (fifo_write_ptr == FIFO_SIZE)
|
if (fifo_write_ptr == FIFO_SIZE)
|
||||||
@ -310,7 +312,6 @@ void Gr_Complex_Ip_Packet_Source::pcap_callback(__attribute__((unused)) u_char *
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// two step wrap write
|
// two step wrap write
|
||||||
gr::thread::scoped_lock guard(d_setlock);
|
|
||||||
memcpy(&fifo_buff[fifo_write_ptr], &udp_payload[0], aligned_write_items); // size in bytes
|
memcpy(&fifo_buff[fifo_write_ptr], &udp_payload[0], aligned_write_items); // size in bytes
|
||||||
fifo_write_ptr = payload_length_bytes - aligned_write_items;
|
fifo_write_ptr = payload_length_bytes - aligned_write_items;
|
||||||
memcpy(&fifo_buff[0], &udp_payload[aligned_write_items], fifo_write_ptr); // size in bytes
|
memcpy(&fifo_buff[0], &udp_payload[aligned_write_items], fifo_write_ptr); // size in bytes
|
||||||
|
Loading…
x
Reference in New Issue
Block a user