From b3a09ae34bd691c95bc41a594a40a808455d748a Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 31 Mar 2015 11:22:50 +0200 Subject: Avoid excessive locking and calling tzset in time functions. * libc/time/lcltime_r.c (localtime_r): Call _tzset_unlocked inside TZ lock. * libc/time/mktime.c (mktime): Ditto. * libc/time/strftime.c (strftime, wcsftime): Ditto. Guard against calling _tzset_unlocked more than once (baring recursion). Signed-off-by: Corinna Vinschen --- newlib/libc/time/strftime.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'newlib/libc/time/strftime.c') diff --git a/newlib/libc/time/strftime.c b/newlib/libc/time/strftime.c index 72f06d32e..9e677346e 100644 --- a/newlib/libc/time/strftime.c +++ b/newlib/libc/time/strftime.c @@ -703,6 +703,7 @@ _DEFUN (strftime, (s, maxsize, format, tim_p), CHAR alt; CHAR pad; unsigned long width; + int tzset_called = 0; struct lc_time_T *_CurrentTimeLocale = __get_current_time_locale (); for (;;) @@ -1283,7 +1284,13 @@ recurse: if (tim_p->tm_isdst >= 0) { long offset; - tzset (); + + TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } #if defined (__CYGWIN__) /* Cygwin must check if the application has been built with or @@ -1302,6 +1309,7 @@ recurse: but have to use __tzrule for daylight savings. */ offset = -tz->__tzrule[tim_p->tm_isdst > 0].offset; #endif + TZ_UNLOCK; len = snprintf (&s[count], maxsize - count, CQ("%+03ld%.2ld"), offset / SECSPERHOUR, labs (offset / SECSPERMIN) % 60L); @@ -1314,8 +1322,12 @@ recurse: size_t size; const char *tznam = NULL; - tzset (); TZ_LOCK; + if (!tzset_called) + { + _tzset_unlocked (); + tzset_called = 1; + } #if defined (__CYGWIN__) /* See above. */ extern const char *__cygwin_gettzname (const struct tm *tmp); -- cgit v1.2.3