mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-26 00:37:43 +03:00
593857 try to work around thread pbm MinGW 4.4
* threads.c: try to cope with HAVE_PTHREAD_H and HAVE_WIN32_THREADS being both defined and pthread_t being a non integer
This commit is contained in:
49
threads.c
49
threads.c
@@ -26,9 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#elif HAVE_WIN32_THREADS
|
||||||
|
|
||||||
#ifdef HAVE_WIN32_THREADS
|
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#ifndef HAVE_COMPILER_TLS
|
#ifndef HAVE_COMPILER_TLS
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
@@ -412,7 +410,7 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
|
|||||||
if (tok->held == 0) {
|
if (tok->held == 0) {
|
||||||
if (tok->waiters)
|
if (tok->waiters)
|
||||||
pthread_cond_signal(&tok->cv);
|
pthread_cond_signal(&tok->cv);
|
||||||
tok->tid = 0;
|
memset(&tok->tid, 0, sizeof(tok->tid));
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&tok->lock);
|
pthread_mutex_unlock(&tok->lock);
|
||||||
#elif defined HAVE_WIN32_THREADS
|
#elif defined HAVE_WIN32_THREADS
|
||||||
@@ -529,7 +527,8 @@ __xmlGlobalInitMutexUnlock(void)
|
|||||||
void
|
void
|
||||||
__xmlGlobalInitMutexDestroy(void)
|
__xmlGlobalInitMutexDestroy(void)
|
||||||
{
|
{
|
||||||
#if defined HAVE_WIN32_THREADS
|
#ifdef HAVE_PTHREAD_H
|
||||||
|
#elif defined HAVE_WIN32_THREADS
|
||||||
if (global_init_lock != NULL) {
|
if (global_init_lock != NULL) {
|
||||||
DeleteCriticalSection(global_init_lock);
|
DeleteCriticalSection(global_init_lock);
|
||||||
free(global_init_lock);
|
free(global_init_lock);
|
||||||
@@ -593,8 +592,8 @@ xmlNewGlobalState(void)
|
|||||||
}
|
}
|
||||||
#endif /* LIBXML_THREAD_ENABLED */
|
#endif /* LIBXML_THREAD_ENABLED */
|
||||||
|
|
||||||
|
#ifdef HAVE_PTHREAD_H
|
||||||
#ifdef HAVE_WIN32_THREADS
|
#elif 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)
|
||||||
typedef struct _xmlGlobalStateCleanupHelperParams {
|
typedef struct _xmlGlobalStateCleanupHelperParams {
|
||||||
@@ -758,6 +757,8 @@ xmlGetGlobalState(void)
|
|||||||
* xmlGetThreadId:
|
* xmlGetThreadId:
|
||||||
*
|
*
|
||||||
* xmlGetThreadId() find the current thread ID number
|
* xmlGetThreadId() find the current thread ID number
|
||||||
|
* Note that this is likely to be broken on some platforms using pthreads
|
||||||
|
* as the specification doesn't mandate pthread_t to be an integer type
|
||||||
*
|
*
|
||||||
* Returns the current thread ID number
|
* Returns the current thread ID number
|
||||||
*/
|
*/
|
||||||
@@ -765,9 +766,15 @@ int
|
|||||||
xmlGetThreadId(void)
|
xmlGetThreadId(void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
|
pthread_t id;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (libxml_is_threaded == 0)
|
if (libxml_is_threaded == 0)
|
||||||
return (0);
|
return (0);
|
||||||
return ((int) pthread_self());
|
id = pthread_self();
|
||||||
|
/* horrible but preserves compat, see warning above */
|
||||||
|
memcpy(&ret, &id, sizeof(ret));
|
||||||
|
return (ret);
|
||||||
#elif defined HAVE_WIN32_THREADS
|
#elif defined HAVE_WIN32_THREADS
|
||||||
return GetCurrentThreadId();
|
return GetCurrentThreadId();
|
||||||
#elif defined HAVE_BEOS_THREADS
|
#elif defined HAVE_BEOS_THREADS
|
||||||
@@ -803,7 +810,7 @@ xmlIsMainThread(void)
|
|||||||
xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
return (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());
|
||||||
#elif defined HAVE_BEOS_THREADS
|
#elif defined HAVE_BEOS_THREADS
|
||||||
@@ -852,9 +859,6 @@ xmlUnlockLibrary(void)
|
|||||||
void
|
void
|
||||||
xmlInitThreads(void)
|
xmlInitThreads(void)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
|
|
||||||
InitializeCriticalSection(&cleanup_helpers_cs);
|
|
||||||
#endif
|
|
||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
if (libxml_is_threaded == -1) {
|
if (libxml_is_threaded == -1) {
|
||||||
if ((pthread_once != NULL) &&
|
if ((pthread_once != NULL) &&
|
||||||
@@ -881,6 +885,8 @@ xmlInitThreads(void)
|
|||||||
libxml_is_threaded = 0;
|
libxml_is_threaded = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
|
||||||
|
InitializeCriticalSection(&cleanup_helpers_cs);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -904,7 +910,10 @@ xmlCleanupThreads(void)
|
|||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
|
xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
|
#ifdef HAVE_PTHREAD_H
|
||||||
|
if ((libxml_is_threaded) && (pthread_key_delete != NULL))
|
||||||
|
pthread_key_delete(globalkey);
|
||||||
|
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
|
||||||
if (globalkey != TLS_OUT_OF_INDEXES) {
|
if (globalkey != TLS_OUT_OF_INDEXES) {
|
||||||
xmlGlobalStateCleanupHelperParams *p;
|
xmlGlobalStateCleanupHelperParams *p;
|
||||||
|
|
||||||
@@ -923,9 +932,6 @@ xmlCleanupThreads(void)
|
|||||||
globalkey = TLS_OUT_OF_INDEXES;
|
globalkey = TLS_OUT_OF_INDEXES;
|
||||||
}
|
}
|
||||||
DeleteCriticalSection(&cleanup_helpers_cs);
|
DeleteCriticalSection(&cleanup_helpers_cs);
|
||||||
#elif defined HAVE_PTHREAD_H
|
|
||||||
if ((libxml_is_threaded) && (pthread_key_delete != NULL))
|
|
||||||
pthread_key_delete(globalkey);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -946,9 +952,7 @@ xmlOnceInit(void)
|
|||||||
#ifdef HAVE_PTHREAD_H
|
#ifdef HAVE_PTHREAD_H
|
||||||
(void) pthread_key_create(&globalkey, xmlFreeGlobalState);
|
(void) pthread_key_create(&globalkey, xmlFreeGlobalState);
|
||||||
mainthread = pthread_self();
|
mainthread = pthread_self();
|
||||||
#endif
|
#elif defined(HAVE_WIN32_THREADS)
|
||||||
|
|
||||||
#if defined(HAVE_WIN32_THREADS)
|
|
||||||
if (!run_once.done) {
|
if (!run_once.done) {
|
||||||
if (InterlockedIncrement(&run_once.control) == 1) {
|
if (InterlockedIncrement(&run_once.control) == 1) {
|
||||||
#if !defined(HAVE_COMPILER_TLS)
|
#if !defined(HAVE_COMPILER_TLS)
|
||||||
@@ -963,9 +967,7 @@ xmlOnceInit(void)
|
|||||||
Sleep(0);
|
Sleep(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#elif HAVE_BEOS_THREADS
|
||||||
|
|
||||||
#ifdef HAVE_BEOS_THREADS
|
|
||||||
if (atomic_add(&run_once_init, 1) == 0) {
|
if (atomic_add(&run_once_init, 1) == 0) {
|
||||||
globalkey = tls_allocate();
|
globalkey = tls_allocate();
|
||||||
tls_set(globalkey, NULL);
|
tls_set(globalkey, NULL);
|
||||||
@@ -987,7 +989,8 @@ xmlOnceInit(void)
|
|||||||
*
|
*
|
||||||
* Returns TRUE always
|
* Returns TRUE always
|
||||||
*/
|
*/
|
||||||
#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL))
|
#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_STATIC_FOR_DLL)
|
||||||
BOOL XMLCALL
|
BOOL XMLCALL
|
||||||
xmlDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
xmlDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||||
|
|||||||
Reference in New Issue
Block a user