Reduce lock contention for simple cases.
# this really should be done with pthread_once, but I've debugged this code. Reviewed by: arch@
This commit is contained in:
parent
7d62c26d32
commit
d140ab1c44
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user