tzset: avoid taking semaphore in interrupt for non-kernel mode

Change-Id: Ic72819eddb38621751e462fe32e9e433288fb33c
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2021-07-30 17:07:51 +08:00 committed by Xiang Xiao
parent cec6aeb059
commit 8f7ad8f9ce
1 changed files with 24 additions and 9 deletions

View File

@ -1817,19 +1817,28 @@ static FAR struct tm *localsub(FAR const time_t *timep,
static FAR struct tm *gmtsub(FAR const time_t *timep,
int_fast32_t offset, FAR struct tm *tmp)
{
tz_semtake(&g_gmt_sem);
if (!g_gmt_isset)
{
g_gmt_ptr = lib_malloc(sizeof *g_gmt_ptr);
if (g_gmt_ptr != NULL)
#ifndef __KERNEL__
if (up_interrupt_context())
{
gmtload(g_gmt_ptr);
g_gmt_isset = 1;
return NULL;
}
}
#endif
tz_semgive(&g_gmt_sem);
tz_semtake(&g_gmt_sem);
if (!g_gmt_isset)
{
g_gmt_ptr = lib_malloc(sizeof *g_gmt_ptr);
if (g_gmt_ptr != NULL)
{
gmtload(g_gmt_ptr);
g_gmt_isset = 1;
}
}
tz_semgive(&g_gmt_sem);
}
tmp->tm_zone = GMT;
return timesub(timep, offset, g_gmt_ptr, tmp);
@ -2528,8 +2537,14 @@ void tzset(void)
{
FAR const char *name;
tz_semtake(&g_lcl_sem);
#ifndef __KERNEL__
if (up_interrupt_context())
{
return;
}
#endif
tz_semtake(&g_lcl_sem);
name = getenv("TZ");
if (name == NULL)
{