1 /* Copyright (c) 2003, Roger Dingledine
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
8 * \brief Cache the last result of time(), for performance and testing.
12 #include "lib/wallclock/approx_time.h"
19 /** Cached estimate of the current time. Updated around once per second;
20 * may be a few seconds off if we are really busy. This is a hack to avoid
21 * calling time(NULL) (which not everybody has optimized) on critical paths.
23 static time_t cached_approx_time
= 0;
25 /** Return a cached estimate of the current time from when
26 * update_approx_time() was last called. This is a hack to avoid calling
27 * time(NULL) on critical paths: please do not even think of calling it
32 return cached_approx_time
;
35 /** Update the cached estimate of the current time. This function SHOULD be
36 * called once per second, and MUST be called before the first call to
39 update_approx_time(time_t now
)
41 cached_approx_time
= now
;
43 #endif /* !defined(TIME_IS_FAST) */