sleep_pos.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Platform Check
00010 *****************************************************************************/
00011 
00012 #include <ecl/config.hpp>
00013 #if defined(ECL_IS_POSIX)
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <ecl/errors/macros.hpp>
00020 #include "../../include/ecl/time/duration.hpp"
00021 #include "../../include/ecl/time/sleep_pos.hpp"
00022 
00023 /*****************************************************************************
00024 ** Namespaces
00025 *****************************************************************************/
00026 
00027 namespace ecl {
00028 
00029 /*****************************************************************************
00030 ** Implementation [Sleep]
00031 *****************************************************************************/
00032 Sleep::Sleep(const Duration &duration) {
00033         required.tv_sec = duration.sec();
00034         required.tv_nsec = duration.nsec();
00035 }
00036 
00037 Sleep::Sleep(const unsigned long &seconds) {
00038         required.tv_sec = seconds;
00039         required.tv_nsec = 0;
00040 }
00041 
00042 void Sleep::operator ()() ecl_assert_throw_decl(StandardException) {
00043     int result = nanosleep(&required, &remaining);
00044     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00045 }
00046 
00047 void Sleep::operator ()(const Duration &duration) ecl_assert_throw_decl(StandardException) {
00048         required.tv_sec = duration.sec();
00049         required.tv_nsec = duration.nsec();
00050     int result = nanosleep(&required, &remaining);
00051     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00052 }
00053 
00054 void Sleep::operator ()(const unsigned long &seconds) ecl_assert_throw_decl(StandardException) {
00055         required.tv_sec = seconds;
00056         required.tv_nsec = 0;
00057     int result = nanosleep(&required, &remaining);
00058     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00059 }
00060 
00061 /*****************************************************************************
00062 ** Implementation [MilliSleep]
00063 *****************************************************************************/
00064 
00065 MilliSleep::MilliSleep(const unsigned long &milliseconds) {
00066         required.tv_sec = milliseconds/1000; // integer division
00067         required.tv_nsec = (milliseconds%1000)*1000000;
00068 }
00069 
00070 void MilliSleep::operator ()() ecl_assert_throw_decl(StandardException) {
00071     int result = nanosleep(&required, &remaining);
00072     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00073 }
00074 
00075 void MilliSleep::operator ()(const unsigned long &milliseconds) ecl_assert_throw_decl(StandardException) {
00076         required.tv_sec = milliseconds/1000; // integer division
00077         required.tv_nsec = (milliseconds%1000)*1000000;
00078 //    required.tv_nsec = 1000000*milli_seconds;
00079     int result = nanosleep(&required, &remaining);
00080     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00081 }
00082 
00083 /*****************************************************************************
00084 ** Implementation [MicroSleep]
00085 *****************************************************************************/
00086 
00087 MicroSleep::MicroSleep(const unsigned long &microseconds) {
00088         required.tv_sec = microseconds/1000000; // integer division
00089         required.tv_nsec = (microseconds%1000000)*1000;
00090 }
00091 
00092 void MicroSleep::operator ()() ecl_assert_throw_decl(StandardException) {
00093     int result = nanosleep(&required, &remaining);
00094     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00095 }
00096 
00097 void MicroSleep::operator ()(const unsigned long &micro_seconds) ecl_assert_throw_decl(StandardException) {
00098     required.tv_nsec = 1000*micro_seconds;
00099     int result = nanosleep(&required, &remaining);
00100     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00101 }
00102 
00103 /*****************************************************************************
00104 ** Implementation [NanoSleep]
00105 *****************************************************************************/
00106 
00107 NanoSleep::NanoSleep(const unsigned long &nanoseconds) {
00108         required.tv_sec = nanoseconds/1000000000; // integer division
00109         required.tv_nsec = nanoseconds%1000000000;
00110 }
00111 
00112 void NanoSleep::operator ()() ecl_assert_throw_decl(StandardException) {
00113     int result = nanosleep(&required, &remaining);
00114     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00115 }
00116 
00117 void NanoSleep::operator ()(const unsigned long &nanoseconds) ecl_assert_throw_decl(StandardException) {
00118     required.tv_nsec = nanoseconds;
00119     int result = nanosleep(&required, &remaining);
00120     ecl_assert_throw( result == 0, time::throwSleepException(LOC) );
00121 }
00122 
00123 } // namespace ecl
00124 
00125 #endif /* ECL_IS_POSIX */
00126 


ecl_time
Author(s): Daniel Stonier
autogenerated on Thu Jun 6 2019 21:17:28