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
| 2195 | * such info only when calling this function from serverCron() but not when |
| 2196 | * calling it from call(). */ |
| 2197 | void 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 | |
| 2216 | void checkChildrenDone(void) { |
| 2217 | int statloc = 0; |
no test coverage detected