INSTINCT Code Coverage Report


Directory: src/
File: util/CallbackTimer.cpp
Date: 2025-06-02 15:19:59
Exec Total Coverage
Lines: 21 26 80.8%
Functions: 5 6 83.3%
Branches: 12 24 50.0%

Line Branch Exec Source
1 // This file is part of INSTINCT, the INS Toolkit for Integrated
2 // Navigation Concepts and Training by the Institute of Navigation of
3 // the University of Stuttgart, Germany.
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9 #include "CallbackTimer.hpp"
10
11 #include <chrono>
12
13 342 CallbackTimer::~CallbackTimer()
14 {
15
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 342 times.
342 if (_execute.load(std::memory_order_acquire))
16 {
17 stop();
18 };
19 342 }
20
21 4 void CallbackTimer::stop()
22 {
23 4 _execute.store(false, std::memory_order_release);
24
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if (_thd.joinable())
25 {
26 4 _thd.join();
27 }
28 4 }
29
30 4 void CallbackTimer::start(int interval, const std::function<void(void*)>& func, void* userData)
31 {
32
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
4 if (_execute.load(std::memory_order_acquire))
33 {
34 stop();
35 };
36 4 _interval.store(interval, std::memory_order_release);
37 4 _execute.store(true, std::memory_order_release);
38
2/6
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
8 _thd = std::thread([this, func, userData]() {
39
1/2
✓ Branch 1 taken 45 times.
✗ Branch 2 not taken.
46 while (_execute.load(std::memory_order_acquire))
40 {
41 45 auto start = std::chrono::steady_clock::now();
42
1/2
✓ Branch 1 taken 43 times.
✗ Branch 2 not taken.
45 func(userData);
43 // std::this_thread::sleep_for(
44 // std::chrono::milliseconds(_interval));
45
46
2/4
✓ Branch 3 taken 36 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 42 times.
✗ Branch 7 not taken.
83 std::this_thread::sleep_until(start + std::chrono::milliseconds(_interval.load(std::memory_order_acquire)));
47 }
48 3 });
49 4 }
50
51 void CallbackTimer::setInterval(int interval)
52 {
53 _interval.store(interval, std::memory_order_release);
54 }
55
56 6 bool CallbackTimer::is_running() const noexcept
57 {
58
3/4
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
6 return (_execute.load(std::memory_order_acquire) && _thd.joinable());
59 }
60