From 8b84d197713a2942d20e78db1e0056be42542154 Mon Sep 17 00:00:00 2001 From: wangbowen6 Date: Fri, 9 Sep 2022 12:00:07 +0800 Subject: [PATCH] lib_localtime: gmtime_r should get right time in OS init process Enable CONFIG_LIBC_LOCALTIME,CONFIG_RTC and CONFIG_SCHED_TICKLESS In os clock init process, clock_initialize() --> ... --> sim_rtc_rdtime() --> gmtime_r() --> gmtsub() --> return NULL get the error rtctime. Signed-off-by: wangbowen6 --- libs/libc/time/lib_localtime.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c index a5ad8fa862..7cb3333323 100644 --- a/libs/libc/time/lib_localtime.c +++ b/libs/libc/time/lib_localtime.c @@ -59,6 +59,7 @@ #include #include +#include #include #include @@ -1768,7 +1769,7 @@ static FAR struct tm *gmtsub(FAR const time_t *timep, if (!g_gmt_isset) { #ifndef __KERNEL__ - if (up_interrupt_context() || sched_idletask()) + if (up_interrupt_context() || (sched_idletask() && OSINIT_IDLELOOP())) { return NULL; } @@ -2486,7 +2487,7 @@ void tzset(void) FAR const char *name; #ifndef __KERNEL__ - if (up_interrupt_context() || sched_idletask()) + if (up_interrupt_context() || (sched_idletask() && OSINIT_IDLELOOP())) { return; }