lib/cpuwatch_rt.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Platform Check
10 *****************************************************************************/
11 
12 #include <ecl/config.hpp>
13 
14 #if defined(ECL_IS_POSIX)
15  // monotonic clock, cpu clock -> clock_gettime; clock_selection -> clock_nanosleep
16  #if defined(_POSIX_MONOTONIC_CLOCK) && (_POSIX_MONOTONIC_CLOCK) >= 0L && defined(_POSIX_CLOCK_SELECTION) && (_POSIX_CLOCK_SELECTION) >= 0L
17 
18 
19 /*****************************************************************************
20 ** Includes
21 *****************************************************************************/
22 
23 #include "../../include/ecl/time/cpuwatch_rt.hpp"
25 
26 /*****************************************************************************
27 ** Namespaces
28 *****************************************************************************/
29 
30 namespace ecl {
31 
32 /*****************************************************************************
33 ** Implementation [CpuWatch]
34 *****************************************************************************/
35 
36 CpuWatch::CpuWatch() {
37  cpu_time(tmp);
38  start_time.stamp(tmp.tv_sec, tmp.tv_nsec);
39  split_time = start_time;
40 };
41 
42 /*****************************************************************************
43 ** Implementation
44 *****************************************************************************/
45 
46 void CpuWatch::restart()
47 {
48  cpu_time(tmp);
49  start_time.stamp(tmp.tv_sec, tmp.tv_nsec);
50  split_time = start_time;
51 }
52 
53 TimeStamp CpuWatch::elapsed()
54 {
55  cpu_time(tmp);
56  TimeStamp current_time(tmp.tv_sec, tmp.tv_nsec);
57  return ( current_time - start_time );
58 }
59 
60 TimeStamp CpuWatch::split()
61 {
62  TimeStamp last_time = split_time;
63  cpu_time(tmp);
64  split_time.stamp(tmp.tv_sec,tmp.tv_nsec);
65  return (split_time - last_time);
66 }
67 
68 }; // namespace ecl
69 
70 #endif /* MANY POSIX TIME REQ'MENTS */
71 #endif /* ECL_IS_POSIX */
72 
config.hpp
cpu_time.hpp
ecl
Embedded control libraries.


ecl_time
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:19