Skip to content

Commit

Permalink
Merge pull request #2439 from mavlink/pr-fix-command-sender-locking
Browse files Browse the repository at this point in the history
core: add missing locks in command queue
  • Loading branch information
julianoes authored Nov 12, 2024
2 parents 6a93d83 + e4f6386 commit a81d258
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
name: ${{ matrix.ubuntu_image }} (mavsdk_server, superbuild)
runs-on: ${{ matrix.ubuntu_image }}
strategy:
fail-fast: false
matrix:
include:
- ubuntu_image: ubuntu-20.04
Expand Down Expand Up @@ -222,6 +223,7 @@ jobs:
name: ${{ matrix.container_name }} (package, non-mavsdk_server)
runs-on: ${{ matrix.container_name }}
strategy:
fail-fast: false
matrix:
container_name: [ubuntu-20.04, ubuntu-22.04, ubuntu-24.04]
steps:
Expand Down Expand Up @@ -258,6 +260,7 @@ jobs:
name: linux-${{ matrix.docker_name }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- docker_name: armv6
Expand Down Expand Up @@ -356,6 +359,7 @@ jobs:
name: ${{ matrix.arch_name }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
arch_name: [linux-armv6-musl, linux-armv7l-musl, linux-arm64-musl]
steps:
Expand Down Expand Up @@ -390,6 +394,7 @@ jobs:
name: ${{ matrix.name }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
include:
- name: android-arm
Expand Down Expand Up @@ -434,6 +439,7 @@ jobs:
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: macOS x64
Expand Down Expand Up @@ -509,6 +515,7 @@ jobs:
name: ${{ matrix.name }}
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- name: ios
Expand Down
30 changes: 18 additions & 12 deletions src/mavsdk/core/mavlink_command_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(identification.command)
<< " that is already being sent";
{
LockedQueue<Work>::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<int>(identification.command)
<< " that is already being sent";
}
return;
}
return;
}
}

Expand All @@ -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<int>(identification.command)
<< " that is already being sent";
{
LockedQueue<Work>::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<int>(identification.command)
<< " that is already being sent";
}
return;
}
return;
}
}

Expand Down

0 comments on commit a81d258

Please sign in to comment.