From 6ad7289d68301c3214608d1efc6fb516c5061173 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Mon, 19 Dec 2011 16:41:57 +0100 Subject: [PATCH] Detect clock_gettime(2) and use (if available) for the fetch cb. --- bin/xbps-bin/fetch_cb.c | 18 ++++++++++++++++-- configure | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/bin/xbps-bin/fetch_cb.c b/bin/xbps-bin/fetch_cb.c index 86ba0adb..5ea42dd2 100644 --- a/bin/xbps-bin/fetch_cb.c +++ b/bin/xbps-bin/fetch_cb.c @@ -42,6 +42,20 @@ #include #include "defs.h" +#include "config.h" + +static void +get_time(struct timeval *tvp) +{ +#ifdef HAVE_CLOCK_GETTIME + struct timespec ts; + (void)clock_gettime(CLOCK_MONOTONIC, &ts); + tvp->tv_sec = ts.tv_sec; + tvp->tv_usec = ts.tv_nsec / 1000; +#else + (void)gettimeofday(tvp, NULL); +#endif +} /* * Compute and display ETA @@ -113,7 +127,7 @@ stat_display(const struct xbps_fetch_cb_data *xfpd, void *cbdata) struct timeval now; char totsize[8], recvsize[8]; - gettimeofday(&now, NULL); + get_time(&now); if (now.tv_sec <= xfer->last.tv_sec) return; xfer->last = now; @@ -136,7 +150,7 @@ fetch_file_progress_cb(const struct xbps_fetch_cb_data *xfpd, void *cbdata) if (xfpd->cb_start) { /* start transfer stats */ - gettimeofday(&xfer->start, NULL); + get_time(&xfer->start); xfer->last.tv_sec = xfer->last.tv_usec = 0; } else if (xfpd->cb_update) { /* update transfer stats */ diff --git a/configure b/configure index 848e2ce1..a9febb61 100755 --- a/configure +++ b/configure @@ -443,6 +443,29 @@ fi echo "$PROPLIB." rm -f _$func.c _$func +# +# Check for clock_gettime(3). +# +func=clock_gettime +printf "Checking for $func() ... " +cat < _$func.c +#include +int main(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return 0; +} +EOF +if $XCC -lrt _$func.c -o _$func 2>/dev/null; then + echo yes. + echo "CPPFLAGS += -DHAVE_CLOCK_GETTIME" >>$CONFIG_MK + echo "LDFLAGS += -lrt" >>$CONFIG_MK + echo "STATIC_LIBS += -lrt" >>$CONFIG_MK +else + echo no. +fi +rm -f _$func.c _$func + # # zlib is required. #