tor  0.4.0.0-alpha-dev
Functions | Variables
approx_time.c File Reference
#include "orconfig.h"
#include "lib/subsys/subsys.h"
#include "lib/wallclock/approx_time.h"
#include "lib/wallclock/wallclock_sys.h"

Go to the source code of this file.

Functions

time_t approx_time (void)
 
void update_approx_time (time_t now)
 
static int subsys_wallclock_initialize (void)
 

Variables

static time_t cached_approx_time = 0
 
const subsys_fns_t sys_wallclock
 

Detailed Description

Cache the last result of time(), for performance and testing.

Definition in file approx_time.c.

Function Documentation

◆ approx_time()

time_t approx_time ( void  )

◆ update_approx_time()

void update_approx_time ( time_t  now)

Update the cached estimate of the current time. This function SHOULD be called once per second, and MUST be called before the first call to get_approx_time.

Definition at line 41 of file approx_time.c.

References cached_approx_time.

Variable Documentation

◆ cached_approx_time

time_t cached_approx_time = 0
static

Cached estimate of the current time. Updated around once per second; may be a few seconds off if we are really busy. This is a hack to avoid calling time(NULL) (which not everybody has optimized) on critical paths.

Definition at line 25 of file approx_time.c.

Referenced by approx_time(), and update_approx_time().

◆ sys_wallclock

const subsys_fns_t sys_wallclock
Initial value:
= {
.name = "wallclock",
.supported = true,
.level = -99,
.initialize = subsys_wallclock_initialize,
}

Definition at line 54 of file approx_time.c.