Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
compat_time.c File Reference

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

#include "lib/time/compat_time.h"
#include "lib/err/torerr.h"
#include "lib/log/log.h"
#include "lib/log/util_bug.h"
#include "lib/intmath/muldiv.h"
#include "lib/intmath/bits.h"
#include "lib/fs/winlib.h"
#include "lib/wallclock/timeval.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>

Go to the source code of this file.

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

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)
 

Variables

static int monotime_initialized = 0
 
static monotime_t initialized_at
 

Detailed Description

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

Definition in file compat_time.c.

Function Documentation

◆ monotime_absolute_msec()

uint64_t monotime_absolute_msec ( void  )

Return the number of milliseconds since the timer system was initialized. The returned value may be equal to zero. Fractional units are truncated, not rounded.

Definition at line 807 of file compat_time.c.

◆ monotime_absolute_nsec()

uint64_t monotime_absolute_nsec ( void  )

Return the number of nanoseconds since the timer system was initialized. The returned value may be equal to zero.

Definition at line 789 of file compat_time.c.

Referenced by monotime_absolute_msec(), and monotime_absolute_usec().

◆ monotime_absolute_usec()

uint64_t monotime_absolute_usec ( void  )

Return the number of microseconds since the timer system was initialized. The returned value may be equal to zero. Fractional units are truncated, not rounded.

Definition at line 801 of file compat_time.c.

Referenced by circpad_estimate_circ_rtt_on_send(), and circpad_machine_remove_token().

◆ monotime_coarse_get_stamp()

uint32_t monotime_coarse_get_stamp ( void  )

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

Definition at line 844 of file compat_time.c.

Referenced by cell_queue_append_packed_copy(), connection_bucket_init(), connection_handle_read_impl(), and connection_or_update_token_buckets_helper().

◆ 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.

The returned value may be equal to zero. Fractional units are truncated, not rounded.

Definition at line 870 of file compat_time.c.

Referenced by rate_per_sec_to_rate_per_step().

◆ 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. The returned value may be equal to zero. Fractional units are truncated, not rounded.

Definition at line 781 of file compat_time.c.

◆ 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. The returned value may be equal to zero. Fractional units are truncated, not rounded.

Definition at line 773 of file compat_time.c.

◆ monotime_init()

void monotime_init ( void  )

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

Definition at line 747 of file compat_time.c.

◆ monotime_zero()

void monotime_zero ( monotime_t out)

Set out to zero.

Definition at line 760 of file compat_time.c.

Variable Documentation

◆ monotime_initialized

int monotime_initialized = 0
static

True iff monotime_init has been called.

Definition at line 80 of file compat_time.c.

Referenced by monotime_init().