diff --git a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc index d5659d0dc..ae557e2d6 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/gr_complex_ip_packet_source.cc @@ -164,6 +164,7 @@ bool Gr_Complex_Ip_Packet_Source::start() // open the ethernet device if (open() == true) { + gr::thread::scoped_lock guard(d_setlock); // start pcap capture thread d_pcap_thread = new boost::thread( #if HAS_GENERIC_LAMBDA @@ -181,6 +182,7 @@ bool Gr_Complex_Ip_Packet_Source::start() bool Gr_Complex_Ip_Packet_Source::stop() { std::cout << "gr_complex_ip_packet_source STOP\n"; + gr::thread::scoped_lock guard(d_setlock); if (descr != nullptr) { 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(uh) + sizeof(gr_udp_header)); if (fifo_items <= (FIFO_SIZE - payload_length_bytes)) { + gr::thread::scoped_lock guard(d_setlock); int aligned_write_items = FIFO_SIZE - fifo_write_ptr; if (aligned_write_items >= payload_length_bytes) { // 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 fifo_write_ptr += payload_length_bytes; if (fifo_write_ptr == FIFO_SIZE) @@ -310,7 +312,6 @@ void Gr_Complex_Ip_Packet_Source::pcap_callback(__attribute__((unused)) u_char * else { // 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 fifo_write_ptr = payload_length_bytes - aligned_write_items; memcpy(&fifo_buff[0], &udp_payload[aligned_write_items], fifo_write_ptr); // size in bytes