[libxml2] Remove HAVE_WIN32_THREADS configuration flag



commit 1e60c768210d16c0f4b47cf6298dab2073df3515
Author: Nick Wellnhofer <wellnhofer aevum de>
Date:   Sun Sep 4 01:49:41 2022 +0200

    Remove HAVE_WIN32_THREADS configuration flag
    
    Check for LIBXML_THREAD_ENABLED and _WIN32 instead.

 CMakeLists.txt           |  7 +----
 configure.ac             |  1 -
 include/libxml/threads.h |  6 ++---
 testThreads.c            |  6 ++---
 threads.c                | 70 +++++++++++++++++++++++++-----------------------
 win32/Makefile.bcb       |  4 +--
 win32/Makefile.mingw     |  7 ++---
 win32/Makefile.msvc      |  4 +--
 8 files changed, 47 insertions(+), 58 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 861234da..07457bd3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -372,9 +372,7 @@ endif()
 
 if(LIBXML2_WITH_THREADS)
        target_compile_definitions(LibXml2 PRIVATE _REENTRANT)
-       if(WIN32)
-               target_compile_definitions(LibXml2 PRIVATE HAVE_WIN32_THREADS)
-       else()
+        if(NOT WIN32)
                check_include_files(pthread.h HAVE_PTHREAD_H)
        endif()
 endif()
@@ -524,9 +522,6 @@ if(LIBXML2_WITH_TESTS)
        endforeach()
        if(Threads_FOUND)
                foreach(TEST runtest testThreads)
-                       if(WIN32)
-                               target_compile_definitions(${TEST} PRIVATE HAVE_WIN32_THREADS)
-                       endif()
                        target_link_libraries(${TEST} Threads::Threads)
                endforeach()
        endif()
diff --git a/configure.ac b/configure.ac
index b0b13b4b..1e9ff166 100644
--- a/configure.ac
+++ b/configure.ac
@@ -919,7 +919,6 @@ else
         *mingw*)
             dnl Default to native threads on Windows
             WITH_THREADS="1"
-            THREAD_CFLAGS="$THREAD_CFLAGS -DHAVE_WIN32_THREADS"
             ;;
         *)
             dnl Use pthread by default in other cases
diff --git a/include/libxml/threads.h b/include/libxml/threads.h
index 6eedac1f..5c9d0bd2 100644
--- a/include/libxml/threads.h
+++ b/include/libxml/threads.h
@@ -74,14 +74,12 @@ XMLPUBFUN void XMLCALL
 XMLPUBFUN xmlGlobalStatePtr XMLCALL
                        xmlGetGlobalState(void);
 
-#ifdef HAVE_PTHREAD_H
-#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_THREAD_ENABLED) && defined(_WIN32) && \
+    !defined(HAVE_COMPILER_TLS) && defined(LIBXML_STATIC_FOR_DLL)
 int XMLCALL
 xmlDllMain(void *hinstDLL, unsigned long fdwReason,
            void *lpvReserved);
 #endif
-#endif
 
 #ifdef __cplusplus
 }
diff --git a/testThreads.c b/testThreads.c
index 01dc5883..0714deba 100644
--- a/testThreads.c
+++ b/testThreads.c
@@ -10,7 +10,7 @@
 #include <libxml/catalog.h>
 #ifdef HAVE_PTHREAD_H
 #include <pthread.h>
-#elif defined HAVE_WIN32_THREADS
+#elif defined(_WIN32)
 #include <windows.h>
 #endif
 #include <string.h>
@@ -23,7 +23,7 @@
 #define TEST_REPEAT_COUNT 500
 #ifdef HAVE_PTHREAD_H
 static pthread_t tid[MAX_ARGC];
-#elif defined HAVE_WIN32_THREADS
+#elif defined(_WIN32)
 static HANDLE tid[MAX_ARGC];
 #endif
 
@@ -141,7 +141,7 @@ main(void)
     xmlMemoryDump();
     return (0);
 }
