36
36
#include "private/threads.h"
37
37
#include "private/xpath.h"
38
38
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
-
98
39
/*
99
40
* TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
100
41
* to avoid some craziness since xmlMalloc/xmlFree may actually
130
71
xmlInitMutex (xmlMutexPtr mutex )
131
72
{
132
73
#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 );
135
75
#elif defined HAVE_WIN32_THREADS
136
76
InitializeCriticalSection (& mutex -> cs );
137
77
#else
168
108
xmlCleanupMutex (xmlMutexPtr mutex )
169
109
{
170
110
#ifdef HAVE_POSIX_THREADS
171
- if (XML_IS_NEVER_THREADED () == 0 )
172
- pthread_mutex_destroy (& mutex -> lock );
111
+ pthread_mutex_destroy (& mutex -> lock );
173
112
#elif defined HAVE_WIN32_THREADS
174
113
DeleteCriticalSection (& mutex -> cs );
175
114
#else
@@ -209,8 +148,7 @@ xmlMutexLock(xmlMutexPtr tok)
209
148
* This assumes that __libc_single_threaded won't change while the
210
149
* lock is held.
211
150
*/
212
- if (XML_IS_THREADED () != 0 )
213
- pthread_mutex_lock (& tok -> lock );
151
+ pthread_mutex_lock (& tok -> lock );
214
152
#elif defined HAVE_WIN32_THREADS
215
153
EnterCriticalSection (& tok -> cs );
216
154
#endif
@@ -229,8 +167,7 @@ xmlMutexUnlock(xmlMutexPtr tok)
229
167
if (tok == NULL )
230
168
return ;
231
169
#ifdef HAVE_POSIX_THREADS
232
- if (XML_IS_THREADED () != 0 )
233
- pthread_mutex_unlock (& tok -> lock );
170
+ pthread_mutex_unlock (& tok -> lock );
234
171
#elif defined HAVE_WIN32_THREADS
235
172
LeaveCriticalSection (& tok -> cs );
236
173
#endif
@@ -254,12 +191,10 @@ xmlNewRMutex(void)
254
191
if ((tok = malloc (sizeof (xmlRMutex ))) == NULL )
255
192
return (NULL );
256
193
#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 );
263
198
#elif defined HAVE_WIN32_THREADS
264
199
InitializeCriticalSection (& tok -> cs );
265
200
#endif
@@ -279,10 +214,8 @@ xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
279
214
if (tok == NULL )
280
215
return ;
281
216
#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 );
286
219
#elif defined HAVE_WIN32_THREADS
287
220
DeleteCriticalSection (& tok -> cs );
288
221
#endif
@@ -301,9 +234,6 @@ xmlRMutexLock(xmlRMutexPtr tok)
301
234
if (tok == NULL )
302
235
return ;
303
236
#ifdef HAVE_POSIX_THREADS
304
- if (XML_IS_THREADED () == 0 )
305
- return ;
306
-
307
237
pthread_mutex_lock (& tok -> lock );
308
238
if (tok -> held ) {
309
239
if (pthread_equal (tok -> tid , pthread_self ())) {
@@ -337,9 +267,6 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
337
267
if (tok == NULL )
338
268
return ;
339
269
#ifdef HAVE_POSIX_THREADS
340
- if (XML_IS_THREADED () == 0 )
341
- return ;
342
-
343
270
pthread_mutex_lock (& tok -> lock );
344
271
tok -> held -- ;
345
272
if (tok -> held == 0 ) {
@@ -377,8 +304,6 @@ xmlGetThreadId(void)
377
304
pthread_t id ;
378
305
int ret ;
379
306
380
- if (XML_IS_THREADED () == 0 )
381
- return (0 );
382
307
id = pthread_self ();
383
308
/* horrible but preserves compat, see warning above */
384
309
memcpy (& ret , & id , sizeof (ret ));
@@ -464,33 +389,8 @@ static void
464
389
xmlGlobalInitMutexLock (void ) {
465
390
#ifdef HAVE_POSIX_THREADS
466
391
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
-
491
392
/* 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 );
494
394
495
395
#elif defined HAVE_WIN32_THREADS
496
396
@@ -532,8 +432,7 @@ xmlGlobalInitMutexLock(void) {
532
432
static void
533
433
xmlGlobalInitMutexUnlock (void ) {
534
434
#ifdef HAVE_POSIX_THREADS
535
- if (XML_IS_THREADED () != 0 )
536
- pthread_mutex_unlock (& global_init_lock );
435
+ pthread_mutex_unlock (& global_init_lock );
537
436
#elif defined HAVE_WIN32_THREADS
538
437
if (global_init_lock != NULL )
539
438
LeaveCriticalSection (global_init_lock );
0 commit comments