GNUNET_TIME_relative_get_unit_ ()
{
static struct GNUNET_TIME_Relative one = { 1 };
+
return one;
}
GNUNET_TIME_relative_get_millisecond_ ()
{
static struct GNUNET_TIME_Relative one = { 1000 };
+
return one;
}
GNUNET_TIME_relative_get_second_ ()
{
static struct GNUNET_TIME_Relative one = { 1000 * 1000LL };
+
return one;
}
GNUNET_TIME_relative_get_minute_ ()
{
static struct GNUNET_TIME_Relative one = { 60 * 1000 * 1000LL };
+
return one;
}
GNUNET_TIME_relative_get_hour_ ()
{
static struct GNUNET_TIME_Relative one = { 60 * 60 * 1000 * 1000LL };
+
return one;
}
GNUNET_TIME_relative_get_forever_ ()
{
static struct GNUNET_TIME_Relative forever = { UINT64_MAX };
+
return forever;
}
+
/**
* Return "forever".
*/
return forever;
}
+
/**
* Convert relative time to an absolute time in the
* future.
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
- unsigned int factor)
+ unsigned long long factor)
{
struct GNUNET_TIME_Relative ret;
return GNUNET_TIME_UNIT_ZERO;
if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
return GNUNET_TIME_UNIT_FOREVER_REL;
- ret.rel_value_us = rel.rel_value_us * (unsigned long long) factor;
+ ret.rel_value_us = rel.rel_value_us * factor;
if (ret.rel_value_us / factor != rel.rel_value_us)
{
GNUNET_break (0);
}
+/**
+ * Saturating multiply relative time by a given factor.
+ *
+ * @param rel some duration
+ * @param factor integer to multiply with
+ * @return FOREVER if rel=FOREVER or on overflow; otherwise rel*factor
+ */
+struct GNUNET_TIME_Relative
+GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel,
+ unsigned long long factor)
+{
+ struct GNUNET_TIME_Relative ret;
+
+ if (0 == factor)
+ return GNUNET_TIME_UNIT_ZERO;
+ if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ ret.rel_value_us = rel.rel_value_us * factor;
+ if (ret.rel_value_us / factor != rel.rel_value_us)
+ {
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
+ return ret;
+}
+
+
/**
* Divide relative time by a given factor.
*
*/
struct GNUNET_TIME_Relative
GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel,
- unsigned int factor)
+ unsigned long long factor)
{
struct GNUNET_TIME_Relative ret;
if ((0 == factor) ||
(rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us))
return GNUNET_TIME_UNIT_FOREVER_REL;
- ret.rel_value_us = rel.rel_value_us / (unsigned long long) factor;
+ ret.rel_value_us = rel.rel_value_us / factor;
return ret;
}
ret.rel_value_us = GNUNET_ntohll (a.rel_value_us__);
return ret;
-
}