sleep_win.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Platform Check
10 *****************************************************************************/
11 
12 #include <ecl/config.hpp>
13 #if defined(ECL_IS_WIN32)
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <ecl/errors/macros.hpp>
20 #include "../../include/ecl/time/duration.hpp"
21 #include "../../include/ecl/time/sleep_win.hpp"
22 
23 #include <iostream>
25 
26 /*****************************************************************************
27 ** Namespaces
28 *****************************************************************************/
29 
30 namespace ecl {
31 
32 /*****************************************************************************
33 ** Implementation [Sleep]
34 *****************************************************************************/
35 Sleep::Sleep(const Duration &duration) {
36  required.tv_sec = duration.sec();
37  required.tv_nsec = duration.nsec();
38 }
39 
40 Sleep::Sleep(const unsigned long &seconds) {
41  required.tv_sec = seconds;
42  required.tv_nsec = 0;
43 }
44 
45 void Sleep::operator ()() {
46  TimeError result = sleep(required);
47  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
48 }
49 
50 void Sleep::operator ()(const Duration &duration) {
51  required.tv_sec = duration.sec();
52  required.tv_nsec = duration.nsec();
53  TimeError result = sleep(required);
54  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
55 }
56 
57 void Sleep::operator ()(const unsigned long &seconds) {
58  required.tv_sec = seconds;
59  required.tv_nsec = 0;
60  TimeError result = sleep(required);
61  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
62 }
63 
64 /*****************************************************************************
65 ** Implementation [MilliSleep]
66 *****************************************************************************/
67 
68 MilliSleep::MilliSleep(const unsigned long &milliseconds) {
69  required.tv_sec = milliseconds/1000; // integer division
70  required.tv_nsec = (milliseconds%1000)*1000000;
71 }
72 
73 void MilliSleep::operator ()() {
74  TimeError result = sleep(required);
75  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
76 }
77 
78 void MilliSleep::operator ()(const unsigned long &milliseconds) {
79  required.tv_sec = milliseconds/1000; // integer division
80  required.tv_nsec = (milliseconds%1000)*1000000;
81 // required.tv_nsec = 1000000*milli_seconds;
82  TimeError result = sleep(required);
83  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
84 }
85 
86 /*****************************************************************************
87 ** Implementation [MicroSleep]
88 *****************************************************************************/
89 
90 MicroSleep::MicroSleep(const unsigned long &microseconds) {
91  required.tv_sec = microseconds/1000000; // integer division
92  required.tv_nsec = (microseconds%1000000)*1000;
93 }
94 
95 void MicroSleep::operator ()() {
96  TimeError result = sleep(required);
97  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
98 }
99 
100 void MicroSleep::operator ()(const unsigned long &micro_seconds) {
101  required.tv_nsec = 1000*micro_seconds;
102  TimeError result = sleep(required);
103  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
104 }
105 
106 /*****************************************************************************
107 ** Implementation [NanoSleep]
108 *****************************************************************************/
109 
110 NanoSleep::NanoSleep(const unsigned long &nanoseconds) {
111  required.tv_sec = nanoseconds/1000000000; // integer division
112  required.tv_nsec = nanoseconds%1000000000;
113 }
114 
115 void NanoSleep::operator ()() {
116  TimeError result = sleep(required);
117  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
118 }
119 
120 void NanoSleep::operator ()(const unsigned long &nanoseconds) {
121  required.tv_nsec = nanoseconds;
122  TimeError result = sleep(required);
123  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
124 }
125 
126 } // namespace ecl
127 
128 #endif /* ECL_IS_WIN32 */
129 
functions.hpp
ecl::NoError
NoError
ecl::Duration
TimeStamp Duration
Convenience typedef to associate timestamps with the concept of durations.
Definition: duration.hpp:47
config.hpp
ecl_assert_throw
#define ecl_assert_throw(expression, exception)
macros.hpp
ecl
Embedded control libraries.


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