8000 threads: Remove pthread weak symbol hack · GNOME/libxml2@2b0c4ab · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 2b0c4ab

Browse files
committed
threads: Remove pthread weak symbol hack
On Linux, we tried to detect the presence of libpthread to disable things like locks. This questionable hack doesn't work since glibc 2.34 which merged libpthread into libc.
1 parent 3848802 commit 2b0c4ab

File tree

4 files changed

+13
-169
lines changed

4 files changed

+13
-169
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ LDADDS = libxml2.la
108108

109109
runtest_SOURCES=runtest.c
110110
runtest_DEPENDENCIES = $(DEPS)
111-
runtest_LDADD= $(BASE_THREAD_LIBS) $(THREAD_LIBS) $(LDADDS)
111+
runtest_LDADD= $(THREAD_LIBS) $(LDADDS)
112112

113113
testrecurse_SOURCES=testrecurse.c
114114
testrecurse_DEPENDENCIES = $(DEPS)

configure.ac

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,6 @@ dnl
746746
dnl Thread-related stuff
747747
dnl
748748
THREAD_LIBS=""
749-
BASE_THREAD_LIBS=""
750749
WITH_THREADS=0
751750
WITH_THREAD_ALLOC=0
752751

@@ -776,22 +775,12 @@ else
776775
if test "$WITH_THREADS" = "0"; then
777776
AC_MSG_ERROR([libpthread not found])
778777
fi
779-
780-
case $host_os in
781-
*linux*)
782-
if test "${GCC}" = "yes" ; then
783-
BASE_THREAD_LIBS="$THREAD_LIBS"
784-
THREAD_LIBS=""
785-
fi
786-
;;
787-
esac
788778
fi
789779
if test "$with_thread_alloc" = "yes" && test "$WITH_THREADS" = "1" ; then
790780
WITH_THREAD_ALLOC=1
791781
fi
792782

793783
AC_SUBST(THREAD_LIBS)
794-
AC_SUBST(BASE_THREAD_LIBS)
795784
AC_SUBST(WITH_THREADS)
796785
AC_SUBST(WITH_THREAD_ALLOC)
797786

globals.c

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,6 @@ static XML_THREAD_LOCAL xmlGlobalState globalState;
119119

120120
#ifdef HAVE_POSIX_THREADS
121121

