MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / updateCachedTime

Function updateCachedTime

src/server.cpp:2197–2214  ·  view source on GitHub ↗

We take a cached value of the unix time in the global state because with * virtual memory and aging there is to store the current time in objects at * every object access, and accuracy is not needed. To access a global var is * a lot faster than calling time(NULL). * * This function should be fast because it is called at every command execution * in call(), so it is possible to decide if to

Source from the content-addressed store, hash-verified

2195 * such info only when calling this function from serverCron() but not when
2196 * calling it from call(). */
2197void updateCachedTime() {
2198 long long t = ustime();
2199 __atomic_store(&g_pserver->ustime, &t, __ATOMIC_RELAXED);
2200 t /= 1000;
2201 __atomic_store(&g_pserver->mstime, &t, __ATOMIC_RELAXED);
2202 t /= 1000;
2203 g_pserver->unixtime = t;
2204
2205 /* To get information about daylight saving time, we need to call
2206 * localtime_r and cache the result. However calling localtime_r in this
2207 * context is safe since we will never fork() while here, in the main
2208 * thread. The logging function will call a thread safe version of
2209 * localtime that has no locks. */
2210 struct tm tm;
2211 time_t ut = g_pserver->unixtime;
2212 localtime_r(&ut,&tm);
2213 __atomic_store(&g_pserver->daylight_active, &tm.tm_isdst, __ATOMIC_RELAXED);
2214}
2215
2216void checkChildrenDone(void) {
2217 int statloc = 0;

Callers 3

initServerConfigFunction · 0.85
wakeTimeThreadFunction · 0.85
timeThreadMainFunction · 0.85

Calls 1

ustimeFunction · 0.70

Tested by

no test coverage detected