1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/lib/libc/resolv/mtctxres.c 156956 2006-03-21 15:37:16Z ume $");
3
4#include <port_before.h>
5#ifdef DO_PTHREADS
6#include <pthread.h>
7#ifdef _LIBC
8#include <pthread_np.h>
9#endif
10#endif
--- 102 unchanged lines hidden (view full) ---
113
114 /*
115 * This if clause should only be executed if we are linking
116 * statically. When linked dynamically _mtctxres_init() should
117 * be called at binding time due the #pragma above.
118 */
119 if (!mt_key_initialized) {
120 static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
121 pthread_mutex_lock(&keylock);
122 _mtctxres_init();
123 pthread_mutex_unlock(&keylock);
124 }
125
126 /*
127 * If we have already been called in this thread return the existing
128 * context. Otherwise recreat a new context and return it. If
129 * that fails return a global context.
130 */
131 if (mt_key_initialized) {
132 if (((mt = pthread_getspecific(key)) != 0) ||
133 (__res_init_ctx() == 0 &&
134 (mt = pthread_getspecific(key)) != 0)) {
135 return (mt);
136 }
137 }
138#endif
139 return (&sharedctx);
140}
2__FBSDID("$FreeBSD: head/lib/libc/resolv/mtctxres.c 156956 2006-03-21 15:37:16Z ume $");
3
4#include <port_before.h>
5#ifdef DO_PTHREADS
6#include <pthread.h>
7#ifdef _LIBC
8#include <pthread_np.h>
9#endif
10#endif
--- 102 unchanged lines hidden (view full) ---
113
114 /*
115 * This if clause should only be executed if we are linking
116 * statically. When linked dynamically _mtctxres_init() should
117 * be called at binding time due the #pragma above.
118 */
119 if (!mt_key_initialized) {
120 static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
121 pthread_mutex_lock(&keylock);
122 _mtctxres_init();
123 pthread_mutex_unlock(&keylock);
124 }
125
126 /*
127 * If we have already been called in this thread return the existing
128 * context. Otherwise recreat a new context and return it. If
129 * that fails return a global context.
130 */
131 if (mt_key_initialized) {
132 if (((mt = pthread_getspecific(key)) != 0) ||
133 (__res_init_ctx() == 0 &&
134 (mt = pthread_getspecific(key)) != 0)) {
135 return (mt);
136 }
137 }
138#endif
139 return (&sharedctx);
140}