X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftime%2Ftime.c;h=166832d8a961d56b8ebcf9ebd4b58c62d1b1e4ed;hb=f3eecc2c76e7ebbd0024b1528326bbb18a7d7742;hp=a6960335a50c814610ec1548a041644da4f81948;hpb=2a91b14cf2eea39b32d17a0ab14dd7243f36b79f;p=ccan diff --git a/ccan/time/time.c b/ccan/time/time.c index a6960335..166832d8 100644 --- a/ccan/time/time.c +++ b/ccan/time/time.c @@ -3,13 +3,6 @@ #include #include -#ifdef DEBUG -#include -#define TIME_CHECK(t) time_check((t), __FILE__ ":" stringify(__LINE__)) -#else -#define TIME_CHECK(t) (t) -#endif - #if !HAVE_CLOCK_GETTIME && !HAVE_CLOCK_GETTIME_IN_LIBRT #include @@ -32,58 +25,6 @@ struct timespec time_now(void) } #endif /* HAVE_CLOCK_GETTIME || HAVE_CLOCK_GETTIME_IN_LIBRT */ -bool time_greater(struct timespec a, struct timespec b) -{ - if (TIME_CHECK(a).tv_sec > TIME_CHECK(b).tv_sec) - return true; - else if (a.tv_sec < b.tv_sec) - return false; - - return a.tv_nsec > b.tv_nsec; -} - -bool time_less(struct timespec a, struct timespec b) -{ - if (TIME_CHECK(a).tv_sec < TIME_CHECK(b).tv_sec) - return true; - else if (a.tv_sec > b.tv_sec) - return false; - - return a.tv_nsec < b.tv_nsec; -} - -bool time_eq(struct timespec a, struct timespec b) -{ - return TIME_CHECK(a).tv_sec == TIME_CHECK(b).tv_sec && a.tv_nsec == b.tv_nsec; -} - -struct timespec time_sub(struct timespec recent, struct timespec old) -{ - struct timespec diff; - - diff.tv_sec = TIME_CHECK(recent).tv_sec - TIME_CHECK(old).tv_sec; - if (old.tv_nsec > recent.tv_nsec) { - diff.tv_sec--; - diff.tv_nsec = 1000000000 + recent.tv_nsec - old.tv_nsec; - } else - diff.tv_nsec = recent.tv_nsec - old.tv_nsec; - - return TIME_CHECK(diff); -} - -struct timespec time_add(struct timespec a, struct timespec b) -{ - struct timespec sum; - - sum.tv_sec = TIME_CHECK(a).tv_sec + TIME_CHECK(b).tv_sec; - sum.tv_nsec = a.tv_nsec + b.tv_nsec; - if (sum.tv_nsec >= 1000000000) { - sum.tv_sec++; - sum.tv_nsec -= 1000000000; - } - return TIME_CHECK(sum); -} - struct timespec time_divide(struct timespec t, unsigned long div) { struct timespec res; @@ -134,57 +75,6 @@ struct timespec time_multiply(struct timespec t, unsigned long mult) return TIME_CHECK(res); } -uint64_t time_to_msec(struct timespec t) -{ - uint64_t msec; - - msec = TIME_CHECK(t).tv_nsec / 1000000 + (uint64_t)t.tv_sec * 1000; - return msec; -} - -uint64_t time_to_usec(struct timespec t) -{ - uint64_t usec; - - usec = TIME_CHECK(t).tv_nsec / 1000 + (uint64_t)t.tv_sec * 1000000; - return usec; -} - -uint64_t time_to_nsec(struct timespec t) -{ - uint64_t nsec; - - nsec = TIME_CHECK(t).tv_nsec + (uint64_t)t.tv_sec * 1000000000; - return nsec; -} - -struct timespec time_from_msec(uint64_t msec) -{ - struct timespec t; - - t.tv_nsec = (msec % 1000) * 1000000; - t.tv_sec = msec / 1000; - return TIME_CHECK(t); -} - -struct timespec time_from_usec(uint64_t usec) -{ - struct timespec t; - - t.tv_nsec = (usec % 1000000) * 1000; - t.tv_sec = usec / 1000000; - return TIME_CHECK(t); -} - -struct timespec time_from_nsec(uint64_t nsec) -{ - struct timespec t; - - t.tv_nsec = nsec % 1000000000; - t.tv_sec = nsec / 1000000000; - return TIME_CHECK(t); -} - struct timespec time_check(struct timespec t, const char *abortstr) { if (t.tv_sec < 0 || t.tv_nsec >= 1000000000) {