diff options
author | imp <imp@FreeBSD.org> | 2007-12-19 04:30:10 +0000 |
---|---|---|
committer | imp <imp@FreeBSD.org> | 2007-12-19 04:30:10 +0000 |
commit | d140ab1c44b82f92710f7b1a2d09683f0ecad564 (patch) | |
tree | 24c8a2c90b3245d7162c681dbe67e315bc5d5b02 /lib/libc | |
parent | 7d62c26d32f26bb512e46641895d835b39402b0c (diff) | |
download | FreeBSD-src-d140ab1c44b82f92710f7b1a2d09683f0ecad564.zip FreeBSD-src-d140ab1c44b82f92710f7b1a2d09683f0ecad564.tar.gz |
Reduce lock contention for simple cases.
# this really should be done with pthread_once, but I've debugged this code.
Reviewed by: arch@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdtime/localtime.c | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index 827b140..bbffea5 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -1093,14 +1093,16 @@ const time_t * const timep; struct tm *p_tm; if (__isthreaded != 0) { - _pthread_mutex_lock(&localtime_mutex); if (localtime_key < 0) { - if (_pthread_key_create(&localtime_key, free) < 0) { - _pthread_mutex_unlock(&localtime_mutex); - return(NULL); + _pthread_mutex_lock(&localtime_mutex); + if (localtime_key < 0) { + if (_pthread_key_create(&localtime_key, free) < 0) { + _pthread_mutex_unlock(&localtime_mutex); + return(NULL); + } } + _pthread_mutex_unlock(&localtime_mutex); } - _pthread_mutex_unlock(&localtime_mutex); p_tm = _pthread_getspecific(localtime_key); if (p_tm == NULL) { if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) @@ -1146,16 +1148,18 @@ const time_t * const timep; const long offset; struct tm * const tmp; { - _MUTEX_LOCK(&gmt_mutex); if (!gmt_is_set) { - gmt_is_set = TRUE; + _MUTEX_LOCK(&gmt_mutex); + if (!gmt_is_set) { #ifdef ALL_STATE - gmtptr = (struct state *) malloc(sizeof *gmtptr); - if (gmtptr != NULL) + gmtptr = (struct state *) malloc(sizeof *gmtptr); + if (gmtptr != NULL) #endif /* defined ALL_STATE */ - gmtload(gmtptr); + gmtload(gmtptr); + gmt_is_set = TRUE; + } + _MUTEX_UNLOCK(&gmt_mutex); } - _MUTEX_UNLOCK(&gmt_mutex); timesub(timep, offset, gmtptr, tmp); #ifdef TM_ZONE /* @@ -1187,14 +1191,16 @@ const time_t * const timep; struct tm *p_tm; if (__isthreaded != 0) { - _pthread_mutex_lock(&gmtime_mutex); if (gmtime_key < 0) { - if (_pthread_key_create(&gmtime_key, free) < 0) { - _pthread_mutex_unlock(&gmtime_mutex); - return(NULL); + _pthread_mutex_lock(&gmtime_mutex); + if (gmtime_key < 0) { + if (_pthread_key_create(&gmtime_key, free) < 0) { + _pthread_mutex_unlock(&gmtime_mutex); + return(NULL); + } } + _pthread_mutex_unlock(&gmtime_mutex); } - _pthread_mutex_unlock(&gmtime_mutex); /* * Changed to follow POSIX.1 threads standard, which * is what BSD currently has. |