diff options
author | jhb <jhb@FreeBSD.org> | 2009-11-20 19:21:33 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2009-11-20 19:21:33 +0000 |
commit | 7ccf9228d7906bfeaa829ac304867443a65e7056 (patch) | |
tree | 032846f23dcd217e41613fbefeac06b2966d0ce6 /lib/libc/stdtime | |
parent | b850b4760dddafa38d7850f86e99ce47326a2676 (diff) | |
download | FreeBSD-src-7ccf9228d7906bfeaa829ac304867443a65e7056.zip FreeBSD-src-7ccf9228d7906bfeaa829ac304867443a65e7056.tar.gz |
Replace gmt_is_set and the gmt_mutex lock with a pthread_once_t variable and
an init routine run on the first invocation via _once().
MFC after: 1 week
Diffstat (limited to 'lib/libc/stdtime')
-rw-r--r-- | lib/libc/stdtime/localtime.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index 9fc5f3e..d391e3e 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -235,9 +235,8 @@ static struct state gmtmem; static char lcl_TZname[TZ_STRLEN_MAX + 1]; static int lcl_is_set; -static int gmt_is_set; +static pthread_once_t gmt_once = PTHREAD_ONCE_INIT; static pthread_rwlock_t lcl_rwlock = PTHREAD_RWLOCK_INITIALIZER; -static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER; char * tzname[2] = { wildabbr, @@ -1464,6 +1463,17 @@ struct tm * tmp; return tmp; } +static void +gmt_init(void) +{ + +#ifdef ALL_STATE + gmtptr = (struct state *) malloc(sizeof *gmtptr); + if (gmtptr != NULL) +#endif /* defined ALL_STATE */ + gmtload(gmtptr); +} + /* ** gmtsub is to gmtime as localsub is to localtime. */ @@ -1476,16 +1486,7 @@ struct tm * const tmp; { register struct tm * result; - _MUTEX_LOCK(&gmt_mutex); - if (!gmt_is_set) { -#ifdef ALL_STATE - gmtptr = (struct state *) malloc(sizeof *gmtptr); - if (gmtptr != NULL) -#endif /* defined ALL_STATE */ - gmtload(gmtptr); - gmt_is_set = TRUE; - } - _MUTEX_UNLOCK(&gmt_mutex); + _once(&gmt_once, gmt_init); result = timesub(timep, offset, gmtptr, tmp); #ifdef TM_ZONE /* |