6
6
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
7
7
* Portions Copyright (c) 1994, Regents of the University of California
8
8
*
9
- * $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.16 2004/04/06 13:55:17 momjian Exp $
9
+ * $PostgreSQL: pgsql/src/tools/thread/thread_test.c,v 1.17 2004/04/21 20:51:54 momjian Exp $
10
10
*
11
11
* This program tests to see if your standard libc functions use
12
12
* pthread_setspecific()/pthread_getspecific() to be thread-safe.
32
32
#include <fcntl.h>
33
33
#include <errno.h>
34
34
35
+ #include "postgres.h"
36
+
35
37
void func_call_1 (void );
36
38
void func_call_2 (void );
37
39
@@ -52,6 +54,11 @@ struct passwd *passwd_p2;
52
54
struct hostent * hostent_p1 ;
53
55
struct hostent * hostent_p2 ;
54
56
57
+ bool gethostbyname_threadsafe ;
58
+ bool getpwuid_threadsafe ;
59
+ bool strerror_threadsafe ;
60
+ bool platform_is_threadsafe = true;
61
+
55
62
pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER ;
56
63
57
64
int main (int argc , char * argv [])
@@ -90,26 +97,93 @@ defines to your template/$port file before compiling this program.\n\n"
90
97
printf ("Add this to your template/$port file:\n\n" );
91
98
92
99
if (strerror_p1 != strerror_p2 )
100
+ {
93
101
printf ("STRERROR_THREADSAFE=yes\n" );
102
+ strerror_threadsafe = true;
103
+ }
94
104
else
105
+ {
95
106
printf ("STRERROR_THREADSAFE=no\n" );
107
+ strerror_threadsafe = false;
108
+ }
96
109
97
110
if (passwd_p1 != passwd_p2 )
111
+ {
98
112
printf ("GETPWUID_THREADSAFE=yes\n" );
113
+ getpwuid_threadsafe = true;
114
+ }
99
115
else
116
+ {
100
117
printf ("GETPWUID_THREADSAFE=no\n" );
118
+ getpwuid_threadsafe = false;
119
+ }
101
120
102
121
if (hostent_p1 != hostent_p2 )
122
+ {
103
123
printf ("GETHOSTBYNAME_THREADSAFE=yes\n" );
124
+ gethostbyname_threadsafe = true;
125
+ }
104
126
else
127
+ {
105
128
printf ("GETHOSTBYNAME_THREADSAFE=no\n" );
129
+ gethostbyname_threadsafe = false;
130
+ }
106
131
107
132
pthread_mutex_unlock (& init_mutex ); /* let children exit */
108
133
109
134
pthread_join (thread1 , NULL ); /* clean up children */
110
135
pthread_join (thread2 , NULL );
111
136
112
- return 0 ;
137
+ printf ("\n" );
138
+
139
+ #ifdef HAVE_STRERROR_R
140
+ printf ("Your system has sterror_r(), so it doesn't use strerror().\n" );
141
+ #else
142
+ printf ("Your system uses strerror().\n" );
143
+ if (!strerror_threadsafe )
144
+ {
145
+ platform_is_threadsafe = false;
146
+ printf ("That function is not thread-safe\n" );
147
+ }
148
+ #endif
149
+
150
+ #ifdef HAVE_GETPWUID_R
151
+ printf ("Your system has getpwuid_r(), so it doesn't use getpwuid().\n" );
152
+ #else
153
+ printf ("Your system uses getpwuid().\n" );
154
+ if (!getpwuid_threadsafe )
155
+ {
156
+ platform_is_threadsafe = false;
157
+ printf ("That function is not thread-safe\n" );
158
+ }
159
+ #endif
160
+
161
+ #ifdef HAVE_GETADDRINFO
162
+ printf ("Your system has getaddrinfo(), so it doesn't use gethostbyname()\n"
163
+ "or gethostbyname_r().\n" );
164
+ #else
165
+ #ifdef HAVE_GETHOSTBYNAME_R
166
+ printf ("Your system has gethostbyname_r(), so it doesn't use gethostbyname().\n" );
167
+ #else
168
+ printf ("Your system uses gethostbyname().\n" );
169
+ if (!gethostbyname_threadsafe )
170
+ {
171
+ platform_is_threadsafe = false;
172
+ printf ("That function is not thread-safe\n" );
173
+ }
174
+ #endif
175
+ #endif
176
+
177
+ if (!platform_is_threadsafe )
178
+ {
179
+ printf ("\n** YOUR PLATFORM IS NOT THREADSAFE **\n" );
180
+ return 1 ;
181
+ }
182
+ else
183
+ {
184
+ printf ("\nYOUR PLATFORM IS THREADSAFE\n" );
185
+ return 0 ;
186
+ }
113
187
}
114
188
115
189
void func_call_1 (void ) {
0 commit comments