| #include <stdexcept> // std::domain_error() |
| #include <cerrno> // errno |
| #include "igs_resource_msg_from_err.h" |
| #include "igs_resource_sleep.h" |
| |
| |
| |
| |
| void igs::resource::sleep_sn(const time_t seconds, const long nano_seconds) { |
| struct timespec req; |
| req.tv_sec = seconds; |
| req.tv_nsec = nano_seconds; |
| struct timespec rem; |
| rem.tv_sec = 0; |
| rem.tv_nsec = 0; |
| if (::nanosleep(&req, &rem) < 0) { |
| throw std::domain_error( |
| igs_resource_msg_from_err(TEXT("nanosleep(-)"), errno)); |
| } |
| } |
| |
| |
| |
| |
| void igs::resource::sleep_m(const DWORD milli_seconds) { |
| const time_t seconds = milli_seconds / 1000; |
| const long nano_seconds = (milli_seconds % 1000) * 1000000; |
| |
| |
| |
| igs::resource::sleep_sn(seconds, nano_seconds); |
| } |