From 97b004131ad7cdd1daaac091bce1dcf6fd12ccaa Mon Sep 17 00:00:00 2001 From: Ashish Chaudhari Date: Tue, 4 Jun 2019 13:46:35 -0700 Subject: rfnoc: Fixed race condition in chdr_ctrl_endpoint The lock acquired by send_fn does not need to share the same mutex as the rest of the class. It only needs to serialize between multiple calls to send_fn. Gave send_fn it's own mutex for that reason --- host/lib/rfnoc/chdr_ctrl_endpoint.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/host/lib/rfnoc/chdr_ctrl_endpoint.cpp b/host/lib/rfnoc/chdr_ctrl_endpoint.cpp index 5761cd0d7..d1d1dccca 100644 --- a/host/lib/rfnoc/chdr_ctrl_endpoint.cpp +++ b/host/lib/rfnoc/chdr_ctrl_endpoint.cpp @@ -74,7 +74,6 @@ public: ep_map_key_t key{dst_epid, dst_port}; // Function to send a control payload auto send_fn = [this, dst_epid](const ctrl_payload& payload, double timeout) { - std::lock_guard lock(_mutex); // Build header chdr_header header; header.set_pkt_type(PKT_TYPE_CTRL); @@ -82,6 +81,7 @@ public: header.set_seq_num(_send_seqnum++); header.set_dst_epid(dst_epid); // Acquire send buffer and send the packet + std::lock_guard lock(_send_mutex); auto send_buff = _xport.send->get_send_buff(timeout); _send_pkt->refresh(send_buff->cast(), header, payload); send_buff->commit(header.get_length()); @@ -167,8 +167,10 @@ private: // A thread that will handle all responses and async message requests std::atomic_bool _stop_recv_thread; std::thread _recv_thread; - // Mutex that protects all state in this class + // Mutex that protects all state in this class except for _send_pkt std::mutex _mutex; + // Mutex that protects _send_pkt and _xport.send + std::mutex _send_mutex; }; chdr_ctrl_endpoint::uptr chdr_ctrl_endpoint::make(const chdr_ctrl_xport_t& xport, -- cgit v1.2.3