Index: third_party/libxml/src/threads.c |
diff --git a/third_party/libxml/src/threads.c b/third_party/libxml/src/threads.c |
index 98fd2c23f2e8b676030ff5f1a28e585e55f31e00..8921204b3c2eef6ac917297c564664dfe13731ad 100644 |
--- a/third_party/libxml/src/threads.c |
+++ b/third_party/libxml/src/threads.c |
@@ -146,6 +146,7 @@ struct _xmlRMutex { |
static pthread_key_t globalkey; |
static pthread_t mainthread; |
static pthread_once_t once_control = PTHREAD_ONCE_INIT; |
+static pthread_once_t once_control_init = PTHREAD_ONCE_INIT; |
static pthread_mutex_t global_init_lock = PTHREAD_MUTEX_INITIALIZER; |
#elif defined HAVE_WIN32_THREADS |
#if defined(HAVE_COMPILER_TLS) |
@@ -251,7 +252,6 @@ xmlMutexLock(xmlMutexPtr tok) |
#ifdef DEBUG_THREADS |
xmlGenericError(xmlGenericErrorContext, |
"xmlMutexLock():BeOS:Couldn't aquire semaphore\n"); |
- exit(); |
#endif |
} |
tok->tid = find_thread(NULL); |
@@ -378,7 +378,7 @@ xmlRMutexLock(xmlRMutexPtr tok) |
pthread_mutex_unlock(&tok->lock); |
#elif defined HAVE_WIN32_THREADS |
EnterCriticalSection(&tok->cs); |
- ++tok->count; |
+ tok->count++; |
#elif defined HAVE_BEOS_THREADS |
if (tok->lock->tid == find_thread(NULL)) { |
tok->count++; |
@@ -414,8 +414,10 @@ xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED) |
} |
pthread_mutex_unlock(&tok->lock); |
#elif defined HAVE_WIN32_THREADS |
- if (!--tok->count) |
+ if (tok->count > 0) { |
LeaveCriticalSection(&tok->cs); |
+ tok->count--; |
+ } |
#elif defined HAVE_BEOS_THREADS |
if (tok->lock->tid == find_thread(NULL)) { |
tok->count--; |
@@ -439,7 +441,8 @@ __xmlGlobalInitMutexLock(void) |
/* Make sure the global init lock is initialized and then lock it. */ |
#ifdef HAVE_PTHREAD_H |
/* The mutex is statically initialized, so we just lock it. */ |
- pthread_mutex_lock(&global_init_lock); |
+ if (pthread_mutex_lock != NULL) |
+ pthread_mutex_lock(&global_init_lock); |
#elif defined HAVE_WIN32_THREADS |
LPCRITICAL_SECTION cs; |
@@ -498,7 +501,6 @@ __xmlGlobalInitMutexLock(void) |
#ifdef DEBUG_THREADS |
xmlGenericError(xmlGenericErrorContext, |
"xmlGlobalInitMutexLock():BeOS:Couldn't acquire semaphore\n"); |
- exit(); |
#endif |
} |
#endif |
@@ -508,7 +510,8 @@ void |
__xmlGlobalInitMutexUnlock(void) |
{ |
#ifdef HAVE_PTHREAD_H |
- pthread_mutex_unlock(&global_init_lock); |
+ if (pthread_mutex_unlock != NULL) |
+ pthread_mutex_unlock(&global_init_lock); |
#elif defined HAVE_WIN32_THREADS |
if (global_init_lock != NULL) { |
LeaveCriticalSection(global_init_lock); |
@@ -913,6 +916,7 @@ xmlCleanupThreads(void) |
#ifdef HAVE_PTHREAD_H |
if ((libxml_is_threaded) && (pthread_key_delete != NULL)) |
pthread_key_delete(globalkey); |
+ once_control = once_control_init; |
#elif defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || defined(LIBXML_STATIC_FOR_DLL)) |
if (globalkey != TLS_OUT_OF_INDEXES) { |
xmlGlobalStateCleanupHelperParams *p; |
@@ -952,6 +956,7 @@ xmlOnceInit(void) |
#ifdef HAVE_PTHREAD_H |
(void) pthread_key_create(&globalkey, xmlFreeGlobalState); |
mainthread = pthread_self(); |
+ __xmlInitializeDict(); |
#elif defined(HAVE_WIN32_THREADS) |
if (!run_once.done) { |
if (InterlockedIncrement(&run_once.control) == 1) { |
@@ -959,6 +964,7 @@ xmlOnceInit(void) |
globalkey = TlsAlloc(); |
#endif |
mainthread = GetCurrentThreadId(); |
+ __xmlInitializeDict(); |
run_once.done = 1; |
} else { |
/* Another thread is working; give up our slice and |
@@ -972,6 +978,7 @@ xmlOnceInit(void) |
globalkey = tls_allocate(); |
tls_set(globalkey, NULL); |
mainthread = find_thread(NULL); |
+ __xmlInitializeDict(); |
} else |
atomic_add(&run_once_init, -1); |
#endif |