mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
clock_gettime => gettimeofday
This commit is contained in:
parent
f01438c369
commit
bbefef4a37
@ -3,9 +3,9 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -19,11 +19,17 @@
|
|||||||
namespace ipc {
|
namespace ipc {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
inline static void calc_wait_time(timespec& ts, std::size_t tm) {
|
inline static bool calc_wait_time(timespec& ts, std::size_t tm /*ms*/) {
|
||||||
::clock_gettime(CLOCK_REALTIME, &ts);
|
timeval now;
|
||||||
ts.tv_nsec += tm * 1000000; // nanoseconds
|
int eno = ::gettimeofday(&now, NULL);
|
||||||
ts.tv_sec += ts.tv_nsec / 1000000000;
|
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;
|
ts.tv_nsec %= 1000000000;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma push_macro("IPC_PTHREAD_FUNC_")
|
#pragma push_macro("IPC_PTHREAD_FUNC_")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user