Added syncronization to t_send worker thread

Which avoids possible deadlocks
This commit is contained in:
Peter van der Perk
2019-11-08 18:58:38 +01:00
committed by Nuno Marques
parent f0d22d3962
commit 991399f105
5 changed files with 69 additions and 71 deletions
+3 -30
View File
@@ -61,12 +61,12 @@ except AttributeError:
#include "RtpsTopics.h"
bool RtpsTopics::init(std::condition_variable* cv)
bool RtpsTopics::init(std::condition_variable* t_send_queue_cv, std::mutex* t_send_queue_mutex, std::queue<uint8_t>* t_send_queue)
{
@[if recv_topics]@
// Initialise subscribers
@[for topic in recv_topics]@
if (_@(topic)_sub.init(cv)) {
if (_@(topic)_sub.init(@(rtps_message_id(ids, topic)), t_send_queue_cv, t_send_queue_mutex, t_send_queue)) {
std::cout << "@(topic) subscriber started" << std::endl;
} else {
std::cout << "ERROR starting @(topic) subscriber" << std::endl;
@@ -126,34 +126,6 @@ void RtpsTopics::publish(uint8_t topic_ID, char data_buffer[], size_t len)
@[end if]@
@[if recv_topics]@
bool RtpsTopics::hasMsg(uint8_t *topic_ID)
{
if (nullptr == topic_ID) return false;
*topic_ID = 0;
while (_next_sub_idx < @(len(recv_topics)) && 0 == *topic_ID)
{
switch (_sub_topics[_next_sub_idx])
{
@[for topic in recv_topics]@
case @(rtps_message_id(ids, topic)): if (_@(topic)_sub.hasMsg()) *topic_ID = @(rtps_message_id(ids, topic)); break;
@[end for]@
default:
printf("Unexpected topic ID to check hasMsg\n");
break;
}
_next_sub_idx++;
}
if (0 == *topic_ID)
{
_next_sub_idx = 0;
return false;
}
return true;
}
bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr)
{
bool ret = false;
@@ -178,6 +150,7 @@ bool RtpsTopics::getMsg(const uint8_t topic_ID, eprosima::fastcdr::Cdr &scdr)
@[ end if]@
msg.serialize(scdr);
ret = true;
_@(topic)_sub.unlockMsg();
}
break;
@[end for]@