diff --git a/src/platform/waiter_linux.h b/src/platform/waiter_linux.h index 071e6c8..f65045c 100644 --- a/src/platform/waiter_linux.h +++ b/src/platform/waiter_linux.h @@ -3,9 +3,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -19,11 +19,17 @@ namespace ipc { namespace detail { -inline static void calc_wait_time(timespec& ts, std::size_t tm) { - ::clock_gettime(CLOCK_REALTIME, &ts); - ts.tv_nsec += tm * 1000000; // nanoseconds - ts.tv_sec += ts.tv_nsec / 1000000000; +inline static bool calc_wait_time(timespec& ts, std::size_t tm /*ms*/) { + timeval now; + int eno = ::gettimeofday(&now, NULL); + if (eno != 0) { + ipc::error("fail gettimeofday[%d]\n", eno); + return false; + } + ts.tv_nsec = (now.tv_usec + (tm % 1000) * 1000) * 1000; + ts.tv_sec = now.tv_sec + (tm / 1000) + (ts.tv_nsec / 1000000000); ts.tv_nsec %= 1000000000; + return true; } #pragma push_macro("IPC_PTHREAD_FUNC_")