tor  master
Macros | Functions
compat_time.c File Reference

Portable wrappers for finding out the current time, running timers, etc. More...

#include "compat.h"
#include "torlog.h"
#include "util.h"
#include "container.h"
Include dependency graph for compat_time.c:

Macros

#define COMPAT_TIME_PRIVATE
 
#define ONE_MILLION   ((int64_t) (1000 * 1000))
 
#define ONE_BILLION   ((int64_t) (1000 * 1000 * 1000))
 
#define initialized_at_coarse   initialized_at
 

Functions

 MOCK_IMPL (void, tor_gettimeofday,(struct timeval *timeval))
 
STATIC void ratchet_timeval (const struct timeval *timeval_raw, struct timeval *out)
 
void monotime_get (monotime_t *out)
 
int64_t monotime_diff_nsec (const monotime_t *start, const monotime_t *end)
 
int32_t monotime_coarse_diff_msec32_ (const monotime_coarse_t *start, const monotime_coarse_t *end)
 
uint32_t monotime_coarse_to_stamp (const monotime_coarse_t *t)
 
int monotime_is_zero (const monotime_t *val)
 
void monotime_add_msec (monotime_t *out, const monotime_t *val, uint32_t msec)
 
void monotime_init (void)
 
void monotime_zero (monotime_t *out)
 
int64_t monotime_diff_usec (const monotime_t *start, const monotime_t *end)
 
int64_t monotime_diff_msec (const monotime_t *start, const monotime_t *end)
 
uint64_t monotime_absolute_nsec (void)
 
uint64_t monotime_absolute_usec (void)
 
uint64_t monotime_absolute_msec (void)
 
uint32_t monotime_coarse_get_stamp (void)
 
uint64_t monotime_coarse_stamp_units_to_approx_msec (uint64_t units)
 
uint64_t monotime_msec_to_approx_coarse_stamp_units (uint64_t msec)
 

Detailed Description

Portable wrappers for finding out the current time, running timers, etc.

Function Documentation

◆ MOCK_IMPL()

MOCK_IMPL ( void  ,
tor_gettimeofday  ,
(struct timeval *timeval  
)

Set *timeval to the current time of day. On error, log and terminate. (Same as gettimeofday(timeval,NULL), but never returns -1.)

◆ monotime_absolute_msec()

uint64_t monotime_absolute_msec ( void  )

Return the number of milliseconds since the timer system was initialized.

Here is the call graph for this function:

◆ monotime_absolute_nsec()

uint64_t monotime_absolute_nsec ( void  )

Return the number of nanoseconds since the timer system was initialized.

Here is the caller graph for this function:

◆ monotime_absolute_usec()

uint64_t monotime_absolute_usec ( void  )

Return the number of microseconds since the timer system was initialized.

Here is the call graph for this function:

◆ monotime_add_msec()

void monotime_add_msec ( monotime_t out,
const monotime_t val,
uint32_t  msec 
)

Set out to N milliseconds after val.

◆ monotime_coarse_diff_msec32_()

int32_t monotime_coarse_diff_msec32_ ( const monotime_coarse_t *  start,
const monotime_coarse_t *  end 
)

As monotime_coarse_diff_msec, but avoid 64-bit division.

Requires that the difference fit into an int32_t; not for use with large time differences.

◆ monotime_coarse_get_stamp()

uint32_t monotime_coarse_get_stamp ( void  )

Return the current time "stamp" as described by monotime_coarse_to_stamp.

Here is the caller graph for this function:

◆ monotime_coarse_stamp_units_to_approx_msec()

uint64_t monotime_coarse_stamp_units_to_approx_msec ( uint64_t  units)

Convert a difference, expressed in the units of monotime_coarse_to_stamp, into an approximate number of milliseconds.

Here is the caller graph for this function:

◆ monotime_coarse_to_stamp()

uint32_t monotime_coarse_to_stamp ( const monotime_coarse_t *  t)

Return a "timestamp" approximation for a coarse monotonic timer. This timestamp is meant to be fast to calculate and easy to compare, and have a unit of something roughly around 1 msec.

It will wrap over from time to time.

It has no defined zero point.

◆ monotime_diff_msec()

int64_t monotime_diff_msec ( const monotime_t start,
const monotime_t end 
)

Return the number of milliseconds between start and end.

Here is the call graph for this function:

◆ monotime_diff_nsec()

int64_t monotime_diff_nsec ( const monotime_t start,
const monotime_t end 
)

Return the number of nanoseconds between start and end.

Here is the caller graph for this function:

◆ monotime_diff_usec()

int64_t monotime_diff_usec ( const monotime_t start,
const monotime_t end 
)

Return the number of microseconds between start and end.

Here is the call graph for this function:

◆ monotime_get()

void monotime_get ( monotime_t out)

Set out to the current time.

Here is the caller graph for this function:

◆ monotime_init()

void monotime_init ( void  )

Initialize the monotonic timer subsystem. Must be called before any monotonic timer functions. This function is idempotent.

Here is the caller graph for this function:

◆ monotime_is_zero()

int monotime_is_zero ( const monotime_t out)

Return true iff out is zero

◆ monotime_zero()

void monotime_zero ( monotime_t out)

Set out to zero.

◆ ratchet_timeval()

STATIC void ratchet_timeval ( const struct timeval timeval_raw,
struct timeval out 
)

Helper for gettimeofday(): Called with a sequence of times that are supposed to be monotonic; increments them as appropriate so that they actually are monotonic.

Caller must hold lock.