GCC Code Coverage Report


Directory: codebase/
File: codebase/system/source/sys.Scheduler.cpp
Date: 2023-03-16 04:37:09
Exec Total Coverage
Lines: 42 43 97.7%
Functions: 8 8 100.0%
Branches: 23 40 57.5%

Line Branch Exec Source
1 /**
2 * @file sys.Scheduler.cpp
3 * @author Sergey Baigudin, sergey@baigudin.software
4 * @copyright 2016-2022, Sergey Baigudin, Baigudin Software
5 */
6 #include "sys.Scheduler.hpp"
7 #include "sys.Thread.hpp"
8 #include "lib.UniquePointer.hpp"
9
10 namespace eoos
11 {
12 namespace sys
13 {
14
15 namespace
16 {
17
18 /**
19 * @brief Causes current thread to sleep in seconds.
20 *
21 * @param s A time to sleep in seconds.
22 */
23 3 void sSleep(int32_t const s)
24 {
25 3 uint_t sec( static_cast<uint_t>(s) );
26
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 3 times.
4 while(sec != 0U)
27 {
28 1 sec = ::sleep(sec);
29 }
30 3 }
31
32 /**
33 * @brief Causes current thread to sleep in milliseconds.
34 *
35 * @param ms A time to sleep in milliseconds.
36 * @return true if no system errors occured.
37 */
38 3 bool_t msSleep(int32_t const ms)
39 {
40 3 bool_t res( false );
41
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
3 if( (0 < ms) && (ms < 1000) )
42 {
43 2 ::useconds_t const us( static_cast< ::useconds_t >(ms) * 1000U );
44 2 int_t const error( ::usleep(us) );
45
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(error == 0)
46 {
47 2 res = true;
48 }
49 }
50 3 return res;
51 }
52
53 } // namespace
54
55 184 Scheduler::Scheduler()
56 : NonCopyable()
57 184 , api::Scheduler() {
58 184 }
59
60 368 Scheduler::~Scheduler() ///< SCA MISRA-C++:2008 Defected Rule 10-3-2
61 {
62 }
63
64 222 bool_t Scheduler::isConstructed() const ///< SCA MISRA-C++:2008 Justified Rule 10-3-1 and Defected Rule 10-3-2
65 {
66 222 return Parent::isConstructed();
67 }
68
69 31 api::Thread* Scheduler::createThread(api::Task& task) ///< SCA MISRA-C++:2008 Defected Rule 10-3-2
70 {
71 31 api::Thread* ptr( NULLPTR );
72
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 if( isConstructed() )
73 {
74
4/8
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 31 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 31 times.
✗ Branch 10 not taken.
31 lib::UniquePointer<api::Thread> res( new Thread(task) );
75
2/4
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 31 times.
✗ Branch 4 not taken.
31 if( !res.isNull() )
76 {
77
4/6
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 31 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 5 times.
✓ Branch 7 taken 26 times.
31 if( !res->isConstructed() )
78 {
79
1/2
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
5 res.reset();
80 }
81 }
82
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 ptr = res.release();
83
1/2
✓ Branch 1 taken 31 times.
✗ Branch 2 not taken.
31 }
84 31 return ptr;
85 }
86
87 3 bool_t Scheduler::sleep(int32_t ms) ///< SCA MISRA-C++:2008 Defected Rule 10-3-2
88 {
89 3 bool_t res( false );
90
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 if( isConstructed() )
91 {
92 3 int32_t time( ms / 1000 );
93 3 sSleep(time);
94 3 time = ms % 1000;
95 3 res = msSleep(time);
96 }
97 3 return res;
98 }
99
100 4 void Scheduler::yield() ///< SCA MISRA-C++:2008 Defected Rule 10-3-2
101 {
102
1/2
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
4 if( isConstructed() )
103 {
104 4 int_t const error( ::sched_yield() );
105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(error != 0)
106 { ///< UT Justified Branch: OS dependency
107 setConstructed(false);
108 }
109 }
110 4 }
111
112 } // namespace sys
113 } // namespace eoos
114