mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-06 08:46:45 +08:00
clock_gettime => gettimeofday
This commit is contained in:
parent
f01438c369
commit
bbefef4a37
@ -3,9 +3,9 @@
|
||||
#include <pthread.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <tuple>
|
||||
@ -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_")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user