Skip to content

Commit

Permalink
Add a boolean to cleanly exit sender thread
Browse files Browse the repository at this point in the history
  • Loading branch information
Arkadiusz Niemiec authored and TSC21 committed Apr 21, 2019
1 parent c78aaeb commit c50c44c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions msg/templates/urtps/microRTPS_agent.cpp.template
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ recv_topics = [s.short_name for idx, s in enumerate(spec) if scope[idx] == MsgSc
****************************************************************************/

#include <thread>
#include <atomic>
#include <unistd.h>
#include <poll.h>
#include <chrono>
Expand Down Expand Up @@ -181,8 +182,9 @@ void signal_handler(int signum)
running = 0;
transport_node->close();
}
@[if recv_topics]@

@[if recv_topics]@
std::atomic<bool> exit_sender_thread(false);
void t_send(void *data)
{
char data_buffer[BUFFER_SIZE] = {};
Expand All @@ -192,7 +194,7 @@ void t_send(void *data)
while (running)
{
// Send subscribed topics over UART
while (topics.hasMsg(&topic_ID))
while (topics.hasMsg(&topic_ID) && !exit_sender_thread.load())
{
uint16_t header_length = transport_node->get_header_length();
/* make room for the header to fill in later */
Expand Down Expand Up @@ -301,6 +303,7 @@ int main(int argc, char** argv)
usleep(_options.sleep_us);
}
@[if recv_topics]@
exit_sender_thread = true;
sender_thread.join();
@[end if]@
delete transport_node;
Expand Down

0 comments on commit c50c44c

Please sign in to comment.