This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 8f7ad8f tzset: avoid taking semaphore in interrupt for non-kernel mode
8f7ad8f is described below
commit 8f7ad8f9cee7a808a37b61e2dad2e4b63514cb4d
Author: Jiuzhu Dong <[email protected]>
AuthorDate: Fri Jul 30 17:07:51 2021 +0800
tzset: avoid taking semaphore in interrupt for non-kernel mode
Change-Id: Ic72819eddb38621751e462fe32e9e433288fb33c
Signed-off-by: Jiuzhu Dong <[email protected]>
---
libs/libc/time/lib_localtime.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/libs/libc/time/lib_localtime.c b/libs/libc/time/lib_localtime.c
index e94b623..66e90c7 100644
--- a/libs/libc/time/lib_localtime.c
+++ b/libs/libc/time/lib_localtime.c
@@ -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_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);
+ 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)
{