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

mavlink / MAVSDK / 22147129029

18 Feb 2026 03:58PM UTC coverage: 48.98% (-0.03%) from 49.009%
22147129029

Pull #2768

github

web-flow
Merge 52160a25e into eb90df759
Pull Request #2768: Shell scripts cleanup

18359 of 37483 relevant lines covered (48.98%)

667.95 hits per line

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

88.64
/cpp/src/mavsdk/core/locked_queue.h
1
#pragma once
2

3
#include <queue>
4
#include <mutex>
5
#include <memory>
6
#include <condition_variable>
7

8
namespace mavsdk {
9

10
template<class T> class LockedQueue {
11
public:
12
    LockedQueue() = default;
1,207✔
13
    ~LockedQueue() = default;
1,207✔
14

15
    void push_back(std::shared_ptr<T> item_ptr)
1,834✔
16
    {
17
        std::lock_guard<std::mutex> lock(_mutex);
1,834✔
18
        _queue.push_back(item_ptr);
1,834✔
19
        _condition_var.notify_one();
1,833✔
20
    }
1,833✔
21

22
    size_t size()
1,232✔
23
    {
24
        std::lock_guard<std::mutex> lock(_mutex);
1,232✔
25
        return _queue.size();
1,232✔
26
    }
1,232✔
27

28
    void stop()
303✔
29
    {
30
        std::lock_guard<std::mutex> lock(_mutex);
303✔
31
        _should_exit = true;
303✔
32
        _condition_var.notify_all();
303✔
33
    }
303✔
34

35
    void restart()
×
36
    {
37
        std::lock_guard<std::mutex> lock(_mutex);
×
38
        _should_exit = false;
×
39
    }
×
40

41
    using iterator = typename std::deque<std::shared_ptr<T>>::iterator;
42
    iterator begin() { return _queue.begin(); }
21,518✔
43

44
    iterator end() { return _queue.end(); }
21,624✔
45

46
    iterator erase(iterator it) { return _queue.erase(it); }
204✔
47

48
    // This guard serves the purpose to combine a get_front with a pop_front.
49
    // Thus, no one can interfere between the two steps.
50
    class Guard {
51
    public:
52
        explicit Guard(LockedQueue& locked_queue) :
146,301✔
53
            _locked_queue(locked_queue),
146,301✔
54
            _lock(locked_queue._mutex)
146,301✔
55
        {}
145,957✔
56

57
        ~Guard() = default;
148,519✔
58

59
        Guard(Guard& other) = delete;
60
        Guard(const Guard& other) = delete;
61
        Guard(Guard&& other) = delete;
62
        Guard(const Guard&& other) = delete;
63
        Guard& operator=(const Guard& other) = delete;
64
        Guard& operator=(Guard&& other) = delete;
65

66
        std::shared_ptr<T> get_front()
126,363✔
67
        {
68
            if (_locked_queue._queue.size() == 0) {
126,363✔
69
                return nullptr;
116,099✔
70
            }
71
            return _locked_queue._queue.front();
6,246✔
72
        }
73

74
        std::shared_ptr<T> wait_and_pop_front()
1,534✔
75
        {
76
            while (_locked_queue._queue.empty()) {
2,972✔
77
                if (_locked_queue._should_exit) {
1,741✔
78
                    return std::shared_ptr<T>{};
303✔
79
                }
80
                _locked_queue._condition_var.wait(_lock);
1,438✔
81
            }
82
            if (_locked_queue._should_exit) {
1,231✔
83
                return std::shared_ptr<T>{};
×
84
            }
85

86
            auto result = _locked_queue._queue.front();
1,231✔
87
            _locked_queue._queue.pop_front();
1,231✔
88
            return result;
1,231✔
89
        }
1,231✔
90

91
        void pop_front() { _locked_queue._queue.pop_front(); }
366✔
92

93
    private:
94
        LockedQueue<T>& _locked_queue;
95
        std::unique_lock<std::mutex> _lock;
96
    };
97

98
private:
99
    std::deque<std::shared_ptr<T>> _queue{};
100
    std::mutex _mutex{};
101
    std::condition_variable _condition_var{};
102
    bool _should_exit{false};
103
};
104

105
} // 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