#ifdef DO_PTHREADS
/*
* Initialize the TSD key. By doing this at library load time, we're
* implicitly running without interference from other threads, so there's
* no need for locking.
*/
static void
_mtctxres_init(void) {
int pthread_keycreate_ret;
/*
* To support binaries that used the private MT-safe interface in
* Solaris 8, we still need to provide the __res_enable_mt()
* and __res_disable_mt() entry points. They're do-nothing routines.
*/
int
__res_enable_mt(void) {
return (-1);
}
int
__res_disable_mt(void) {
return (0);
}
#ifdef DO_PTHREADS
static int
__res_init_ctx(void) {
/*
* This if clause should only be executed if we are linking
* statically. When linked dynamically _mtctxres_init() should
* be called at binding time due the #pragma above.
*/
if (!mt_key_initialized) {
static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
if (pthread_mutex_lock(&keylock) == 0) {
_mtctxres_init();
(void) pthread_mutex_unlock(&keylock);
}
}
/*
* If we have already been called in this thread return the existing
* context. Otherwise recreat a new context and return it. If
* that fails return a global context.
*/
if (mt_key_initialized) {
if (((mt = pthread_getspecific(key)) != 0) ||
(__res_init_ctx() == 0 &&
(mt = pthread_getspecific(key)) != 0)) {
return (mt);
}
}
#endif
return (&sharedctx);
}