Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit53b5455

Browse files
committed
Improve thread test program to show if non-*_r functions are even called.
1 parent37fa3b6 commit53b5455

File tree

1 file changed

+76
-2
lines changed

1 file changed

+76
-2
lines changed

‎src/tools/thread/thread_test.c

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
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 $
1010
*
1111
*This program tests to see if your standard libc functions use
1212
*pthread_setspecific()/pthread_getspecific() to be thread-safe.
@@ -32,6 +32,8 @@
3232
#include<fcntl.h>
3333
#include<errno.h>
3434

35+
#include"postgres.h"
36+
3537
voidfunc_call_1(void);
3638
voidfunc_call_2(void);
3739

@@ -52,6 +54,11 @@ struct passwd *passwd_p2;
5254
structhostent*hostent_p1;
5355
structhostent*hostent_p2;
5456

57+
boolgethostbyname_threadsafe;
58+
boolgetpwuid_threadsafe;
59+
boolstrerror_threadsafe;
60+
boolplatform_is_threadsafe= true;
61+
5562
pthread_mutex_tinit_mutex=PTHREAD_MUTEX_INITIALIZER;
5663

5764
intmain(intargc,char*argv[])
@@ -90,26 +97,93 @@ defines to your template/$port file before compiling this program.\n\n"
9097
printf("Add this to your template/$port file:\n\n");
9198

9299
if (strerror_p1!=strerror_p2)
100+
{
93101
printf("STRERROR_THREADSAFE=yes\n");
102+
strerror_threadsafe= true;
103+
}
94104
else
105+
{
95106
printf("STRERROR_THREADSAFE=no\n");
107+
strerror_threadsafe= false;
108+
}
96109

97110
if (passwd_p1!=passwd_p2)
111+
{
98112
printf("GETPWUID_THREADSAFE=yes\n");
113+
getpwuid_threadsafe= true;
114+
}
99115
else
116+
{
100117
printf("GETPWUID_THREADSAFE=no\n");
118+
getpwuid_threadsafe= false;
119+
}
101120

102121
if (hostent_p1!=hostent_p2)
122+
{
103123
printf("GETHOSTBYNAME_THREADSAFE=yes\n");
124+
gethostbyname_threadsafe= true;
125+
}
104126
else
127+
{
105128
printf("GETHOSTBYNAME_THREADSAFE=no\n");
129+
gethostbyname_threadsafe= false;
130+
}
106131

107132
pthread_mutex_unlock(&init_mutex);/* let children exit */
108133

109134
pthread_join(thread1,NULL);/* clean up children */
110135
pthread_join(thread2,NULL);
111136

112-
return0;
137+
printf("\n");
138+
139+
#ifdefHAVE_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+
#ifdefHAVE_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+
#ifdefHAVE_GETADDRINFO
162+
printf("Your system has getaddrinfo(), so it doesn't use gethostbyname()\n"
163+
"or gethostbyname_r().\n");
164+
#else
165+
#ifdefHAVE_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+
return1;
181+
}
182+
else
183+
{
184+
printf("\nYOUR PLATFORM IS THREADSAFE\n");
185+
return0;
186+
}
113187
}
114188

115189
voidfunc_call_1(void) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp