Proper termination of UAVACN server thread

This commit is contained in:
Pavel Kirienko 2015-10-17 20:29:49 +03:00 committed by Lorenz Meier
parent 9d86dbb6a1
commit 5b9fc2d9fa
2 changed files with 11 additions and 7 deletions

View File

@ -141,13 +141,14 @@ int UavcanServers::stop()
return -1;
}
_instance = nullptr;
if (server->_subnode_thread != -1) {
pthread_cancel(server->_subnode_thread);
pthread_join(server->_subnode_thread, NULL);
if (server->_subnode_thread) {
warnx("stopping fw srv thread...");
server->_subnode_thread_should_exit = true;
(void)pthread_join(server->_subnode_thread, NULL);
}
_instance = nullptr;
server->_main_node.getDispatcher().removeRxFrameListener();
delete server;
@ -334,7 +335,7 @@ pthread_addr_t UavcanServers::run(pthread_addr_t)
memset(_esc_enumeration_ids, 0, sizeof(_esc_enumeration_ids));
_esc_enumeration_index = 0;
while (1) {
while (!_subnode_thread_should_exit) {
if (_check_fw == true) {
_check_fw = false;
@ -554,7 +555,9 @@ pthread_addr_t UavcanServers::run(pthread_addr_t)
}
}
warnx("exiting.");
_subnode_thread_should_exit = false;
warnx("exiting");
return (pthread_addr_t) 0;
}

View File

@ -110,6 +110,7 @@ public:
private:
pthread_t _subnode_thread;
pthread_mutex_t _subnode_mutex;
volatile bool _subnode_thread_should_exit = false;
int init();