1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

Remove HAVE_WIN32_THREADS configuration flag

Check for LIBXML_THREAD_ENABLED and _WIN32 instead.
This commit is contained in:
Nick Wellnhofer
2022-09-04 01:49:41 +02:00
parent 13a6637815
commit 1e60c76821
8 changed files with 47 additions and 58 deletions

View File

@@ -372,9 +372,7 @@ endif()
if(LIBXML2_WITH_THREADS) if(LIBXML2_WITH_THREADS)
target_compile_definitions(LibXml2 PRIVATE _REENTRANT) target_compile_definitions(LibXml2 PRIVATE _REENTRANT)
if(WIN32) if(NOT WIN32)
target_compile_definitions(LibXml2 PRIVATE HAVE_WIN32_THREADS)
else()
check_include_files(pthread.h HAVE_PTHREAD_H) check_include_files(pthread.h HAVE_PTHREAD_H)
endif() endif()
endif() endif()
@@ -524,9 +522,6 @@ if(LIBXML2_WITH_TESTS)
endforeach() endforeach()
if(Threads_FOUND) if(Threads_FOUND)
foreach(TEST runtest testThreads) foreach(TEST runtest testThreads)
if(WIN32)
target_compile_definitions(${TEST} PRIVATE HAVE_WIN32_THREADS)
endif()
target_link_libraries(${TEST} Threads::Threads) target_link_libraries(${TEST} Threads::Threads)
endforeach() endforeach()
endif() endif()

View File

@@ -919,7 +919,6 @@ else
*mingw*) *mingw*)
dnl Default to native threads on Windows dnl Default to native threads on Windows
WITH_THREADS="1" WITH_THREADS="1"
THREAD_CFLAGS="$THREAD_CFLAGS -DHAVE_WIN32_THREADS"
;; ;;
*) *)
dnl Use pthread by default in other cases dnl Use pthread by default in other cases

View File

