GNUnet  0.10.x
Macros | Functions | Variables
time.c File Reference

functions for handling time and time arithmetic More...

#include "platform.h"
#include "gnunet_util_lib.h"
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define __STDC_NO_ATOMICS__   1
 
#define ATOMIC
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "util-time", __VA_ARGS__)
 

Functions

void GNUNET_TIME_set_offset (long long offset)
 Set the timestamp offset for this instance. More...
 
long long GNUNET_TIME_get_offset ()
 Get the timestamp offset for this instance. More...
 
int GNUNET_TIME_round_abs (struct GNUNET_TIME_Absolute *at)
 Round a time value so that it is suitable for transmission via JSON encodings. More...
 
int GNUNET_TIME_round_rel (struct GNUNET_TIME_Relative *rt)
 Round a time value so that it is suitable for transmission via JSON encodings. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get ()
 Get the current time (works just as "time", just that we use the unit of time that the cron-jobs use (and is 64 bit)). More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_ ()
 Return relative time of 0ms. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_zero_ ()
 Return absolute time of 0ms. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_unit_ ()
 Return relative time of 1us. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_millisecond_ ()
 Return relative time of 1ms. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_second_ ()
 Return relative time of 1s. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_ ()
 Return relative time of 1 minute. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_hour_ ()
 Return relative time of 1 hour. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever_ ()
 Return "forever". More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever_ ()
 Return "forever". More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
 Convert relative time to an absolute time in the future. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
 Return the minimum of two relative time values. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max (struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
 Return the maximum of two relative time values. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
 Return the minimum of two relative time values. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
 Return the maximum of two relative time values. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future)
 Given a timestamp in the future, how much time remains until then? More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
 Compute the time difference between the given start and end times. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute whence)
 Get the duration of an operation as the difference of the current time and the given start time "whence". More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
 Add a given relative duration to the given start time. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
 Subtract a given relative duration from the given start time. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Multiply relative time by a given factor. More...
 
struct GNUNET_TIME_Relative relative_multiply_double (struct GNUNET_TIME_Relative rel, double factor)
 Multiply relative time by a given floating-point factor. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_saturating_multiply (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Saturating multiply relative time by a given factor. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide (struct GNUNET_TIME_Relative rel, unsigned long long factor)
 Divide relative time by a given factor. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, uint64_t finished, uint64_t total)
 Calculate the estimate time of arrival/completion for an operation. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
 Add relative times together. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
 Subtract relative timestamp from the other. More...
 
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton (struct GNUNET_TIME_Relative a)
 Convert relative time to network byte order. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh (struct GNUNET_TIME_RelativeNBO a)
 Convert relative time from network byte order. More...
 
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton (struct GNUNET_TIME_Absolute a)
 Convert absolute time to network byte order. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh (struct GNUNET_TIME_AbsoluteNBO a)
 Convert absolute time from network byte order. More...
 
unsigned int GNUNET_TIME_get_current_year ()
 Return the current year (i.e. More...
 
unsigned int GNUNET_TIME_time_to_year (struct GNUNET_TIME_Absolute at)
 Convert an expiration time to the respective year (rounds) More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_year_to_time (unsigned int year)
 Convert a year to an expiration time of January 1st of that year. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_randomized_backoff (struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
 Randomized exponential back-off, starting at 1 ms and going up by a factor of 2+r, where 0 <= r <= 0.5, up to a maximum of the given threshold. More...
 
struct GNUNET_TIME_Relative GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
 Return a random time value between 0.5*r and 1.5*r. More...
 
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Obtain the current time and make sure it is monotonically increasing. More...
 
void __attribute__ ((destructor))
 Destructor. More...
 

Variables

static long long timestamp_offset
 Variable used to simulate clock skew. More...
 

Detailed Description

functions for handling time and time arithmetic

Author
Christian Grothoff

Definition in file time.c.

Macro Definition Documentation

◆ __STDC_NO_ATOMICS__

#define __STDC_NO_ATOMICS__   1

Definition at line 35 of file time.c.

◆ ATOMIC

#define ATOMIC

Definition at line 36 of file time.c.

Referenced by GNUNET_TIME_absolute_get_monotonic().

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "util-time", __VA_ARGS__)

Definition at line 40 of file time.c.

Function Documentation

◆ relative_multiply_double()

struct GNUNET_TIME_Relative relative_multiply_double ( struct GNUNET_TIME_Relative  rel,
double  factor 
)

Multiply relative time by a given floating-point factor.

The factor must be positive.

Returns
FOREVER if rel=FOREVER or on overflow; otherwise rel*factor

Definition at line 465 of file time.c.

References GNUNET_assert, GNUNET_break, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, m, and GNUNET_TIME_Relative::rel_value_us.

Referenced by GNUNET_TIME_randomize(), and GNUNET_TIME_randomized_backoff().

467 {
468  struct GNUNET_TIME_Relative out;
469  double m;
470 
471  GNUNET_assert (0 <= factor);
472 
473  if (0 == factor)
474  return GNUNET_TIME_UNIT_ZERO;
475  if (rel.rel_value_us == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
477 
478  m = ((double) rel.rel_value_us) * factor;
479 
480  if (m >= (double) (GNUNET_TIME_UNIT_FOREVER_REL).rel_value_us)
481  {
482  GNUNET_break (0);
484  }
485 
486  out.rel_value_us = (uint64_t) m;
487  return out;
488 }
uint64_t rel_value_us
The actual value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Time for relative time used by GNUnet, in microseconds.
Here is the caller graph for this function:

◆ __attribute__()

void __attribute__ ( (destructor)  )

Destructor.

Definition at line 930 of file time.c.

References GNUNET_TIME_absolute_get_monotonic().

932 {
934 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_monotonic(const struct GNUNET_CONFIGURATION_Handle *cfg)
Obtain the current time and make sure it is monotonically increasing.
Definition: time.c:807
Here is the call graph for this function:

Variable Documentation

◆ timestamp_offset

long long timestamp_offset
static

Variable used to simulate clock skew.

Used for testing, never in production.

Definition at line 45 of file time.c.

Referenced by GNUNET_TIME_absolute_get(), GNUNET_TIME_get_offset(), and GNUNET_TIME_set_offset().