From 1454b76482d42e78c1904028de55d82261e5ecaa Mon Sep 17 00:00:00 2001 From: JerryH Date: Fri, 10 Dec 2021 09:06:44 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3gmtime=E5=92=8Clocalti?= =?UTF-8?q?me=E6=8E=A5=E5=8F=A3=E7=94=B1=E4=BA=8Eg=5Ftm=E5=85=A8=E5=B1=80?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E5=AF=BC=E8=87=B4=E7=9A=84=E7=AB=9E=E6=80=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 删除全局变量,接口使用自己的内部静态变量,避免竞态 Close #I4LW3H Signed-off-by: JerryH Change-Id: I3c74b1897b3909df93d21b9d521af270cc6fc610 --- kal/posix/src/time.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/kal/posix/src/time.c b/kal/posix/src/time.c index 0f54fca3..8e1dbb5b 100644 --- a/kal/posix/src/time.c +++ b/kal/posix/src/time.c @@ -63,9 +63,6 @@ STATIC const UINT8 g_montbl[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, */ long timezone = -8 * 60 * 60; // defaults to CST: 8 hours east of the Prime Meridian -/* internal shared struct tm object for localtime and gmtime */ -static struct tm g_tm; - int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { UINT64 nseconds; @@ -508,7 +505,8 @@ struct tm *gmtime_r(const time_t *timep, struct tm *result) struct tm *gmtime(const time_t *timer) { - return gmtime_r(timer, &g_tm); + static struct tm tm; + return gmtime_r(timer, &tm); } struct tm *localtime_r(const time_t *timep, struct tm *result) @@ -526,7 +524,8 @@ struct tm *localtime_r(const time_t *timep, struct tm *result) struct tm *localtime(const time_t *timer) { - return localtime_r(timer, &g_tm); + static struct tm tm; + return localtime_r(timer, &tm); } static time_t ConvertUtc2Secs(struct tm *tm)