From 54db79277dc3919f5eab064f30bd36cfdf033985 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Tue, 12 Nov 2024 12:38:52 +1300 Subject: [PATCH] core: add missing locks in command queue --- src/mavsdk/core/mavlink_command_sender.cpp | 30 +++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/mavsdk/core/mavlink_command_sender.cpp b/src/mavsdk/core/mavlink_command_sender.cpp index 81017214a..5ed98b340 100644 --- a/src/mavsdk/core/mavlink_command_sender.cpp +++ b/src/mavsdk/core/mavlink_command_sender.cpp @@ -88,13 +88,16 @@ void MavlinkCommandSender::queue_command_async( CommandIdentification identification = identification_from_command(command); - for (const auto& work : _work_queue) { - if (work->identification == identification && callback == nullptr) { - if (_command_debugging) { - LogDebug() << "Dropping command " << static_cast(identification.command) - << " that is already being sent"; + { + LockedQueue::Guard work_queue_guard(_work_queue); + for (const auto& work : _work_queue) { + if (work->identification == identification && callback == nullptr) { + if (_command_debugging) { + LogDebug() << "Dropping command " << static_cast(identification.command) + << " that is already being sent"; + } + return; } - return; } } @@ -117,13 +120,16 @@ void MavlinkCommandSender::queue_command_async( CommandIdentification identification = identification_from_command(command); - for (const auto& work : _work_queue) { - if (work->identification == identification && callback == nullptr) { - if (_command_debugging) { - LogDebug() << "Dropping command " << static_cast(identification.command) - << " that is already being sent"; + { + LockedQueue::Guard work_queue_guard(_work_queue); + for (const auto& work : _work_queue) { + if (work->identification == identification && callback == nullptr) { + if (_command_debugging) { + LogDebug() << "Dropping command " << static_cast(identification.command) + << " that is already being sent"; + } + return; } - return; } }