122-
/*
123-
* Weak symbol hack, see threads.c
124-
*/
125-
#if defined(__GNUC__) && \
126-
defined(__GLIBC__) && \
127-
__GLIBC__ * 100 + __GLIBC_MINOR__ < 234
128-
129-
#pragma weak pthread_getspecific
130-
#pragma weak pthread_setspecific
131-
#pragma weak pthread_key_create
132-
#pragma weak pthread_key_delete
133-
#pragma weak pthread_equal
134-
#pragma weak pthread_self
135-
136-
#define XML_PTHREAD_WEAK
137-
138-
static int libxml_is_threaded = -1;
139-
140-
#endif
141-
142122
/*
143123
* On POSIX, we need thread-specific data even with thread-local storage
144124
* to destroy indirect references from global state (xmlLastError) at
@@ -570,22 +550,6 @@ void xmlInitGlobalsInternal(void) {
570550
xmlInitMutex(&xmlThrDefMutex);
571551

572552
#ifdef HAVE_POSIX_THREADS
573-
#ifdef XML_PTHREAD_WEAK
574-
if (libxml_is_threaded == -1)
575-
libxml_is_threaded =
576-
(pthread_getspecific != NULL) &&
577-
(pthread_setspecific != NULL) &&
578-
(pthread_key_create != NULL) &&
579-
(pthread_key_delete != NULL) &&
580-
/*
581-
* pthread_equal can be inline, resuting in -Waddress warnings.
582-
* Let's assume it's available if all the other functions are.
583-
*/
584-
/* (pthread_equal != NULL) && */
585-
(pthread_self != NULL);
586-
if (libxml_is_threaded == 0)
587-
return;
588-
#endif /* XML_PTHREAD_WEAK */
589553
pthread_key_create(&globalkey, xmlFreeGlobalState);
590554
mainthread = pthread_self();
591555
#elif defined(HAVE_WIN32_THREADS)
@@ -623,10 +587,6 @@ void xmlCleanupGlobalsInternal(void) {
623587
xmlCleanupMutex(&xmlThrDefMutex);
624588

625589
#ifdef HAVE_POSIX_THREADS
626-
#ifdef XML_PTHREAD_WEAK
627-
if (libxml_is_threaded == 0)
628-
return;
629-
#endif /* XML_PTHREAD_WEAK */
630590
pthread_key_delete(globalkey);
631591
#elif defined(HAVE_WIN32_THREADS)
632592
#ifndef USE_TLS
@@ -672,10 +632,6 @@ xmlIsMainThreadInternal(void) {
672632
}
673633

674634
#ifdef HAVE_POSIX_THREADS
675-
#ifdef XML_PTHREAD_WEAK
676-
if (libxml_is_threaded == 0)
677-
return (1);
678-
#endif
679635
return (pthread_equal(mainthread, pthread_self()));
680636
#elif defined HAVE_WIN32_THREADS
681637
return (mainthread == GetCurrentThreadId());

threads.c

Lines changed: 12 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,6 @@
3636
#include "private/threads.h"
3737
#include "private/xpath.h"
3838

39-
#if defined(HAVE_POSIX_THREADS) && \
40-
defined(__GLIBC__) && \
41-
__GLIBC__ * 100 + __GLIBC_MINOR__ >= 234
42-
43-
/*
44-
* The modern way available since glibc 2.32.
45-
*
46-
* The check above is for glibc 2.34 which merged the pthread symbols into
47-
* libc. Since we still allow linking without pthread symbols (see below),
48-
* this only works if pthread symbols are guaranteed to be available.
49-
*/
50-
51-
#include <sys/single_threaded.h>
52-
53-
#define XML_IS_THREADED() (!__libc_single_threaded)
54-
#define XML_IS_NEVER_THREADED() 0
55-
56-
#elif defined(HAVE_POSIX_THREADS) && \
57-
defined(__GLIBC__) && \
58-
defined(__GNUC__)
59-
60-
/*
61-
* The traditional way to check for single-threaded applications with
62-
* glibc was to check whether the separate libpthread library is
63-
* linked in. This works by not linking libxml2 with libpthread (see
64-
* BASE_THREAD_LIBS in configure.ac and Makefile.am) and declaring
65-
* pthread functions as weak symbols.
66-
*
67-
* In glibc 2.34, the pthread symbols were moved from libpthread to libc,
68-
* so this doesn't work anymore.
69-
*
70-
* At some point, this legacy code and the BASE_THREAD_LIBS hack in
71-
* configure.ac can probably be removed.
72-
*/
73-
74-
#pragma weak pthread_mutex_init
75-
#pragma weak pthread_mutex_destroy
76-
#pragma weak pthread_mutex_lock
77-
#pragma weak pthread_mutex_unlock
78-
#pragma weak pthread_cond_init
79-
#pragma weak pthread_cond_destroy
80-
#pragma weak pthread_cond_wait
81-
#pragma weak pthread_equal
82-
#pragma weak pthread_self
83-
#pragma weak pthread_cond_signal
84-
85-
#define XML_PTHREAD_WEAK
86-
#define XML_IS_THREADED() libxml_is_threaded
87-
#define XML_IS_NEVER_THREADED() (!libxml_is_threaded)
88-
89-
static int libxml_is_threaded = -1;
90-
91-
#else /* other POSIX platforms */
92-
93-
#define XML_IS_THREADED() 1
94-
#define XML_IS_NEVER_THREADED() 0
95-
96-
#endif
97-
9839
/*
9940
* TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
10041
* to avoid some craziness since xmlMalloc/xmlFree may actually
@@ -130,8 +71,7 @@ void
13071
xmlInitMutex(xmlMutexPtr mutex)
13172
{
13273
#ifdef HAVE_POSIX_THREADS
133-
if (XML_IS_NEVER_THREADED() == 0)
134-
pthread_mutex_init(&mutex->lock, NULL);
74+
pthread_mutex_init(&mutex->lock, NULL);
13575
#elif defined HAVE_WIN32_THREADS
13676
InitializeCriticalSection(&mutex->cs);
13777
#else
@@ -168,8 +108,7 @@ void
168108
xmlCleanupMutex(xmlMutexPtr mutex)
169109
{
170110
#ifdef HAVE_POSIX_THREADS
171-
if (XML_IS_NEVER_THREADED() == 0)
172-
pthread_mutex_destroy(&mutex->lock);
111+
pthread_mutex_destroy(&mutex->lock);
173112
#elif defined HAVE_WIN32_THREADS
174113
DeleteCriticalSection(&mutex->cs);
175114
#else
@@ -209,8 +148,7 @@ xmlMutexLock(xmlMutexPtr tok)
209148
* This assumes that __libc_single_threaded won't change while the
210149
* lock is held.
211150
*/
212-
if (XML_IS_THREADED() != 0)
213-
pthread_mutex_lock(&tok->lock);
151+
pthread_mutex_lock(&tok->lock);
214152
#elif defined HAVE_WIN32_THREADS
215153
EnterCriticalSection(&tok->cs);
216154
#endif
@@ -229,8 +167,7 @@ xmlMutexUnlock(xmlMutexPtr tok)
229167
if (tok == NULL)
230168
return;
231169
#ifdef HAVE_POSIX_THREADS
232-
if (XML_IS_THREADED() != 0)
233-
pthread_mutex_unlock(&tok->lock);
170+
pthread_mutex_unlock(&tok->lock);
234171
#elif defined HAVE_WIN32_THREADS
235172
LeaveCriticalSection(&tok->cs);
236173
#endif
@@ -254,12 +191,10 @@ xmlNewRMutex(void)
254191
if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
255192
return (NULL);
256193
#ifdef HAVE_POSIX_THREADS
257-
if (XML_IS_NEVER_THREADED() == 0) {
258-
pthread_mutex_init(&tok->lock, NULL);
259-
tok->held = 0;
260-
tok->waiters = 0;
261-
pthread_cond_init(&tok->cv, NULL);
262-
}
194+
pthread_mutex_init(&tok->lock, NULL);
195+
tok->held = 0;
196+
tok->waiters = 0;
197+
pthread_cond_init(&tok->cv, NULL);
263198
#elif defined HAVE_WIN32_THREADS
264199
InitializeCriticalSection(&tok->cs);
265200
#endif
@@ -279,10 +214,8 @@ xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
279214
if (tok == NULL)
280215
return;
281216
#ifdef HAVE_POSIX_THREADS
282-
if (XML_IS_NEVER_THREADED() == 0) {
283-
pthread_mutex_destroy(&tok->lock);
284-
pthread_cond_destroy(&tok->cv);
285-
}
217+
pthread_mutex_destroy(&tok->lock);
218+
pthread_cond_destroy(&tok->cv);
286219
#elif defined HAVE_WIN32_THREADS
287220
DeleteCriticalSection(&tok->cs);
288221
#endif
@@ -301,9 +234,6 @@ xmlRMutexLock(xmlRMutexPtr tok)
301234
if (tok == NULL)
302235
return;
303236
#ifdef HAVE_POSIX_THREADS
304-
if (XML_IS_THREADED() == 0)
305-
return;
306-
307237
pthread_mutex_lock(&tok->lock);
308238
if (tok->held) {
309239
if (pthread_equal(tok->tid, pthread_self())) {
@@ -337,9 +267,6 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
337267
if (tok == NULL)
338268
return;
339269
#ifdef HAVE_POSIX_THREADS
340-
if (XML_IS_THREADED() == 0)
341-
return;
342-
343270
pthread_mutex_lock(&tok->lock);
344271
tok->held--;
345272
if (tok->held == 0) {
@@ -377,8 +304,6 @@ xmlGetThreadId(void)
377304
pthread_t id;
378305
int ret;
379306

380-
if (XML_IS_THREADED() == 0)
381-
return (0);
382307
id = pthread_self();
383308
/* horrible but preserves compat, see warning above */
384309
memcpy(&ret, &id, sizeof(ret));
@@ -464,33 +389,8 @@ static void
464389
xmlGlobalInitMutexLock(void) {
465390
#ifdef HAVE_POSIX_THREADS
466391

467-
#ifdef XML_PTHREAD_WEAK
468-
/*
469-
* This is somewhat unreliable since libpthread could be loaded
470-
* later with dlopen() and threads could be created. But it's
471-
* long-standing behavior and hard to work around.
472-
*/
473-
if (libxml_is_threaded == -1)
474-
libxml_is_threaded =
475-
(pthread_mutex_init != NULL) &&
476-
(pthread_mutex_destroy != NULL) &&
477-
(pthread_mutex_lock != NULL) &&
478-
(pthread_mutex_unlock != NULL) &&
479-
(pthread_cond_init != NULL) &&
480-
(pthread_cond_destroy != NULL) &&
481-
(pthread_cond_wait != NULL) &&
482-
/*
483-
* pthread_equal can be inline, resuting in -Waddress warnings.
484-
* Let's assume it's available if all the other functions are.
485-
*/
486-
/* (pthread_equal != NULL) && */
487-
(pthread_self != NULL) &&
488-
(pthread_cond_signal != NULL);
489-
#endif
490-
491392
/* The mutex is statically initialized, so we just lock it. */
492-
if (XML_IS_THREADED() != 0)
493-
pthread_mutex_lock(&global_init_lock);
393+
pthread_mutex_lock(&global_init_lock);
494394

495395
#elif defined HAVE_WIN32_THREADS
496396

@@ -532,8 +432,7 @@ xmlGlobalInitMutexLock(void) {
532432
static void
533433
xmlGlobalInitMutexUnlock(void) {
534434
#ifdef HAVE_POSIX_THREADS
535-
if (XML_IS_THREADED() != 0)
536-
pthread_mutex_unlock(&global_init_lock);
435+
pthread_mutex_unlock(&global_init_lock);
537436
#elif defined HAVE_WIN32_THREADS
538437
if (global_init_lock != NULL)
539438
LeaveCriticalSection(global_init_lock);

0 commit comments

Comments
 (0)
0