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 ()() ecl_assert_throw_decl(StandardException) {
46  TimeError result = sleep(required);
47  ecl_assert_throw( result == TimeError(NoError), time::throwSleepException(LOC) );
48 }
49 
50 void Sleep::operator ()(const Duration &duration) ecl_assert_throw_decl(StandardException) {
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) ecl_assert_throw_decl(StandardException) {
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 ()() ecl_assert_throw_decl(StandardException) {
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) ecl_assert_throw_decl(StandardException) {
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 ()() ecl_assert_throw_decl(StandardException) {
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) ecl_assert_throw_decl(StandardException) {
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 ()() ecl_assert_throw_decl(StandardException) {
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) ecl_assert_throw_decl(StandardException) {
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 
Embedded control libraries.
#define ecl_assert_throw(expression, exception)
#define ecl_assert_throw_decl(exception)
TimeStamp Duration
Convenience typedef to associate timestamps with the concept of durations.
Definition: duration.hpp:41


ecl_time
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:15