Fix MAVLink app teardown with mavlink stop-all command

This commit is contained in:
Lorenz Meier
2016-03-25 15:20:32 +01:00
parent c385d5e32b
commit 6d42595c79
3 changed files with 13 additions and 15 deletions
+5 -5
View File
@@ -1629,7 +1629,7 @@ Mavlink::task_main(int argc, char *argv[])
mavlink_update_system();
/* start the MAVLink receiver */
_receive_thread = MavlinkReceiver::receive_start(this);
MavlinkReceiver::receive_start(&_receive_thread, this);
MavlinkOrbSubscription *param_sub = add_orb_subscription(ORB_ID(parameter_update));
uint64_t param_time = 0;
@@ -1988,6 +1988,9 @@ Mavlink::task_main(int argc, char *argv[])
_task_running = true;
}
/* first wait for threads to complete before tearing down anything */
pthread_join(_receive_thread, NULL);
delete _subscribe_to_stream;
_subscribe_to_stream = nullptr;
@@ -2015,10 +2018,7 @@ Mavlink::task_main(int argc, char *argv[])
_subscriptions = nullptr;
/* wait for threads to complete */
pthread_join(_receive_thread, NULL);
if (_uart_fd >= 0) {
if (_uart_fd >= 0 && !_is_usb_uart) {
/* reset the UART flags to original state */
tcsetattr(_uart_fd, TCSANOW, &uart_config_original);
+6 -8
View File
@@ -1918,7 +1918,7 @@ MavlinkReceiver::receive_thread(void *arg)
}
}
return NULL;
return nullptr;
}
void MavlinkReceiver::print_status()
@@ -1951,15 +1951,15 @@ void *MavlinkReceiver::start_helper(void *context)
MavlinkReceiver *rcv = new MavlinkReceiver((Mavlink *)context);
rcv->receive_thread(NULL);
void* ret = rcv->receive_thread(NULL);
delete rcv;
return nullptr;
return ret;
}
pthread_t
MavlinkReceiver::receive_start(Mavlink *parent)
void
MavlinkReceiver::receive_start(pthread_t *thread, Mavlink *parent)
{
pthread_attr_t receiveloop_attr;
pthread_attr_init(&receiveloop_attr);
@@ -1976,9 +1976,7 @@ MavlinkReceiver::receive_start(Mavlink *parent)
(void)pthread_attr_setschedparam(&receiveloop_attr, &param);
pthread_attr_setstacksize(&receiveloop_attr, 2100);
pthread_t thread;
pthread_create(&thread, &receiveloop_attr, MavlinkReceiver::start_helper, (void *)parent);
pthread_create(thread, &receiveloop_attr, MavlinkReceiver::start_helper, (void *)parent);
pthread_attr_destroy(&receiveloop_attr);
return thread;
}
+2 -2
View File
@@ -106,12 +106,11 @@ public:
*/
void print_status();
static pthread_t receive_start(Mavlink *parent);
static void receive_start(pthread_t *thread, Mavlink *parent);
static void *start_helper(void *context);
private:
Mavlink *_mavlink;
void handle_message(mavlink_message_t *msg);
void handle_message_command_long(mavlink_message_t *msg);
@@ -163,6 +162,7 @@ private:
bool evaluate_target_ok(int command, int target_system, int target_component);
Mavlink *_mavlink;
mavlink_status_t status;
struct vehicle_local_position_s hil_local_pos;
struct vehicle_land_detected_s hil_land_detector;