From fc881afd0a8e7020085abef669fbd423e6e02d6c Mon Sep 17 00:00:00 2001 From: Binbin Date: Mon, 5 Aug 2024 18:56:41 +0800 Subject: [PATCH] Change server.daylight_active to an atomic variable Signed-off-by: Binbin --- src/server.c | 5 +++-- src/server.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/server.c b/src/server.c index d332e6989c..4905c0a8c1 100644 --- a/src/server.c +++ b/src/server.c @@ -131,10 +131,11 @@ void serverLogRaw(int level, const char *msg) { struct timeval tv; int role_char; pid_t pid = getpid(); + int daylight_active = atomic_load_explicit(&server.daylight_active, memory_order_relaxed); gettimeofday(&tv, NULL); struct tm tm; - nolocks_localtime(&tm, tv.tv_sec, server.timezone, server.daylight_active); + nolocks_localtime(&tm, tv.tv_sec, server.timezone, daylight_active); off = strftime(buf, sizeof(buf), "%d %b %Y %H:%M:%S.", &tm); snprintf(buf + off, sizeof(buf) - off, "%03d", (int)tv.tv_usec / 1000); if (server.sentinel_mode) { @@ -1091,7 +1092,7 @@ static inline void updateCachedTimeWithUs(int update_daylight_info, const long l struct tm tm; time_t ut = server.unixtime; localtime_r(&ut, &tm); - server.daylight_active = tm.tm_isdst; + atomic_store_explicit(&server.daylight_active, tm.tm_isdst, memory_order_relaxed); } } diff --git a/src/server.h b/src/server.h index ccdece20dd..f73f1c8642 100644 --- a/src/server.h +++ b/src/server.h @@ -2114,7 +2114,7 @@ struct valkeyServer { /* time cache */ time_t unixtime; /* Unix time sampled every cron cycle. */ time_t timezone; /* Cached timezone. As set by tzset(). */ - int daylight_active; /* Currently in daylight saving time. */ + _Atomic int daylight_active; /* Currently in daylight saving time. */ mstime_t mstime; /* 'unixtime' in milliseconds. */ ustime_t ustime; /* 'unixtime' in microseconds. */ mstime_t cmd_time_snapshot; /* Time snapshot of the root execution nesting. */