time: Add csync_gettime() function.

This commit is contained in:
Andreas Schneider 2012-02-04 13:09:07 +01:00
parent 331783baef
commit 1d609e5985
2 changed files with 26 additions and 0 deletions

View file

@ -32,6 +32,31 @@
#define CSYNC_LOG_CATEGORY_NAME "csync.time" #define CSYNC_LOG_CATEGORY_NAME "csync.time"
#include "csync_log.h" #include "csync_log.h"
#ifdef _POSIX_MONOTONIC_CLOCK
# define CSYNC_CLOCK CLOCK_MONOTONIC
#else
# define CSYNC_CLOCK CLOCK_REALTIME
#endif
int csync_gettime(struct timespec *tp)
{
#ifdef HAVE_CLOCK_GETTIME
return clock_gettime(CSYNC_CLOCK, &tp);
#else
struct timeval tv;
if (gettimeofday(&tv, NULL) < 0) {
return -1;
}
tp->tv_sec = tv.tv_sec;
tp->tv_nsec = tv.tv_usec * 1000;
#endif
return 0;
}
#undef CSYNC_CLOCK
/* check time difference between the replicas */ /* check time difference between the replicas */
time_t csync_timediff(CSYNC *ctx) { time_t csync_timediff(CSYNC *ctx) {
time_t timediff = -1; time_t timediff = -1;

View file

@ -27,6 +27,7 @@
#include "csync_private.h" #include "csync_private.h"
int csync_gettime(struct timespec *tp);
time_t csync_timediff(CSYNC *ctx); time_t csync_timediff(CSYNC *ctx);
#endif /* _CSYNC_TIME_H */ #endif /* _CSYNC_TIME_H */