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
diff --git a/ChangeLog b/ChangeLog
index b710995..65cd848 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+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
diff --git a/parser.c b/parser.c
index 1d64452..15a0f69 100644
--- a/parser.c
+++ b/parser.c
@@ -10188,7 +10188,9 @@
xmlInitParser(void) {
if (xmlParserInitialized) return;
+ initGenericErrorDefaultFunc(NULL);
xmlInitThreads();
+ xmlInitMemory();
initGenericErrorDefaultFunc(NULL);
xmlInitCharEncodingHandlers();
xmlInitializePredefinedEntities();
diff --git a/parserInternals.c b/parserInternals.c
index 4edb111..68553c2 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -74,7 +74,7 @@
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 9b0a346..49ada34 100644
--- a/threads.c
+++ b/threads.c
@@ -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 @@
* - 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 @@
pthread_setspecific(globalkey, tsd);
return (tsd);
- } else
- return (globalval);
+ }
+ return (globalval);
+#else
+ return(NULL);
#endif
}
@@ -326,6 +332,29 @@
************************************************************************/
/**
+ * 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:
*
* xmlLockLibrary() is used to take out a re-entrant lock on the libxml2
@@ -334,6 +363,9 @@
void
xmlLockLibrary(void)
{
+#ifdef DEBUG_THREADS
+ xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
+#endif
xmlRMutexLock(xmlLibraryLock);
}
@@ -346,6 +378,9 @@
void
xmlUnlockLibrary(void)
{
+#ifdef DEBUG_THREADS
+ xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
+#endif
xmlRMutexUnlock(xmlLibraryLock);
}
@@ -358,6 +393,18 @@
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 @@
void
xmlCleanupThreads(void)
{
+ if (initialized == 0)
+ return;
+
+#ifdef DEBUG_THREADS
+ xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
+#endif
+
+ initialized = 0;
}