[tz] [PROPOSED PATCH 3/4] * localtime.c: Lessen lock overhead for gmtime etc.

Paul Eggert eggert at cs.ucla.edu
Sat Aug 23 01:42:27 UTC 2014


(gmtcheck): Lock only if !gmt_is_set.
(gmtime_r, offtime, timeoff): Do not lock; gmtcheck now does this.
---
 localtime.c | 22 +++-------------------
 1 file changed, 3 insertions(+), 19 deletions(-)

diff --git a/localtime.c b/localtime.c
index 67b1d78..8260625 100644
--- a/localtime.c
+++ b/localtime.c
@@ -1244,12 +1244,15 @@ gmtcheck(void)
 {
   if (gmt_is_set)
     return;
+  if (lock() != 0)
+    return;
 #ifdef ALL_STATE
   gmtptr = malloc(sizeof *gmtptr);
 #endif
   if (gmtptr)
     gmtload(gmtptr);
   gmt_is_set = true;
+  unlock();
 }
 
 /*
@@ -1404,14 +1407,8 @@ gmtime(const time_t *const timep)
 struct tm *
 gmtime_r(const time_t *const timep, struct tm *tmp)
 {
-  int err = lock();
-  if (err) {
-    errno = err;
-    return NULL;
-  }
   gmtcheck();
   tmp = gmtsub(timep, 0, tmp);
-  unlock();
   return tmp;
 }
 
@@ -1421,14 +1418,8 @@ struct tm *
 offtime(const time_t *const timep, const long offset)
 {
   struct tm *tmp;
-  int err = lock();
-  if (err) {
-    errno = err;
-    return NULL;
-  }
   gmtcheck();
   tmp = gmtsub(timep, offset, &tm);
-  unlock();
   return tmp;
 }
 
@@ -1996,17 +1987,10 @@ time_t
 timeoff(struct tm *const tmp, const long offset)
 {
   time_t t;
-  int err;
   if (tmp)
     tmp->tm_isdst = 0;
-  err = lock();
-  if (err) {
-    errno = err;
-    return -1;
-  }
   gmtcheck();
   t = time1(tmp, gmtsub, offset);
-  unlock();
   return t;
 }
 
-- 
1.9.1



More information about the tz mailing list