svn commit: r199607 - head/lib/libc/stdtime
John Baldwin
jhb at FreeBSD.org
Fri Nov 20 19:21:33 UTC 2009
Author: jhb
Date: Fri Nov 20 19:21:33 2009
New Revision: 199607
URL: http://svn.freebsd.org/changeset/base/199607
Log:
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
Modified:
head/lib/libc/stdtime/localtime.c
Modified: head/lib/libc/stdtime/localtime.c
==============================================================================
--- head/lib/libc/stdtime/localtime.c Fri Nov 20 19:19:51 2009 (r199606)
+++ head/lib/libc/stdtime/localtime.c Fri Nov 20 19:21:33 2009 (r199607)
@@ -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
/*
More information about the svn-src-head
mailing list