Remove unused function: dns_randfn_() in dns.c.
[tor.git] / src / lib / wallclock / approx_time.c
blobee498702d5c31b87824e482d913e0d8f0561a7d5
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 */
6 /**
7 * \file approx_time.c
8 * \brief Cache the last result of time(), for performance and testing.
9 **/
11 #include "orconfig.h"
12 #include "lib/wallclock/approx_time.h"
14 /* =====
15 * Cached time
16 * ===== */
18 #ifndef TIME_IS_FAST
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
28 * anywhere else. */
29 time_t
30 approx_time(void)
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
37 * get_approx_time. */
38 void
39 update_approx_time(time_t now)
41 cached_approx_time = now;
43 #endif /* !defined(TIME_IS_FAST) */