aboutsummaryrefslogtreecommitdiff
path: root/src/util/time.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-11 09:43:04 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-11 09:43:04 +0000
commitd9d94d0e53d26af75ec8241383d166544ebd79f3 (patch)
tree9080b73624389403a198257fe0547bb4634e64d2 /src/util/time.c
parent2d792ee2e9cc0c993b8907e2c8edb0c2b8465343 (diff)
downloadgnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.tar.gz
gnunet-d9d94d0e53d26af75ec8241383d166544ebd79f3.zip
converting to GNUNET_LOG_from*
Diffstat (limited to 'src/util/time.c')
-rw-r--r--src/util/time.c64
1 files changed, 33 insertions, 31 deletions
diff --git a/src/util/time.c b/src/util/time.c
index d3dd3b5ec..e48377fa3 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -26,6 +26,8 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_time_lib.h" 27#include "gnunet_time_lib.h"
28 28
29#define LOG(kind,...) GNUNET_log_from (kind, "util", __VA_ARGS__)
30
29static long long timestamp_offset; 31static long long timestamp_offset;
30 32
31/** 33/**
@@ -53,8 +55,8 @@ GNUNET_TIME_absolute_get ()
53 55
54 GETTIMEOFDAY (&tv, NULL); 56 GETTIMEOFDAY (&tv, NULL);
55 ret.abs_value = 57 ret.abs_value =
56 (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + 58 (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) +
57 ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset; 59 ((uint64_t) tv.tv_usec / 1000LL)) + timestamp_offset;
58 return ret; 60 return ret;
59} 61}
60 62
@@ -128,10 +130,10 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
128 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 130 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
129 131
130 if (rel.rel_value + now.abs_value < rel.rel_value) 132 if (rel.rel_value + now.abs_value < rel.rel_value)
131 { 133 {
132 GNUNET_break (0); /* overflow... */ 134 GNUNET_break (0); /* overflow... */
133 return GNUNET_TIME_absolute_get_forever (); 135 return GNUNET_TIME_absolute_get_forever ();
134 } 136 }
135 ret.abs_value = rel.rel_value + now.abs_value; 137 ret.abs_value = rel.rel_value + now.abs_value;
136 return ret; 138 return ret;
137} 139}
@@ -146,7 +148,7 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
146 */ 148 */
147struct GNUNET_TIME_Relative 149struct GNUNET_TIME_Relative
148GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, 150GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
149 struct GNUNET_TIME_Relative t2) 151 struct GNUNET_TIME_Relative t2)
150{ 152{
151 return (t1.rel_value < t2.rel_value) ? t1 : t2; 153 return (t1.rel_value < t2.rel_value) ? t1 : t2;
152} 154}
@@ -161,7 +163,7 @@ GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1,
161 */ 163 */
162struct GNUNET_TIME_Relative 164struct GNUNET_TIME_Relative
163GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, 165GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
164 struct GNUNET_TIME_Relative t2) 166 struct GNUNET_TIME_Relative t2)
165{ 167{
166 return (t1.rel_value > t2.rel_value) ? t1 : t2; 168 return (t1.rel_value > t2.rel_value) ? t1 : t2;
167} 169}
@@ -177,7 +179,7 @@ GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1,
177 */ 179 */
178struct GNUNET_TIME_Absolute 180struct GNUNET_TIME_Absolute
179GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, 181GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
180 struct GNUNET_TIME_Absolute t2) 182 struct GNUNET_TIME_Absolute t2)
181{ 183{
182 return (t1.abs_value < t2.abs_value) ? t1 : t2; 184 return (t1.abs_value < t2.abs_value) ? t1 : t2;
183} 185}
@@ -192,7 +194,7 @@ GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1,
192 */ 194 */
193struct GNUNET_TIME_Absolute 195struct GNUNET_TIME_Absolute
194GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, 196GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1,
195 struct GNUNET_TIME_Absolute t2) 197 struct GNUNET_TIME_Absolute t2)
196{ 198{
197 return (t1.abs_value > t2.abs_value) ? t1 : t2; 199 return (t1.abs_value > t2.abs_value) ? t1 : t2;
198} 200}
@@ -228,7 +230,7 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future)
228 */ 230 */
229struct GNUNET_TIME_Relative 231struct GNUNET_TIME_Relative
230GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, 232GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start,
231 struct GNUNET_TIME_Absolute end) 233 struct GNUNET_TIME_Absolute end)
232{ 234{
233 struct GNUNET_TIME_Relative ret; 235 struct GNUNET_TIME_Relative ret;
234 236
@@ -269,17 +271,17 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence)
269 */ 271 */
270struct GNUNET_TIME_Absolute 272struct GNUNET_TIME_Absolute
271GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, 273GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
272 struct GNUNET_TIME_Relative duration) 274 struct GNUNET_TIME_Relative duration)
273{ 275{
274 struct GNUNET_TIME_Absolute ret; 276 struct GNUNET_TIME_Absolute ret;
275 277
276 if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX)) 278 if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX))
277 return GNUNET_TIME_absolute_get_forever (); 279 return GNUNET_TIME_absolute_get_forever ();
278 if (start.abs_value + duration.rel_value < start.abs_value) 280 if (start.abs_value + duration.rel_value < start.abs_value)
279 { 281 {
280 GNUNET_break (0); 282 GNUNET_break (0);
281 return GNUNET_TIME_absolute_get_forever (); 283 return GNUNET_TIME_absolute_get_forever ();
282 } 284 }
283 ret.abs_value = start.abs_value + duration.rel_value; 285 ret.abs_value = start.abs_value + duration.rel_value;
284 return ret; 286 return ret;
285} 287}
@@ -295,7 +297,7 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start,
295 */ 297 */
296struct GNUNET_TIME_Absolute 298struct GNUNET_TIME_Absolute
297GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, 299GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
298 struct GNUNET_TIME_Relative duration) 300 struct GNUNET_TIME_Relative duration)
299{ 301{
300 struct GNUNET_TIME_Absolute ret; 302 struct GNUNET_TIME_Absolute ret;
301 303
@@ -315,7 +317,7 @@ GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start,
315 */ 317 */
316struct GNUNET_TIME_Relative 318struct GNUNET_TIME_Relative
317GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, 319GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
318 unsigned int factor) 320 unsigned int factor)
319{ 321{
320 struct GNUNET_TIME_Relative ret; 322 struct GNUNET_TIME_Relative ret;
321 323
@@ -323,10 +325,10 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
323 return GNUNET_TIME_relative_get_zero (); 325 return GNUNET_TIME_relative_get_zero ();
324 ret.rel_value = rel.rel_value * (unsigned long long) factor; 326 ret.rel_value = rel.rel_value * (unsigned long long) factor;
325 if (ret.rel_value / factor != rel.rel_value) 327 if (ret.rel_value / factor != rel.rel_value)
326 { 328 {
327 GNUNET_break (0); 329 GNUNET_break (0);
328 return GNUNET_TIME_relative_get_forever (); 330 return GNUNET_TIME_relative_get_forever ();
329 } 331 }
330 return ret; 332 return ret;
331} 333}
332 334
@@ -340,7 +342,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
340 */ 342 */
341struct GNUNET_TIME_Relative 343struct GNUNET_TIME_Relative
342GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, 344GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
343 unsigned int factor) 345 unsigned int factor)
344{ 346{
345 struct GNUNET_TIME_Relative ret; 347 struct GNUNET_TIME_Relative ret;
346 348
@@ -363,8 +365,8 @@ GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
363 * assuming it continues at the same speed 365 * assuming it continues at the same speed
364 */ 366 */
365struct GNUNET_TIME_Relative 367struct GNUNET_TIME_Relative
366GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished, 368GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
367 uint64_t total) 369 uint64_t finished, uint64_t total)
368{ 370{
369 struct GNUNET_TIME_Relative dur; 371 struct GNUNET_TIME_Relative dur;
370 double exp; 372 double exp;
@@ -391,17 +393,17 @@ GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished,
391 */ 393 */
392struct GNUNET_TIME_Relative 394struct GNUNET_TIME_Relative
393GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, 395GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
394 struct GNUNET_TIME_Relative a2) 396 struct GNUNET_TIME_Relative a2)
395{ 397{
396 struct GNUNET_TIME_Relative ret; 398 struct GNUNET_TIME_Relative ret;
397 399
398 if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX)) 400 if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX))
399 return GNUNET_TIME_relative_get_forever (); 401 return GNUNET_TIME_relative_get_forever ();
400 if (a1.rel_value + a2.rel_value < a1.rel_value) 402 if (a1.rel_value + a2.rel_value < a1.rel_value)
401 { 403 {
402 GNUNET_break (0); 404 GNUNET_break (0);
403 return GNUNET_TIME_relative_get_forever (); 405 return GNUNET_TIME_relative_get_forever ();
404 } 406 }
405 ret.rel_value = a1.rel_value + a2.rel_value; 407 ret.rel_value = a1.rel_value + a2.rel_value;
406 return ret; 408 return ret;
407} 409}
@@ -416,7 +418,7 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1,
416 */ 418 */
417struct GNUNET_TIME_Relative 419struct GNUNET_TIME_Relative
418GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, 420GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1,
419 struct GNUNET_TIME_Relative a2) 421 struct GNUNET_TIME_Relative a2)
420{ 422{
421 struct GNUNET_TIME_Relative ret; 423 struct GNUNET_TIME_Relative ret;
422 424