GCC Code Coverage Report


Directory: ./
File: src/spinner.cpp
Date: 2022-06-29 13:58:11
Exec Total Coverage
Lines: 9 13 69.2%
Branches: 2 4 50.0%

Line Branch Exec Source
1 /**
2 * @file spinner.cpp
3 * @author Maximilien Naveau (maximilien.naveau@gmail.com)
4 * license License BSD-3-Clause
5 * @copyright Copyright (c) 2019, New York University and Max Planck
6 * Gesellschaft.
7 * @date 2019-05-22
8 *
9 * @brief This file implements a spinner to time a loop
10 */
11
12 #include <pthread.h>
13 #include <iostream>
14 #include <real_time_tools/spinner.hpp>
15 #include <real_time_tools/timer.hpp>
16
17 namespace real_time_tools
18 {
19 2 Spinner::Spinner()
20 {
21 2 period_sec_ = 0.0;
22 2 next_date_sec_ = Timer::get_current_time_sec() + period_sec_;
23 2 }
24
25 void Spinner::initialize()
26 {
27 next_date_sec_ = Timer::get_current_time_sec() + period_sec_;
28 }
29
30 11 void Spinner::spin()
31 {
32 11 Timer::sleep_until_sec(next_date_sec_);
33 11 next_date_sec_ = Timer::get_current_time_sec() + period_sec_;
34 11 }
35
36 double Spinner::predict_sleeping_time()
37 {
38 return next_date_sec_ - Timer::get_current_time_sec();
39 }
40
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
42 } // namespace real_time_tools
41