libc/time: Avoid modify the global variables concurrently in tzset
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com> Change-Id: I7fb6439c3a669ef07c1756ccc294cd487805a510
This commit is contained in:
parent
4ecabe5fc2
commit
26908f472e
|
@ -1664,11 +1664,8 @@ static void gmtload(FAR struct state_s *const sp)
|
|||
|
||||
static void tzsetwall(void)
|
||||
{
|
||||
tz_semtake(&g_lcl_sem);
|
||||
|
||||
if (g_lcl_isset < 0)
|
||||
{
|
||||
tz_semgive(&g_lcl_sem);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1685,8 +1682,6 @@ static void tzsetwall(void)
|
|||
settzname();
|
||||
|
||||
g_lcl_isset = -1;
|
||||
|
||||
tz_semgive(&g_lcl_sem);
|
||||
}
|
||||
|
||||
/* The easy way to behave "as if no library function calls" localtime
|
||||
|
@ -2523,16 +2518,18 @@ void tzset(void)
|
|||
{
|
||||
FAR const char *name;
|
||||
|
||||
tz_semtake(&g_lcl_sem);
|
||||
|
||||
name = getenv("TZ");
|
||||
if (name == NULL)
|
||||
{
|
||||
tzsetwall();
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (g_lcl_isset > 0 && strcmp(g_lcl_tzname, name) == 0)
|
||||
{
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
g_lcl_isset = strlen(name) < sizeof g_lcl_tzname;
|
||||
|
@ -2547,7 +2544,7 @@ void tzset(void)
|
|||
if (lclptr == NULL)
|
||||
{
|
||||
settzname(); /* all we can do */
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2572,6 +2569,9 @@ void tzset(void)
|
|||
}
|
||||
|
||||
settzname();
|
||||
|
||||
out:
|
||||
tz_semgive(&g_lcl_sem);
|
||||
}
|
||||
|
||||
FAR struct tm *localtime(FAR const time_t * const timep)
|
||||
|
|
Loading…
Reference in New Issue