-#elif defined HAVE_WIN32_THREADS
+#elif defined(_WIN32)
 static DWORD WINAPI
 win32_thread_specific_data(void *private_data)
 {
diff --git a/threads.c b/threads.c
index ab91f5f3..9fa477e5 100644
--- a/threads.c
+++ b/threads.c
@@ -16,14 +16,18 @@
 #include <libxml/threads.h>
 #include <libxml/globals.h>
 
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#elif defined HAVE_WIN32_THREADS
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#ifndef HAVE_COMPILER_TLS
-#include <process.h>
-#endif
+#ifdef LIBXML_THREAD_ENABLED
+  #ifdef HAVE_PTHREAD_H
+    #include <pthread.h>
+    #define HAVE_POSIX_THREADS
+  #elif defined(_WIN32)
+    #define WIN32_LEAN_AND_MEAN
+    #include <windows.h>
+    #ifndef HAVE_COMPILER_TLS
+      #include <process.h>
+    #endif
+    #define HAVE_WIN32_THREADS
+  #endif
 #endif
 
 #if defined(SOLARIS)
@@ -35,7 +39,7 @@
 
 /* #define DEBUG_THREADS */
 
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
 
 #if defined(__GNUC__) && defined(__linux__)
 
@@ -67,7 +71,7 @@ static int libxml_is_threaded = 1;
 
 #endif /* __GNUC__, __GLIBC__, __linux__ */
 
-#endif /* HAVE_PTHREAD_H */
+#endif /* HAVE_POSIX_THREADS */
 
 /*
  * 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
  */
 struct _xmlMutex {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     pthread_mutex_t lock;
 #elif defined HAVE_WIN32_THREADS
     CRITICAL_SECTION cs;
@@ -92,7 +96,7 @@ struct _xmlMutex {
  * xmlRMutex are reentrant mutual exception locks
  */
 struct _xmlRMutex {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     pthread_mutex_t lock;
     unsigned int held;
     unsigned int waiters;
@@ -111,7 +115,7 @@ struct _xmlRMutex {
  *   - globalkey used for per-thread data
  */
 
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
 static pthread_key_t globalkey;
 static pthread_t mainthread;
 static pthread_once_t once_control = PTHREAD_ONCE_INIT;
@@ -153,7 +157,7 @@ xmlNewMutex(void)
 
     if ((tok = malloc(sizeof(xmlMutex))) == NULL)
         return (NULL);
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0)
         pthread_mutex_init(&tok->lock, NULL);
 #elif defined HAVE_WIN32_THREADS
@@ -175,7 +179,7 @@ xmlFreeMutex(xmlMutexPtr tok)
     if (tok == NULL)
         return;
 
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0)
         pthread_mutex_destroy(&tok->lock);
 #elif defined HAVE_WIN32_THREADS
@@ -195,7 +199,7 @@ xmlMutexLock(xmlMutexPtr tok)
 {
     if (tok == NULL)
         return;
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0)
         pthread_mutex_lock(&tok->lock);
 #elif defined HAVE_WIN32_THREADS
@@ -215,7 +219,7 @@ xmlMutexUnlock(xmlMutexPtr tok)
 {
     if (tok == NULL)
         return;
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0)
         pthread_mutex_unlock(&tok->lock);
 #elif defined HAVE_WIN32_THREADS
@@ -240,7 +244,7 @@ xmlNewRMutex(void)
 
     if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
         return (NULL);
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0) {
         pthread_mutex_init(&tok->lock, NULL);
         tok->held = 0;
@@ -265,7 +269,7 @@ xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
 {
     if (tok == NULL)
         return;
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0) {
         pthread_mutex_destroy(&tok->lock);
         pthread_cond_destroy(&tok->cv);
@@ -287,7 +291,7 @@ xmlRMutexLock(xmlRMutexPtr tok)
 {
     if (tok == NULL)
         return;
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded == 0)
         return;
 
@@ -323,7 +327,7 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
 {
     if (tok == NULL)
         return;
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded == 0)
         return;
 
@@ -350,7 +354,7 @@ void
 __xmlGlobalInitMutexLock(void)
 {
     /* 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. */
 #ifdef XML_PTHREAD_WEAK
     if (pthread_mutex_lock == NULL)
@@ -396,7 +400,7 @@ __xmlGlobalInitMutexLock(void)
 void
 __xmlGlobalInitMutexUnlock(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
 #ifdef XML_PTHREAD_WEAK
     if (pthread_mutex_unlock == NULL)
         return;
@@ -418,7 +422,7 @@ __xmlGlobalInitMutexUnlock(void)
 void
 __xmlGlobalInitMutexDestroy(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
 #elif defined HAVE_WIN32_THREADS
     if (global_init_lock != NULL) {
         DeleteCriticalSection(global_init_lock);
@@ -483,7 +487,7 @@ xmlNewGlobalState(void)
 }
 #endif /* LIBXML_THREAD_ENABLED */
 
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
 #elif defined HAVE_WIN32_THREADS
 #if !defined(HAVE_COMPILER_TLS)
 #if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
@@ -528,7 +532,7 @@ static CRITICAL_SECTION cleanup_helpers_cs;
 xmlGlobalStatePtr
 xmlGetGlobalState(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     xmlGlobalState *globalval;
 
     if (libxml_is_threaded == 0)
@@ -623,7 +627,7 @@ xmlGetGlobalState(void)
 int
 xmlGetThreadId(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     pthread_t id;
     int ret;
 
@@ -650,7 +654,7 @@ xmlGetThreadId(void)
 int
 xmlIsMainThread(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded == -1)
         xmlInitThreads();
     if (libxml_is_threaded == 0)
@@ -663,7 +667,7 @@ xmlIsMainThread(void)
 #ifdef DEBUG_THREADS
     xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
 #endif
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     return (pthread_equal(mainthread,pthread_self()));
 #elif defined HAVE_WIN32_THREADS
     return (mainthread == GetCurrentThreadId());
@@ -714,7 +718,7 @@ xmlUnlockLibrary(void)
 void
 xmlInitThreads(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
 #ifdef XML_PTHREAD_WEAK
     if (libxml_is_threaded == -1) {
         if ((pthread_once != NULL) &&
@@ -770,7 +774,7 @@ xmlCleanupThreads(void)
 #ifdef DEBUG_THREADS
     xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
 #endif
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     if (libxml_is_threaded != 0)
         pthread_key_delete(globalkey);
     once_control = once_control_init;
@@ -818,7 +822,7 @@ xmlCleanupThreads(void)
 static void
 xmlOnceInit(void)
 {
-#ifdef HAVE_PTHREAD_H
+#ifdef HAVE_POSIX_THREADS
     (void) pthread_key_create(&globalkey, xmlFreeGlobalState);
     mainthread = pthread_self();
     __xmlInitializeDict();
@@ -856,7 +860,7 @@ xmlOnceInit(void)
  *
  * 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))
 #if defined(LIBXML_STATIC_FOR_DLL)
 int XMLCALL
diff --git a/win32/Makefile.bcb b/win32/Makefile.bcb
index 43b5ab95..4b0a2ef5 100644
--- a/win32/Makefile.bcb
+++ b/win32/Makefile.bcb
@@ -59,9 +59,7 @@ CFLAGS = $(CFLAGS) -D_REENTRANT -tWM
 CFLAGS = $(CFLAGS) -tWR
 !endif
 !if "$(WITH_THREADS)" == "yes" || "$(WITH_THREADS)" == "ctls"
-CFLAGS = $(CFLAGS) -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS
-!else if "$(WITH_THREADS)" == "native"
-CFLAGS = $(CFLAGS) -DHAVE_WIN32_THREADS
+CFLAGS = $(CFLAGS) -DHAVE_COMPILER_TLS
 !else if "$(WITH_THREADS)" == "posix"
 CFLAGS = $(CFLAGS) -DHAVE_PTHREAD_H
 !endif
diff --git a/win32/Makefile.mingw b/win32/Makefile.mingw
index b10738d2..bd0c4297 100644
--- a/win32/Makefile.mingw
+++ b/win32/Makefile.mingw
@@ -46,13 +46,10 @@ ifneq ($(WITH_THREADS),no)
 CFLAGS += -D_REENTRANT
 endif
 ifeq ($(WITH_THREADS),yes) 
-CFLAGS += -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS
+CFLAGS += -DHAVE_COMPILER_TLS
 endif
 ifeq ($(WITH_THREADS),ctls)
-CFLAGS += -DHAVE_WIN32_THREADS -DHAVE_COMPILER_TLS
-endif
-ifeq ($(WITH_THREADS),native)
-CFLAGS += -DHAVE_WIN32_THREADS
+CFLAGS += -DHAVE_COMPILER_TLS
 endif
 ifeq ($(WITH_THREADS),posix)
 CFLAGS += -DHAVE_PTHREAD_H
diff --git a/win32/Makefile.msvc b/win32/Makefile.msvc
index bd3e2ec1..7cc25b84 100644
--- a/win32/Makefile.msvc
+++ b/win32/Makefile.msvc
@@ -50,9 +50,7 @@ CFLAGS = $(CFLAGS) /I$(XML_SRCDIR) /I$(XML_SRCDIR)\include /I$(INCPREFIX)
 CFLAGS = $(CFLAGS) /D "_REENTRANT"
 !endif
 !if "$(WITH_THREADS)" == "yes" || "$(WITH_THREADS)" == "ctls"
-CFLAGS = $(CFLAGS) /D "HAVE_WIN32_THREADS" /D "HAVE_COMPILER_TLS"
-!else if "$(WITH_THREADS)" == "native"
-CFLAGS = $(CFLAGS) /D "HAVE_WIN32_THREADS"
+CFLAGS = $(CFLAGS) /D "HAVE_COMPILER_TLS"
 !else if "$(WITH_THREADS)" == "posix"
 CFLAGS = $(CFLAGS) /D "HAVE_PTHREAD_H"
 !endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]