@@ -74,14 +74,12 @@ XMLPUBFUN void XMLCALL
XMLPUBFUN xmlGlobalStatePtr XMLCALL XMLPUBFUN xmlGlobalStatePtr XMLCALL
xmlGetGlobalState(void); xmlGetGlobalState(void);
#ifdef HAVE_PTHREAD_H #if defined(LIBXML_THREAD_ENABLED) && defined(_WIN32) && \
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)) !defined(HAVE_COMPILER_TLS) && defined(LIBXML_STATIC_FOR_DLL)
#if defined(LIBXML_STATIC_FOR_DLL)
int XMLCALL int XMLCALL
xmlDllMain(void *hinstDLL, unsigned long fdwReason, xmlDllMain(void *hinstDLL, unsigned long fdwReason,
void *lpvReserved); void *lpvReserved);
#endif #endif
#endif
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -10,7 +10,7 @@
#include <libxml/catalog.h> #include <libxml/catalog.h>
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
#include <pthread.h> #include <pthread.h>
#elif defined HAVE_WIN32_THREADS #elif defined(_WIN32)
#include <windows.h> #include <windows.h>
#endif #endif
#include <string.h> #include <string.h>
@@ -23,7 +23,7 @@
#define TEST_REPEAT_COUNT 500 #define TEST_REPEAT_COUNT 500
#ifdef HAVE_PTHREAD_H #ifdef HAVE_PTHREAD_H
static pthread_t tid[MAX_ARGC]; static pthread_t tid[MAX_ARGC];
#elif defined HAVE_WIN32_THREADS #elif defined(_WIN32)
static HANDLE tid[MAX_ARGC]; static HANDLE tid[MAX_ARGC];
#endif #endif
@@ -141,7 +141,7 @@ main(void)
xmlMemoryDump(); xmlMemoryDump();
return (0); return (0);
} }
#elif defined HAVE_WIN32_THREADS #elif defined(_WIN32)
static DWORD WINAPI static DWORD WINAPI
win32_thread_specific_data(void *private_data) win32_thread_specific_data(void *private_data)
{ {

View File

@@ -16,14 +16,18 @@
#include <libxml/threads.h> #include <libxml/threads.h>
#include <libxml/globals.h> #include <libxml/globals.h>
#ifdef HAVE_PTHREAD_H #ifdef LIBXML_THREAD_ENABLED
#include <pthread.h> #ifdef HAVE_PTHREAD_H
#elif defined HAVE_WIN32_THREADS #include <pthread.h>
#define WIN32_LEAN_AND_MEAN #define HAVE_POSIX_THREADS
#include <windows.h> #elif defined(_WIN32)
#ifndef HAVE_COMPILER_TLS #define WIN32_LEAN_AND_MEAN
#include <process.h> #include <windows.h>
#endif #ifndef HAVE_COMPILER_TLS
#include <process.h>
#endif
#define HAVE_WIN32_THREADS
#endif
#endif #endif
#if defined(SOLARIS) #if defined(SOLARIS)
@@ -35,7 +39,7 @@
/* #define DEBUG_THREADS */ /* #define DEBUG_THREADS */
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
#if defined(__GNUC__) && defined(__linux__) #if defined(__GNUC__) && defined(__linux__)
@@ -67,7 +71,7 @@ static int libxml_is_threaded = 1;
#endif /* __GNUC__, __GLIBC__, __linux__ */ #endif /* __GNUC__, __GLIBC__, __linux__ */
#endif /* HAVE_PTHREAD_H */ #endif /* HAVE_POSIX_THREADS */
/* /*
* TODO: this module still uses malloc/free and not xmlMalloc/xmlFree * TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
@@ -79,7 +83,7 @@ static int libxml_is_threaded = 1;
* xmlMutex are a simple mutual exception locks * xmlMutex are a simple mutual exception locks
*/ */
struct _xmlMutex { struct _xmlMutex {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
pthread_mutex_t lock; pthread_mutex_t lock;
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
CRITICAL_SECTION cs; CRITICAL_SECTION cs;
@@ -92,7 +96,7 @@ struct _xmlMutex {
* xmlRMutex are reentrant mutual exception locks * xmlRMutex are reentrant mutual exception locks
*/ */
struct _xmlRMutex { struct _xmlRMutex {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
pthread_mutex_t lock; pthread_mutex_t lock;
unsigned int held; unsigned int held;
unsigned int waiters; unsigned int waiters;
@@ -111,7 +115,7 @@ struct _xmlRMutex {
* - globalkey used for per-thread data * - globalkey used for per-thread data
*/ */
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
static pthread_key_t globalkey; static pthread_key_t globalkey;
static pthread_t mainthread; static pthread_t mainthread;
static pthread_once_t once_control = PTHREAD_ONCE_INIT; static pthread_once_t once_control = PTHREAD_ONCE_INIT;
@@ -153,7 +157,7 @@ xmlNewMutex(void)
if ((tok = malloc(sizeof(xmlMutex))) == NULL) if ((tok = malloc(sizeof(xmlMutex))) == NULL)
return (NULL); return (NULL);
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) if (libxml_is_threaded != 0)
pthread_mutex_init(&tok->lock, NULL); pthread_mutex_init(&tok->lock, NULL);
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
@@ -175,7 +179,7 @@ xmlFreeMutex(xmlMutexPtr tok)
if (tok == NULL) if (tok == NULL)
return; return;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) if (libxml_is_threaded != 0)
pthread_mutex_destroy(&tok->lock); pthread_mutex_destroy(&tok->lock);
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
@@ -195,7 +199,7 @@ xmlMutexLock(xmlMutexPtr tok)
{ {
if (tok == NULL) if (tok == NULL)
return; return;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) if (libxml_is_threaded != 0)
pthread_mutex_lock(&tok->lock); pthread_mutex_lock(&tok->lock);
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
@@ -215,7 +219,7 @@ xmlMutexUnlock(xmlMutexPtr tok)
{ {
if (tok == NULL) if (tok == NULL)
return; return;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) if (libxml_is_threaded != 0)
pthread_mutex_unlock(&tok->lock); pthread_mutex_unlock(&tok->lock);
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
@@ -240,7 +244,7 @@ xmlNewRMutex(void)
if ((tok = malloc(sizeof(xmlRMutex))) == NULL) if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
return (NULL); return (NULL);
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) { if (libxml_is_threaded != 0) {
pthread_mutex_init(&tok->lock, NULL); pthread_mutex_init(&tok->lock, NULL);
tok->held = 0; tok->held = 0;
@@ -265,7 +269,7 @@ xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
{ {
if (tok == NULL) if (tok == NULL)
return; return;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) { if (libxml_is_threaded != 0) {
pthread_mutex_destroy(&tok->lock); pthread_mutex_destroy(&tok->lock);
pthread_cond_destroy(&tok->cv); pthread_cond_destroy(&tok->cv);
@@ -287,7 +291,7 @@ xmlRMutexLock(xmlRMutexPtr tok)
{ {
if (tok == NULL) if (tok == NULL)
return; return;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded == 0) if (libxml_is_threaded == 0)
return; return;
@@ -323,7 +327,7 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
{ {
if (tok == NULL) if (tok == NULL)
return; return;
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded == 0) if (libxml_is_threaded == 0)
return; return;
@@ -350,7 +354,7 @@ void
__xmlGlobalInitMutexLock(void) __xmlGlobalInitMutexLock(void)
{ {
/* Make sure the global init lock is initialized and then lock it. */ /* Make sure the global init lock is initialized and then lock it. */
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
/* The mutex is statically initialized, so we just lock it. */ /* The mutex is statically initialized, so we just lock it. */
#ifdef XML_PTHREAD_WEAK #ifdef XML_PTHREAD_WEAK
if (pthread_mutex_lock == NULL) if (pthread_mutex_lock == NULL)
@@ -396,7 +400,7 @@ __xmlGlobalInitMutexLock(void)
void void
__xmlGlobalInitMutexUnlock(void) __xmlGlobalInitMutexUnlock(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
#ifdef XML_PTHREAD_WEAK #ifdef XML_PTHREAD_WEAK
if (pthread_mutex_unlock == NULL) if (pthread_mutex_unlock == NULL)
return; return;
@@ -418,7 +422,7 @@ __xmlGlobalInitMutexUnlock(void)
void void
__xmlGlobalInitMutexDestroy(void) __xmlGlobalInitMutexDestroy(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
if (global_init_lock != NULL) { if (global_init_lock != NULL) {
DeleteCriticalSection(global_init_lock); DeleteCriticalSection(global_init_lock);
@@ -483,7 +487,7 @@ xmlNewGlobalState(void)
} }
#endif /* LIBXML_THREAD_ENABLED */ #endif /* LIBXML_THREAD_ENABLED */
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
#if !defined(HAVE_COMPILER_TLS) #if !defined(HAVE_COMPILER_TLS)
#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL) #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
@@ -528,7 +532,7 @@ static CRITICAL_SECTION cleanup_helpers_cs;
xmlGlobalStatePtr xmlGlobalStatePtr
xmlGetGlobalState(void) xmlGetGlobalState(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
xmlGlobalState *globalval; xmlGlobalState *globalval;
if (libxml_is_threaded == 0) if (libxml_is_threaded == 0)
@@ -623,7 +627,7 @@ xmlGetGlobalState(void)
int int
xmlGetThreadId(void) xmlGetThreadId(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
pthread_t id; pthread_t id;
int ret; int ret;
@@ -650,7 +654,7 @@ xmlGetThreadId(void)
int int
xmlIsMainThread(void) xmlIsMainThread(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded == -1) if (libxml_is_threaded == -1)
xmlInitThreads(); xmlInitThreads();
if (libxml_is_threaded == 0) if (libxml_is_threaded == 0)
@@ -663,7 +667,7 @@ xmlIsMainThread(void)
#ifdef DEBUG_THREADS #ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n"); xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
#endif #endif
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
return (pthread_equal(mainthread,pthread_self())); return (pthread_equal(mainthread,pthread_self()));
#elif defined HAVE_WIN32_THREADS #elif defined HAVE_WIN32_THREADS
return (mainthread == GetCurrentThreadId()); return (mainthread == GetCurrentThreadId());
@@ -714,7 +718,7 @@ xmlUnlockLibrary(void)
void void
xmlInitThreads(void) xmlInitThreads(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
#ifdef XML_PTHREAD_WEAK #ifdef XML_PTHREAD_WEAK
if (libxml_is_threaded == -1) { if (libxml_is_threaded == -1) {
if ((pthread_once != NULL) && if ((pthread_once != NULL) &&
@@ -770,7 +774,7 @@ xmlCleanupThreads(void)
#ifdef DEBUG_THREADS #ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n"); xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
#endif #endif
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
if (libxml_is_threaded != 0) if (libxml_is_threaded != 0)
pthread_key_delete(globalkey); pthread_key_delete(globalkey);
once_control = once_control_init; once_control = once_control_init;
@@ -818,7 +822,7 @@ xmlCleanupThreads(void)
static void static void
xmlOnceInit(void) xmlOnceInit(void)
{ {
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
(void) pthread_key_create(&globalkey, xmlFreeGlobalState); (void) pthread_key_create(&globalkey, xmlFreeGlobalState);
mainthread = pthread_self(); mainthread = pthread_self();
__xmlInitializeDict(); __xmlInitializeDict();
@@ -856,7 +860,7 @@ xmlOnceInit(void)
* *
* Returns TRUE always * Returns TRUE always
*/ */
#ifdef HAVE_PTHREAD_H #ifdef HAVE_POSIX_THREADS
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)) #elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
#if defined(LIBXML_STATIC_FOR_DLL) #if defined(LIBXML_STATIC_FOR_DLL)
int XMLCALL int XMLCALL

View File

@@ -59,9 +59,7 @@ CFLAGS = $(CFLAGS) -D_REENTRANT -tWM
CFLAGS = $(CFLAGS) -tWR CFLAGS = $(CFLAGS) -tWR
!endif !endif
!if "$(WITH_THREADS)" == "yes" || "$(WITH_THREADS)" == "ctls" !if "$(WITH_THREADS)" == "yes" || "$(WITH_THREADS)" == "ctls"
CFLAGS = $(CFLAGS) -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS CFLAGS = $(CFLAGS) -DHAVE_COMPILER_TLS
!else if "$(WITH_THREADS)" == "native"
CFLAGS = $(CFLAGS) -DHAVE_WIN32_THREADS
!else if "$(WITH_THREADS)" == "posix" !else if "$(WITH_THREADS)" == "posix"
CFLAGS = $(CFLAGS) -DHAVE_PTHREAD_H CFLAGS = $(CFLAGS) -DHAVE_PTHREAD_H
!endif !endif

View File

@@ -46,13 +46,10 @@ ifneq ($(WITH_THREADS),no)
CFLAGS += -D_REENTRANT CFLAGS += -D_REENTRANT
endif endif
ifeq ($(WITH_THREADS),yes) ifeq ($(WITH_THREADS),yes)
CFLAGS += -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS CFLAGS += -DHAVE_COMPILER_TLS
endif endif
ifeq ($(WITH_THREADS),ctls) ifeq ($(WITH_THREADS),ctls)
CFLAGS += -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS CFLAGS += -DHAVE_COMPILER_TLS
endif
ifeq ($(WITH_THREADS),native)
CFLAGS += -DHAVE_WIN32_THREADS
endif endif
ifeq ($(WITH_THREADS),posix) ifeq ($(WITH_THREADS),posix)
CFLAGS += -DHAVE_PTHREAD_H CFLAGS += -DHAVE_PTHREAD_H

View File

@@ -50,9 +50,7 @@ CFLAGS = $(CFLAGS) /I$(XML_SRCDIR) /I$(XML_SRCDIR)\include /I$(INCPREFIX)
CFLAGS = $(CFLAGS) /D "_REENTRANT" CFLAGS = $(CFLAGS) /D "_REENTRANT"
!endif !endif
!if "$(WITH_THREADS)" == "yes" || "$(WITH_THREADS)" == "ctls" !if "$(WITH_THREADS)" == "yes" || "$(WITH_THREADS)" == "ctls"
CFLAGS = $(CFLAGS) /D "HAVE_WIN32_THREADS" /D "HAVE_COMPILER_TLS" CFLAGS = $(CFLAGS) /D "HAVE_COMPILER_TLS"
!else if "$(WITH_THREADS)" == "native"
CFLAGS = $(CFLAGS) /D "HAVE_WIN32_THREADS"
!else if "$(WITH_THREADS)" == "posix" !else if "$(WITH_THREADS)" == "posix"
CFLAGS = $(CFLAGS) /D "HAVE_PTHREAD_H" CFLAGS = $(CFLAGS) /D "HAVE_PTHREAD_H"
!endif !endif