Commit 6f350291 authored by Daniel Veillard's avatar Daniel Veillard

debugged and fixed initialization problems which were giving troubles on

* parser.c parserInternals.c threads.c: debugged and fixed
  initialization problems which were giving troubles on SMP
  boxes.
Daniel
parent 6661ffa5
Sun Oct 14 05:55:01 EDT 2001 Daniel Veillard <daniel@veillard.com>
* parser.c parserInternals.c threads.c: debugged and fixed
initialization problems which were giving troubles on SMP
boxes.
Sat Oct 13 16:17:13 CEST 2001 Daniel Veillard <daniel@veillard.com>
* include/libxml/Makefile.am: missing globals.h
......
......@@ -10188,7 +10188,9 @@ void
xmlInitParser(void) {
if (xmlParserInitialized) return;
initGenericErrorDefaultFunc(NULL);
xmlInitThreads();
xmlInitMemory();
initGenericErrorDefaultFunc(NULL);
xmlInitCharEncodingHandlers();
xmlInitializePredefinedEntities();
......
......@@ -74,7 +74,7 @@ void
xmlCheckVersion(int version) {
int myversion = (int) LIBXML_VERSION;
xmlInitMemory();
xmlInitParser();
if ((myversion / 10000) != (version / 10000)) {
xmlGenericError(xmlGenericErrorContext,
......
......@@ -31,6 +31,7 @@
#include <note.h>
#endif
/* #define DEBUG_THREADS */
/*
* TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
......@@ -70,10 +71,13 @@ struct _xmlRMutex {
* - keylock protecting globalkey
* - keyonce to mark initialization of globalkey
*/
static int initialized = 0;
#ifdef HAVE_PTHREAD_H
static pthread_mutex_t keylock;
static pthread_mutex_t keylock = PTHREAD_MUTEX_INITIALIZER;
static pthread_key_t globalkey;
static int keyonce = 0;
static pthread_t mainthread;
#endif
static xmlRMutexPtr xmlLibraryLock = NULL;
......@@ -313,8 +317,10 @@ xmlGetGlobalState(void)
pthread_setspecific(globalkey, tsd);
return (tsd);
} else
return (globalval);
}
return (globalval);
#else
return(NULL);
#endif
}
......@@ -325,6 +331,29 @@ xmlGetGlobalState(void)
* *
************************************************************************/
/**
* xmlIsMainThread:
*
* xmlIsMainThread() check wether the current thread is the main thread.
*
* Returns 1 if the current thread is the main thread, 0 otherwise
*/
int
xmlIsMainThread(void)
{
if (!initialized)
xmlInitThreads();
#ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
#endif
#ifdef HAVE_PTHREAD_H
return(mainthread == pthread_self());
#else
return(1);
#endif
}
/**
* xmlLockLibrary:
*
......@@ -334,6 +363,9 @@ xmlGetGlobalState(void)
void
xmlLockLibrary(void)
{
#ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
#endif
xmlRMutexLock(xmlLibraryLock);
}
......@@ -346,6 +378,9 @@ xmlLockLibrary(void)
void
xmlUnlockLibrary(void)
{
#ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
#endif
xmlRMutexUnlock(xmlLibraryLock);
}
......@@ -358,6 +393,18 @@ xmlUnlockLibrary(void)
void
xmlInitThreads(void)
{
if (initialized != 0)
return;
#ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlInitThreads()\n");
#endif
#ifdef HAVE_PTHREAD_H
mainthread = pthread_self();
#endif
initialized = 1;
}
/**
......@@ -369,4 +416,12 @@ xmlInitThreads(void)
void
xmlCleanupThreads(void)
{
if (initialized == 0)
return;
#ifdef DEBUG_THREADS
xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
#endif
initialized = 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment