diff --git a/ChangeLog b/ChangeLog index b710995e..65cd848b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Sun Oct 14 05:55:01 EDT 2001 Daniel Veillard + + * 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 * include/libxml/Makefile.am: missing globals.h diff --git a/parser.c b/parser.c index 1d644527..15a0f691 100644 --- a/parser.c +++ b/parser.c @@ -10188,7 +10188,9 @@ void xmlInitParser(void) { if (xmlParserInitialized) return; + initGenericErrorDefaultFunc(NULL); xmlInitThreads(); + xmlInitMemory(); initGenericErrorDefaultFunc(NULL); xmlInitCharEncodingHandlers(); xmlInitializePredefinedEntities(); diff --git a/parserInternals.c b/parserInternals.c index 4edb1118..68553c25 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -74,7 +74,7 @@ void xmlCheckVersion(int version) { int myversion = (int) LIBXML_VERSION; - xmlInitMemory(); + xmlInitParser(); if ((myversion / 10000) != (version / 10000)) { xmlGenericError(xmlGenericErrorContext, diff --git a/threads.c b/threads.c index 9b0a3464..49ada346 100644 --- a/threads.c +++ b/threads.c @@ -31,6 +31,7 @@ #include #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; }