14 #include "../../include/ecl/time_lite/functions_win.hpp" 20 #if defined(ECL_HAS_WIN_TIMERS) 46 static double cpu_frequency() {
47 static double frequency = 0.0;
49 if ( frequency == 0.0 ) {
51 QueryPerformanceFrequency(&freq);
52 frequency =
static_cast<double>(freq.QuadPart);
61 TimeError epoch_time(TimeStructure &time) {
64 QueryPerformanceCounter(&stamp);
65 double t =
static_cast<double>(stamp.QuadPart)/cpu_frequency();
66 time.tv_sec =
static_cast<long>(t);
67 time.tv_nsec = ((t -
static_cast<double>(time.tv_sec))*1000000000.0);
71 TimeError sleep_until(
const TimeStructure &time) {
72 TimeStructure current_time, sleep_time;
74 TimeError error = epoch_time(current_time);
75 if ( error.flag() !=
NoError ) {
return error; }
80 if ( current_time.tv_sec > time.tv_sec ) {
82 }
else if ( current_time.tv_sec == time.tv_sec ) {
83 if ( current_time.tv_nsec > time.tv_nsec ) {
87 sleep_time.tv_sec = time.tv_sec - current_time.tv_sec;
88 if ( current_time.tv_nsec <= time.tv_nsec ) {
89 sleep_time.tv_nsec = time.tv_nsec - current_time.tv_nsec;
91 sleep_time.tv_sec -= 1;
92 sleep_time.tv_nsec = 1000000000L - current_time.tv_nsec + time.tv_nsec;
94 return ecl::sleep(sleep_time);
97 TimeError sleep(
const TimeStructure &time) {
99 LARGE_INTEGER sleep_time;
101 sleep_time.QuadPart = -
102 static_cast<ecl::uint64
>(time.tv_sec)*10000000LL -
103 static_cast<ecl::uint64>(time.tv_nsec) / 100LL;
105 if ( (timer = CreateWaitableTimer(NULL, TRUE, NULL)) == NULL ) {
108 if (!SetWaitableTimer (timer, &sleep_time, 0, NULL, NULL, 0)) {
112 if (WaitForSingleObject (timer, INFINITE) != WAIT_OBJECT_0) {