X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=time.c;h=1fd7b0981584fc4557079ee62a87fbd713554f3a;hp=809cefc92ff9b4334669cc837936db2ee0def6ac;hb=d27b31524e1d60ad4fdbeb606bba31ba0ee54048;hpb=48027ab6ec9113c037dfd388e91579ecf0a70eae diff --git a/time.c b/time.c index 809cefc9..1fd7b098 100644 --- a/time.c +++ b/time.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Andre Noll + * Copyright (C) 2005-2008 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -53,7 +53,7 @@ void d2tv(double x, struct timeval *tv) * If \a diff is not \p NULL, it contains the absolute value |\a b - \a a| on * return. * - * \return If \a b < \a, this function returns -1, otherwise it returns 1. + * \return If \a b < \a a, this function returns -1, otherwise it returns 1. */ int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *diff) { @@ -82,8 +82,7 @@ int tv_diff(const struct timeval *b, const struct timeval *a, struct timeval *di * * \param a First addend. * \param b Second addend. - * - * \param \a Sum contains the sum \a + \a b on return. + * \param sum Contains the sum \a + \a b on return. */ void tv_add(const struct timeval *a, const struct timeval *b, struct timeval *sum) @@ -122,17 +121,10 @@ void tv_scale(const unsigned long mult, const struct timeval *tv, void tv_divide(const unsigned long divisor, const struct timeval *tv, struct timeval *result) { - long unsigned q; + uint64_t x = ((uint64_t)tv->tv_sec * 1000 * 1000 + tv->tv_usec) / divisor; - q = tv->tv_usec / divisor; - result->tv_sec = tv->tv_sec / divisor; - result->tv_usec = (tv->tv_sec - result->tv_sec * divisor) - * 1000 * 1000 / divisor; - if (result->tv_usec + q >= 1000 * 1000) { - result->tv_sec++; - result->tv_usec = 1000 * 1000 - result->tv_usec - q; - } else - result->tv_usec += q; + result->tv_sec = x / 1000 / 1000; + result->tv_usec = x % (1000 * 1000); } /** @@ -177,3 +169,13 @@ int tv_convex_combination(const long a, const struct timeval *tv1, ret = -ret; return ret; } + +void compute_chunk_time(long unsigned chunk_num, + struct timeval *chunk_tv, struct timeval *stream_start, + struct timeval *result) +{ + struct timeval tmp; + + tv_scale(chunk_num, chunk_tv, &tmp); + tv_add(&tmp, stream_start, result); +}