77 *
88 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
99 *
10- * $Id: thread.c,v 1.12 2003/10/26 04:29:15 momjian Exp $
10+ * $Id: thread.c,v 1.13 2003/11/24 13:16:22 petere Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
2121#else
2222#include <pwd.h>
2323#endif
24- #if defined(USE_THREADS )
24+ #if defined(ENABLE_THREAD_SAFETY )
2525#include <pthread.h>
2626#endif
2727
7373char *
7474pqStrerror (int errnum ,char * strerrbuf ,size_t buflen )
7575{
76- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& defined(HAVE_STRERROR_R )
76+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& defined(HAVE_STRERROR_R )
7777/* reentrant strerror_r is available */
7878/* some early standards had strerror_r returning char * */
7979strerror_r (errnum ,strerrbuf ,buflen );
8080return strerrbuf ;
8181
8282#else
8383
84- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_STRERROR_R )
84+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_STRERROR_R )
8585static pthread_mutex_t strerror_lock = PTHREAD_MUTEX_INITIALIZER ;
8686pthread_mutex_lock (& strerror_lock );
8787#endif
8888
8989/* no strerror_r() available, just use strerror */
9090StrNCpy (strerrbuf ,strerror (errnum ),buflen );
9191
92- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_STRERROR_R )
92+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_STRERROR_R )
9393pthread_mutex_unlock (& strerror_lock );
9494#endif
9595
106106pqGetpwuid (uid_t uid ,struct passwd * resultbuf ,char * buffer ,
107107size_t buflen ,struct passwd * * result )
108108{
109- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& defined(HAVE_GETPWUID_R )
109+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& defined(HAVE_GETPWUID_R )
110110/*
111111 * Early POSIX draft of getpwuid_r() returns 'struct passwd *'.
112112 * getpwuid_r(uid, resultbuf, buffer, buflen)
@@ -117,15 +117,15 @@ pqGetpwuid(uid_t uid, struct passwd *resultbuf, char *buffer,
117117
118118#else
119119
120- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETPWUID_R )
120+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETPWUID_R )
121121static pthread_mutex_t getpwuid_lock = PTHREAD_MUTEX_INITIALIZER ;
122122pthread_mutex_lock (& getpwuid_lock );
123123#endif
124124
125125/* no getpwuid_r() available, just use getpwuid() */
126126* result = getpwuid (uid );
127127
128- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETPWUID_R )
128+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETPWUID_R )
129129
130130/* Use 'buffer' memory for storage of strings used by struct passwd */
131131if (* result &&
@@ -181,7 +181,7 @@ pqGethostbyname(const char *name,
181181struct hostent * * result ,
182182int * herrno )
183183{
184- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& defined(HAVE_GETHOSTBYNAME_R )
184+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& defined(HAVE_GETHOSTBYNAME_R )
185185/*
186186 * broken (well early POSIX draft) gethostbyname_r() which returns
187187 * 'struct hostent *'
@@ -191,15 +191,15 @@ pqGethostbyname(const char *name,
191191
192192#else
193193
194- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETHOSTBYNAME_R )
194+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETHOSTBYNAME_R )
195195static pthread_mutex_t gethostbyname_lock = PTHREAD_MUTEX_INITIALIZER ;
196196pthread_mutex_lock (& gethostbyname_lock );
197197#endif
198198
199199/* no gethostbyname_r(), just use gethostbyname() */
200200* result = gethostbyname (name );
201201
202- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETHOSTBYNAME_R )
202+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETHOSTBYNAME_R )
203203
204204/*
205205 *Use 'buffer' memory for storage of structures used by struct hostent.
@@ -268,7 +268,7 @@ pqGethostbyname(const char *name,
268268if (* result != NULL )
269269* herrno = h_errno ;
270270
271- #if defined(FRONTEND )&& defined(USE_THREADS )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETHOSTBYNAME_R )
271+ #if defined(FRONTEND )&& defined(ENABLE_THREAD_SAFETY )&& defined(NEED_REENTRANT_FUNCS )&& !defined(HAVE_GETHOSTBYNAME_R )
272272pthread_mutex_unlock (& gethostbyname_lock );
273273#endif
274274