• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mavlink / MAVSDK / 14322270604

08 Apr 2025 12:26AM UTC coverage: 44.296% (-0.005%) from 44.301%
14322270604

push

github

web-flow
Merge pull request #2536 from mavlink/pr-fix-mutex-abort

core: fix mutex lock failed

19 of 53 new or added lines in 2 files covered. (35.85%)

2 existing lines in 2 files now uncovered.

14607 of 32976 relevant lines covered (44.3%)

282.39 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.11
/src/mavsdk/core/mavlink_parameter_subscription.cpp
1
#include "mavlink_parameter_subscription.h"
2

3
#include <algorithm>
4

5
namespace mavsdk {
6

7
void MavlinkParameterSubscription::subscribe_param_float_changed(
8✔
8
    const std::string& name, const ParamFloatChangedCallback& callback, const void* cookie)
9
{
10
    subscribe_param_changed<float>(name, callback, cookie);
8✔
11
}
8✔
12

13
void MavlinkParameterSubscription::subscribe_param_int_changed(
34✔
14
    const std::string& name, const ParamIntChangedCallback& callback, const void* cookie)
15
{
16
    subscribe_param_changed<int>(name, callback, cookie);
34✔
17
}
34✔
18

19
void MavlinkParameterSubscription::subscribe_param_custom_changed(
8✔
20
    const std::string& name, const ParamCustomChangedCallback& callback, const void* cookie)
21
{
22
    subscribe_param_changed<std::string>(name, callback, cookie);
8✔
23
}
8✔
24

25
void MavlinkParameterSubscription::find_and_call_subscriptions_value_changed(
37✔
26
    const std::string& param_name, const ParamValue& value)
27
{
28
    // Process any deferred operations before calling subscriptions
29
    process_deferred_operations();
37✔
30

31
    // Now lock the mutex and call the subscriptions
32
    std::lock_guard<std::mutex> lock(_param_changed_subscriptions_mutex);
37✔
33
    for (const auto& subscription : _param_changed_subscriptions) {
450✔
34
        if (subscription.param_name != param_name) {
413✔
35
            continue;
376✔
36
        }
37
        LogDebug() << "Param " << param_name << " changed to " << value;
37✔
38
        // We have a subscription on this param name, now check if the subscription is for the right
39
        // type and call the callback when matching
40
        if (std::get_if<ParamFloatChangedCallback>(&subscription.callback) && value.get_float()) {
37✔
41
            std::get<ParamFloatChangedCallback>(subscription.callback)(value.get_float().value());
2✔
42
        } else if (
67✔
43
            std::get_if<ParamIntChangedCallback>(&subscription.callback) && value.get_int()) {
67✔
44
            std::get<ParamIntChangedCallback>(subscription.callback)(value.get_int().value());
32✔
45
        } else if (
5✔
46
            std::get_if<ParamCustomChangedCallback>(&subscription.callback) && value.get_custom()) {
5✔
47
            std::get<ParamCustomChangedCallback>(subscription.callback)(value.get_custom().value());
2✔
48
        } else {
49
            // The callback we have set is not for this type.
50
            LogErr() << "Type and callback mismatch";
1✔
51
        }
52
    }
53
}
37✔
54

55
void MavlinkParameterSubscription::unsubscribe_all_params_changed(const void* cookie)
8✔
56
{
57
    // Process any deferred operations first
58
    process_deferred_operations();
8✔
59

60
    // Try to lock the mutex, if it fails we're likely in a callback
61
    if (_param_changed_subscriptions_mutex.try_lock()) {
8✔
62
        // We've acquired the lock without blocking, so we can modify the list
63
        _param_changed_subscriptions.erase(
32✔
64
            std::remove_if(
16✔
65
                _param_changed_subscriptions.begin(),
66
                _param_changed_subscriptions.end(),
67
                [&](const auto& subscription) { return subscription.cookie == cookie; }),
50✔
68
            _param_changed_subscriptions.end());
16✔
69
        _param_changed_subscriptions_mutex.unlock();
8✔
70
    } else {
71
        // We couldn't acquire the lock because we're likely in a callback
72
        // Defer the unsubscription of all params for this cookie
NEW
73
        std::lock_guard<std::mutex> lock(_deferred_unsubscriptions_mutex);
×
74
        // Add a special marker for unsubscribe_all (empty param_name)
NEW
75
        _deferred_unsubscriptions.push_back({"", cookie});
×
NEW
76
    }
×
77
}
8✔
78

79
} // namespace mavsdk
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc