Deleted Added
sdiff udiff text old ( 156956 ) new ( 165258 )
full compact
1#include <sys/cdefs.h>
2__FBSDID("$FreeBSD: head/lib/libc/resolv/mtctxres.c 165258 2006-12-15 20:59:55Z 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 if (pthread_mutex_lock(&keylock) == 0) {
122 _mtctxres_init();
123 (void) pthread_mutex_unlock(&keylock);
124 }
125 }
126
127 /*
128 * If we have already been called in this thread return the existing
129 * context. Otherwise recreat a new context and return it. If
130 * that fails return a global context.
131 */
132 if (mt_key_initialized) {
133 if (((mt = pthread_getspecific(key)) != 0) ||
134 (__res_init_ctx() == 0 &&
135 (mt = pthread_getspecific(key)) != 0)) {
136 return (mt);
137 }
138 }
139#endif
140 return (&sharedctx);
141}