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

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

#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  )

Return a cached estimate of the current time from when update_approx_time() was last called. This is a hack to avoid calling time(NULL) on critical paths: please do not even think of calling it anywhere else.

Definition at line 32 of file approx_time.c.

Referenced by build_service_desc_plaintext(), circpad_cell_event_nonpadding_received(), circpad_cell_event_padding_received(), circuit_build_times_needs_circuits_now(), circuit_build_times_network_is_live(), circuit_set_n_circid_chan(), circuit_set_p_circid_chan(), connection_ap_handle_onion(), connection_ap_handshake_attach_chosen_circuit(), connection_buf_read_from_socket(), connection_edge_flushed_some(), connection_edge_process_inbuf(), connection_handle_read_impl(), dirauth_get_voting_schedule(), dnsserv_launch_request(), entry_guard_consider_retry(), entry_guard_state_should_expire(), entry_guards_note_guard_failure(), entry_guards_note_guard_success(), entry_guards_note_internet_connectivity(), get_guard_state_for_bridge_desc_fetch(), handle_response_fetch_consensus(), have_been_under_memory_pressure(), hs_get_responsible_hsdirs(), hs_get_time_period_num(), log_master_signing_key_cert_expiration(), lookup_v3_desc_as_client(), mark_circuit_unusable_for_new_conns(), microdesc_note_outdated_dirserver(), networkstatus_set_current_consensus(), overload_happened_recently(), reasonably_live_consensus_is_missing(), router_descriptor_is_older_than(), routerlist_descriptors_added(), should_collect_v3_stats(), sr_get_current(), and sr_get_previous().

◆ subsys_wallclock_initialize()

static int subsys_wallclock_initialize ( void  )
static

Initialize the "wallclock" subsystem by setting the current cached time.

Definition at line 51 of file approx_time.c.

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

Referenced by subsys_wallclock_initialize().

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 = -98,
}
static int subsys_wallclock_initialize(void)
Definition: approx_time.c:51
#define SUBSYS_DECLARE_LOCATION()
Definition: subsys.h:211

Subsystem function table describing the "wallclock" subsystem.

Definition at line 60 of file approx_time.c.