diff options
author | Ashish Chaudhari <ashish@ettus.com> | 2019-06-04 13:46:35 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2019-11-26 11:49:24 -0800 |
commit | 97b004131ad7cdd1daaac091bce1dcf6fd12ccaa (patch) | |
tree | ed880f0fb068ec0729d56aed62fc1022f568ce25 /host | |
parent | 01f08d3fa5ae0cd8a2fc3c6e1112117a1f7f9768 (diff) | |
download | uhd-97b004131ad7cdd1daaac091bce1dcf6fd12ccaa.tar.gz uhd-97b004131ad7cdd1daaac091bce1dcf6fd12ccaa.tar.bz2 uhd-97b004131ad7cdd1daaac091bce1dcf6fd12ccaa.zip |
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
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/rfnoc/chdr_ctrl_endpoint.cpp | 6 |
1 files 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<std::mutex> 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<std::mutex> lock(_send_mutex); auto send_buff = _xport.send->get_send_buff(timeout); _send_pkt->refresh(send_buff->cast<void*>(), 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, |