diff options
author | Bertrand Marc <beberking@gmail.com> | 2012-06-06 20:47:48 +0200 |
---|---|---|
committer | Bertrand Marc <beberking@gmail.com> | 2012-06-06 20:47:48 +0200 |
commit | 740b30688bd745a527f96f9116c19acb3480971a (patch) | |
tree | 2709a3f4dba11c174aa9e1ba3612e30c578e76a9 /src/util/time.c | |
parent | 2b81464a43485fcc8ce079fafdee7b7a171835f4 (diff) |
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'src/util/time.c')
-rw-r--r-- | src/util/time.c | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/src/util/time.c b/src/util/time.c index c57ccd1..7467b44 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -68,7 +68,7 @@ GNUNET_TIME_absolute_get () * Return relative time of 0ms. */ struct GNUNET_TIME_Relative -GNUNET_TIME_relative_get_zero () +GNUNET_TIME_relative_get_zero_ () { static struct GNUNET_TIME_Relative zero; @@ -80,28 +80,63 @@ GNUNET_TIME_relative_get_zero () * Return absolute time of 0ms. */ struct GNUNET_TIME_Absolute -GNUNET_TIME_absolute_get_zero () +GNUNET_TIME_absolute_get_zero_ () { static struct GNUNET_TIME_Absolute zero; return zero; } + /** * Return relative time of 1ms. */ struct GNUNET_TIME_Relative -GNUNET_TIME_relative_get_unit () +GNUNET_TIME_relative_get_unit_ () { static struct GNUNET_TIME_Relative one = { 1 }; return one; } + +/** + * Return relative time of 1s. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_second_ () +{ + static struct GNUNET_TIME_Relative one = { 1000 }; + return one; +} + + +/** + * Return relative time of 1 minute. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_minute_ () +{ + static struct GNUNET_TIME_Relative one = { 60 * 1000 }; + return one; +} + + +/** + * Return relative time of 1 hour. + */ +struct GNUNET_TIME_Relative +GNUNET_TIME_relative_get_hour_ () +{ + static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 }; + return one; +} + + /** * Return "forever". */ struct GNUNET_TIME_Relative -GNUNET_TIME_relative_get_forever () +GNUNET_TIME_relative_get_forever_ () { static struct GNUNET_TIME_Relative forever = { UINT64_MAX }; return forever; @@ -111,7 +146,7 @@ GNUNET_TIME_relative_get_forever () * Return "forever". */ struct GNUNET_TIME_Absolute -GNUNET_TIME_absolute_get_forever () +GNUNET_TIME_absolute_get_forever_ () { static struct GNUNET_TIME_Absolute forever = { UINT64_MAX }; return forever; @@ -129,13 +164,13 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) struct GNUNET_TIME_Absolute ret; if (rel.rel_value == UINT64_MAX) - return GNUNET_TIME_absolute_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_ABS; struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); if (rel.rel_value + now.abs_value < rel.rel_value) { GNUNET_break (0); /* overflow... */ - return GNUNET_TIME_absolute_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_ABS; } ret.abs_value = rel.rel_value + now.abs_value; return ret; @@ -193,7 +228,7 @@ GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, * * @param t1 first timestamp * @param t2 other timestamp - * @return timestamp that is smaller + * @return timestamp that is bigger */ struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, @@ -215,11 +250,11 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) struct GNUNET_TIME_Relative ret; if (future.abs_value == UINT64_MAX) - return GNUNET_TIME_relative_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_REL; struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); if (now.abs_value > future.abs_value) - return GNUNET_TIME_relative_get_zero (); + return GNUNET_TIME_UNIT_ZERO; ret.rel_value = future.abs_value - now.abs_value; return ret; } @@ -238,9 +273,9 @@ GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative ret; if (end.abs_value == UINT64_MAX) - return GNUNET_TIME_relative_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_REL; if (end.abs_value < start.abs_value) - return GNUNET_TIME_relative_get_zero (); + return GNUNET_TIME_UNIT_ZERO; ret.rel_value = end.abs_value - start.abs_value; return ret; } @@ -260,7 +295,7 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence) now = GNUNET_TIME_absolute_get (); GNUNET_assert (whence.abs_value != UINT64_MAX); if (whence.abs_value > now.abs_value) - return GNUNET_TIME_relative_get_zero (); + return GNUNET_TIME_UNIT_ZERO; ret.rel_value = now.abs_value - whence.abs_value; return ret; } @@ -279,11 +314,11 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute ret; if ((start.abs_value == UINT64_MAX) || (duration.rel_value == UINT64_MAX)) - return GNUNET_TIME_absolute_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_ABS; if (start.abs_value + duration.rel_value < start.abs_value) { GNUNET_break (0); - return GNUNET_TIME_absolute_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_ABS; } ret.abs_value = start.abs_value + duration.rel_value; return ret; @@ -325,12 +360,12 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, struct GNUNET_TIME_Relative ret; if (factor == 0) - return GNUNET_TIME_relative_get_zero (); + return GNUNET_TIME_UNIT_ZERO; ret.rel_value = rel.rel_value * (unsigned long long) factor; if (ret.rel_value / factor != rel.rel_value) { GNUNET_break (0); - return GNUNET_TIME_relative_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_REL; } return ret; } @@ -401,11 +436,11 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative ret; if ((a1.rel_value == UINT64_MAX) || (a2.rel_value == UINT64_MAX)) - return GNUNET_TIME_relative_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_REL; if (a1.rel_value + a2.rel_value < a1.rel_value) { GNUNET_break (0); - return GNUNET_TIME_relative_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_REL; } ret.rel_value = a1.rel_value + a2.rel_value; return ret; @@ -426,9 +461,9 @@ GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative ret; if (a2.rel_value >= a1.rel_value) - return GNUNET_TIME_relative_get_zero (); + return GNUNET_TIME_UNIT_ZERO; if (a1.rel_value == UINT64_MAX) - return GNUNET_TIME_relative_get_forever (); + return GNUNET_TIME_UNIT_FOREVER_REL; ret.rel_value = a1.rel_value - a2.rel_value; return ret; } |