Re: [xml] libxml2 and pthreads



Daniel Veillard wrote:

  Ulrich Drepper looked at your mail in the archive as stated there isn't
enough information to be worth looking at. Provide a complete glibc bug
report at http://gnuweb.binarycompass.org/software/libc/bugs.html but not
here it is not libxml2 related.

I'll make up a test case next time I boot my FC2 machine.

An initial patch is attached.  It is not complete, but I think
shows what I am suggesting.  Completed code would have initialization
methods to assign the lock method pointers and the 3 locks.  The
global config would be slightly more complicated, requiring either
an at_once type callback or, perhaps more cleanly, a lock and a hash-table
to match a thread-id to a global-config object.

Also, my RH9 box has the wrong make-file generation tool (1.6 instead of 1.8 it appears),
so I had to hack the makefiles manually.  Those hacks are not included in this
patch so you'd have to change the Makefiles manually.

If there is no way that a non-pthread using libxml will become
the default compile option, then there is no real reason for me
to complete this because I will always have to compile my own
private libxml anyway.

Perhaps someone with more time and inclination than myself
will find it useful.

Thanks,
Ben

--
Ben Greear <greearb candelatech com>
Candela Technologies Inc  http://www.candelatech.com

diff -urN libxml2-2.6.11/catalog.c libxml2-2.6.11.ben/catalog.c
--- libxml2-2.6.11/catalog.c    2004-06-27 09:14:07.000000000 -0700
+++ libxml2-2.6.11.ben/catalog.c        2004-08-20 11:07:28.000000000 -0700
@@ -38,7 +38,7 @@
 #include <libxml/parserInternals.h>
 #include <libxml/catalog.h>
 #include <libxml/xmlerror.h>
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 #include <libxml/globals.h>
 
 #define MAX_DELEGATE   50
@@ -182,7 +182,7 @@
  * It also protects xmlCatalogXMLFiles
  * The core of this readers/writer scheme is in xmlFetchXMLCatalogFile()
  */
-static xmlRMutexPtr xmlCatalogMutex = NULL;
+//static xmlRMutexPtr xmlCatalogMutex = NULL;
 
 /*
  * Whether the catalog support was initialized.
@@ -1282,10 +1282,10 @@
     /*
      * lock the whole catalog for modification
      */
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
     if (catal->children != NULL) {
        /* Okay someone else did it in the meantime */
-       xmlRMutexUnlock(xmlCatalogMutex);
+        xmlCatalogMutexUnlock(); //RMutexUnlock(xmlCatalogMutex);
        return(0);
     }
 
@@ -1302,7 +1302,7 @@
            else
                catal->children = doc;
            catal->dealloc = 0;
-           xmlRMutexUnlock(xmlCatalogMutex);
+           xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
            return(0);
        }
        if (xmlDebugCatalogs)
@@ -1318,7 +1318,7 @@
     doc = xmlParseXMLCatalogFile(catal->prefer, catal->URL);
     if (doc == NULL) {
        catal->type = XML_CATA_BROKEN_CATALOG;
-       xmlRMutexUnlock(xmlCatalogMutex);
+        xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
        return(-1);
     }
 
@@ -1337,7 +1337,8 @@
                "%s added to file hash\n", catal->URL);
        xmlHashAddEntry(xmlCatalogXMLFiles, catal->URL, doc);
     }
-    xmlRMutexUnlock(xmlCatalogMutex);
+    
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
     return(0);
 }
 
@@ -2901,7 +2902,7 @@
 
     if (getenv("XML_DEBUG_CATALOG")) 
        xmlDebugCatalogs = 1;
-    xmlCatalogMutex = xmlNewRMutex();
+    //xmlCatalogMutex = xmlNewRMutex();
 
     xmlCatalogInitialized = 1;
 }
@@ -2918,7 +2919,7 @@
        return;
 
     xmlInitializeCatalogData();
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
 
     if (getenv("XML_DEBUG_CATALOG")) 
        xmlDebugCatalogs = 1;
@@ -2989,8 +2990,8 @@
            xmlDefaultCatalog = catal;
        }
     }
-
-    xmlRMutexUnlock(xmlCatalogMutex);
+    
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
 }
 
 
@@ -3014,22 +3015,22 @@
     if (!xmlCatalogInitialized)
        xmlInitializeCatalogData();
 
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
 
     if (xmlDefaultCatalog == NULL) {
        catal = xmlLoadACatalog(filename);
        if (catal == NULL) {
-           xmlRMutexUnlock(xmlCatalogMutex);
+            xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
            return(-1);
        }
 
        xmlDefaultCatalog = catal;
-       xmlRMutexUnlock(xmlCatalogMutex);
+        xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
        return(0);
     }
 
     ret = xmlExpandCatalog(xmlDefaultCatalog, filename);
-    xmlRMutexUnlock(xmlCatalogMutex);
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
     return(ret);
 }
 
@@ -3079,7 +3080,7 @@
     if (xmlCatalogInitialized == 0)
         return;
 
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
     if (xmlDebugCatalogs)
        xmlGenericError(xmlGenericErrorContext,
                "Catalogs cleanup\n");
@@ -3092,8 +3093,8 @@
     xmlDefaultCatalog = NULL;
     xmlDebugCatalogs = 0;
     xmlCatalogInitialized = 0;
-    xmlRMutexUnlock(xmlCatalogMutex);
-    xmlFreeRMutex(xmlCatalogMutex);
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
+    //xmlFreeRMutex(xmlCatalogMutex);
 }
 
 /**
@@ -3216,7 +3217,7 @@
     if (!xmlCatalogInitialized)
        xmlInitializeCatalogData();
 
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
     /*
      * Specific case where one want to override the default catalog
      * put in place by xmlInitializeCatalog();
@@ -3228,12 +3229,12 @@
        xmlDefaultCatalog->xml = xmlNewCatalogEntry(XML_CATA_CATALOG, NULL,
                                    orig, NULL,  xmlCatalogDefaultPrefer);
 
-       xmlRMutexUnlock(xmlCatalogMutex);
+        xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
        return(0);
     } 
 
     res = xmlACatalogAdd(xmlDefaultCatalog, type, orig, replace);
-    xmlRMutexUnlock(xmlCatalogMutex);
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
     return(res);
 }
 
@@ -3252,9 +3253,9 @@
     if (!xmlCatalogInitialized)
        xmlInitializeCatalog();
 
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
     res = xmlACatalogRemove(xmlDefaultCatalog, value);
-    xmlRMutexUnlock(xmlCatalogMutex);
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
     return(res);
 }
 
@@ -3272,9 +3273,9 @@
     if (!xmlCatalogInitialized)
        xmlInitializeCatalog();
 
-    xmlRMutexLock(xmlCatalogMutex);
+    xmlCatalogMutexLock(); //xmlRMutexLock(xmlCatalogMutex);
     res = xmlConvertSGMLCatalog(xmlDefaultCatalog);
-    xmlRMutexUnlock(xmlCatalogMutex);
+    xmlCatalogMutexUnlock(); //xmlRMutexUnlock(xmlCatalogMutex);
     return(res);
 }
 
diff -urN libxml2-2.6.11/elfgcchack.h libxml2-2.6.11.ben/elfgcchack.h
--- libxml2-2.6.11/elfgcchack.h 2004-06-29 06:24:43.000000000 -0700
+++ libxml2-2.6.11.ben/elfgcchack.h     2004-08-20 10:47:09.000000000 -0700
@@ -30,7 +30,10 @@
 #include "libxml/SAX2.h"
 #include "libxml/SAX.h"
 #include "libxml/schemasInternals.h"
+#if 0
 #include "libxml/threads.h"
+#endif
+
 #include "libxml/tree.h"
 #include "libxml/uri.h"
 #include "libxml/valid.h"
@@ -1002,9 +1005,11 @@
 extern __typeof (xmlCleanupPredefinedEntities) xmlCleanupPredefinedEntities 
__attribute((alias("xmlCleanupPredefinedEntities__internal_alias")));
 #define xmlCleanupPredefinedEntities xmlCleanupPredefinedEntities__internal_alias
 
+#if 0
 extern __typeof (xmlCleanupThreads) xmlCleanupThreads__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlCleanupThreads) xmlCleanupThreads 
__attribute((alias("xmlCleanupThreads__internal_alias")));
 #define xmlCleanupThreads xmlCleanupThreads__internal_alias
+#endif
 
 extern __typeof (xmlClearNodeInfoSeq) xmlClearNodeInfoSeq__internal_alias 
__attribute((visibility("hidden")));
 extern __typeof (xmlClearNodeInfoSeq) xmlClearNodeInfoSeq 
__attribute((alias("xmlClearNodeInfoSeq__internal_alias")));
@@ -1482,9 +1487,11 @@
 extern __typeof (xmlFreeInputStream) xmlFreeInputStream 
__attribute((alias("xmlFreeInputStream__internal_alias")));
 #define xmlFreeInputStream xmlFreeInputStream__internal_alias
 
+#if 0
 extern __typeof (xmlFreeMutex) xmlFreeMutex__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlFreeMutex) xmlFreeMutex __attribute((alias("xmlFreeMutex__internal_alias")));
 #define xmlFreeMutex xmlFreeMutex__internal_alias
+#endif
 
 extern __typeof (xmlFreeNode) xmlFreeNode__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlFreeNode) xmlFreeNode __attribute((alias("xmlFreeNode__internal_alias")));
@@ -1534,9 +1541,11 @@
 extern __typeof (xmlFreePropList) xmlFreePropList __attribute((alias("xmlFreePropList__internal_alias")));
 #define xmlFreePropList xmlFreePropList__internal_alias
 
+#if 0
 extern __typeof (xmlFreeRMutex) xmlFreeRMutex__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlFreeRMutex) xmlFreeRMutex __attribute((alias("xmlFreeRMutex__internal_alias")));
 #define xmlFreeRMutex xmlFreeRMutex__internal_alias
+#endif
 
 extern __typeof (xmlFreeRefTable) xmlFreeRefTable__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlFreeRefTable) xmlFreeRefTable __attribute((alias("xmlFreeRefTable__internal_alias")));
@@ -1634,9 +1643,11 @@
 extern __typeof (xmlGetFeaturesList) xmlGetFeaturesList 
__attribute((alias("xmlGetFeaturesList__internal_alias")));
 #define xmlGetFeaturesList xmlGetFeaturesList__internal_alias
 
+#if 0
 extern __typeof (xmlGetGlobalState) xmlGetGlobalState__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlGetGlobalState) xmlGetGlobalState 
__attribute((alias("xmlGetGlobalState__internal_alias")));
 #define xmlGetGlobalState xmlGetGlobalState__internal_alias
+#endif
 
 extern __typeof (xmlGetID) xmlGetID__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlGetID) xmlGetID __attribute((alias("xmlGetID__internal_alias")));
@@ -1694,9 +1705,11 @@
 extern __typeof (xmlGetRefs) xmlGetRefs __attribute((alias("xmlGetRefs__internal_alias")));
 #define xmlGetRefs xmlGetRefs__internal_alias
 
+#if 0
 extern __typeof (xmlGetThreadId) xmlGetThreadId__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlGetThreadId) xmlGetThreadId __attribute((alias("xmlGetThreadId__internal_alias")));
 #define xmlGetThreadId xmlGetThreadId__internal_alias
+#endif
 
 extern __typeof (xmlGetUTF8Char) xmlGetUTF8Char__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlGetUTF8Char) xmlGetUTF8Char __attribute((alias("xmlGetUTF8Char__internal_alias")));
@@ -1888,9 +1901,11 @@
 extern __typeof (xmlInitParserCtxt) xmlInitParserCtxt 
__attribute((alias("xmlInitParserCtxt__internal_alias")));
 #define xmlInitParserCtxt xmlInitParserCtxt__internal_alias
 
+#if 0
 extern __typeof (xmlInitThreads) xmlInitThreads__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlInitThreads) xmlInitThreads __attribute((alias("xmlInitThreads__internal_alias")));
 #define xmlInitThreads xmlInitThreads__internal_alias
+#endif
 
 #ifdef LIBXML_CATALOG_ENABLED
 extern __typeof (xmlInitializeCatalog) xmlInitializeCatalog__internal_alias 
__attribute((visibility("hidden")));
@@ -1946,9 +1961,11 @@
 extern __typeof (xmlIsLetter) xmlIsLetter __attribute((alias("xmlIsLetter__internal_alias")));
 #define xmlIsLetter xmlIsLetter__internal_alias
 
+#if 0
 extern __typeof (xmlIsMainThread) xmlIsMainThread__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlIsMainThread) xmlIsMainThread __attribute((alias("xmlIsMainThread__internal_alias")));
 #define xmlIsMainThread xmlIsMainThread__internal_alias
+#endif
 
 extern __typeof (xmlIsMixedElement) xmlIsMixedElement__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlIsMixedElement) xmlIsMixedElement 
__attribute((alias("xmlIsMixedElement__internal_alias")));
@@ -2106,9 +2123,11 @@
 #define xmlLoadSGMLSuperCatalog xmlLoadSGMLSuperCatalog__internal_alias
 #endif
 
+#if 0
 extern __typeof (xmlLockLibrary) xmlLockLibrary__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlLockLibrary) xmlLockLibrary __attribute((alias("xmlLockLibrary__internal_alias")));
 #define xmlLockLibrary xmlLockLibrary__internal_alias
+#endif
 
 #ifdef LIBXML_DEBUG_ENABLED
 extern __typeof (xmlLsCountNode) xmlLsCountNode__internal_alias __attribute((visibility("hidden")));
@@ -2174,6 +2193,7 @@
 extern __typeof (xmlMemoryStrdup) xmlMemoryStrdup __attribute((alias("xmlMemoryStrdup__internal_alias")));
 #define xmlMemoryStrdup xmlMemoryStrdup__internal_alias
 
+#if 0
 extern __typeof (xmlMutexLock) xmlMutexLock__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlMutexLock) xmlMutexLock __attribute((alias("xmlMutexLock__internal_alias")));
 #define xmlMutexLock xmlMutexLock__internal_alias
@@ -2181,6 +2201,7 @@
 extern __typeof (xmlMutexUnlock) xmlMutexUnlock__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlMutexUnlock) xmlMutexUnlock __attribute((alias("xmlMutexUnlock__internal_alias")));
 #define xmlMutexUnlock xmlMutexUnlock__internal_alias
+#endif
 
 extern __typeof (xmlNamespaceParseNCName) xmlNamespaceParseNCName__internal_alias 
__attribute((visibility("hidden")));
 extern __typeof (xmlNamespaceParseNCName) xmlNamespaceParseNCName 
__attribute((alias("xmlNamespaceParseNCName__internal_alias")));
@@ -2522,9 +2543,11 @@
 extern __typeof (xmlNewInputStream) xmlNewInputStream 
__attribute((alias("xmlNewInputStream__internal_alias")));
 #define xmlNewInputStream xmlNewInputStream__internal_alias
 
+#if 0
 extern __typeof (xmlNewMutex) xmlNewMutex__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlNewMutex) xmlNewMutex __attribute((alias("xmlNewMutex__internal_alias")));
 #define xmlNewMutex xmlNewMutex__internal_alias
+#endif
 
 extern __typeof (xmlNewNode) xmlNewNode__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlNewNode) xmlNewNode __attribute((alias("xmlNewNode__internal_alias")));
@@ -2558,9 +2581,11 @@
 extern __typeof (xmlNewProp) xmlNewProp __attribute((alias("xmlNewProp__internal_alias")));
 #define xmlNewProp xmlNewProp__internal_alias
 
+#if 0
 extern __typeof (xmlNewRMutex) xmlNewRMutex__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlNewRMutex) xmlNewRMutex __attribute((alias("xmlNewRMutex__internal_alias")));
 #define xmlNewRMutex xmlNewRMutex__internal_alias
+#endif
 
 extern __typeof (xmlNewReference) xmlNewReference__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlNewReference) xmlNewReference __attribute((alias("xmlNewReference__internal_alias")));
@@ -3180,6 +3205,7 @@
 extern __typeof (xmlPushInput) xmlPushInput __attribute((alias("xmlPushInput__internal_alias")));
 #define xmlPushInput xmlPushInput__internal_alias
 
+#if 0
 extern __typeof (xmlRMutexLock) xmlRMutexLock__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlRMutexLock) xmlRMutexLock __attribute((alias("xmlRMutexLock__internal_alias")));
 #define xmlRMutexLock xmlRMutexLock__internal_alias
@@ -3187,6 +3213,7 @@
 extern __typeof (xmlRMutexUnlock) xmlRMutexUnlock__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlRMutexUnlock) xmlRMutexUnlock __attribute((alias("xmlRMutexUnlock__internal_alias")));
 #define xmlRMutexUnlock xmlRMutexUnlock__internal_alias
+#endif
 
 extern __typeof (xmlReadDoc) xmlReadDoc__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlReadDoc) xmlReadDoc __attribute((alias("xmlReadDoc__internal_alias")));
@@ -6222,9 +6249,11 @@
 extern __typeof (xmlUnlinkNode) xmlUnlinkNode __attribute((alias("xmlUnlinkNode__internal_alias")));
 #define xmlUnlinkNode xmlUnlinkNode__internal_alias
 
+#if 0
 extern __typeof (xmlUnlockLibrary) xmlUnlockLibrary__internal_alias __attribute((visibility("hidden")));
 extern __typeof (xmlUnlockLibrary) xmlUnlockLibrary __attribute((alias("xmlUnlockLibrary__internal_alias")));
 #define xmlUnlockLibrary xmlUnlockLibrary__internal_alias
+#endif
 
 #ifdef LIBXML_TREE_ENABLED
 extern __typeof (xmlUnsetNsProp) xmlUnsetNsProp__internal_alias __attribute((visibility("hidden")));
diff -urN libxml2-2.6.11/globals.c libxml2-2.6.11.ben/globals.c
--- libxml2-2.6.11/globals.c    2004-06-27 09:14:07.000000000 -0700
+++ libxml2-2.6.11.ben/globals.c        2004-08-20 11:17:06.000000000 -0700
@@ -21,7 +21,7 @@
 
 #include <libxml/globals.h>
 #include <libxml/xmlmemory.h>
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 
 /* #define DEBUG_GLOBALS */
 
@@ -37,7 +37,7 @@
 /*
  * Mutex to protect "ForNewThreads" variables
  */
-static xmlMutexPtr xmlThrDefMutex = NULL;
+//static xmlMutexPtr xmlThrDefMutex = NULL;
 
 /**
  * xmlInitGlobals:
@@ -46,7 +46,7 @@
  */
 void xmlInitGlobals()
 {
-    xmlThrDefMutex = xmlNewMutex();
+   //xmlThrDefMutex = xmlNewMutex();
 }
 
 /**
@@ -56,10 +56,10 @@
  */
 void xmlCleanupGlobals()
 {
-    if (xmlThrDefMutex != NULL) {
-       xmlFreeMutex(xmlThrDefMutex);
-       xmlThrDefMutex = NULL;
-    }
+   //if (xmlThrDefMutex != NULL) {
+   //     xmlFreeMutex(xmlThrDefMutex);
+   //  xmlThrDefMutex = NULL;
+   //}
 }
 
 /************************************************************************
@@ -139,7 +139,7 @@
 xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
 #endif /* DEBUG_MEMORY_LOCATION || DEBUG_MEMORY */
 
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 #include <libxml/globals.h>
 #include <libxml/SAX.h>
 
@@ -498,10 +498,10 @@
     /*
      * Perform initialization as required by libxml
      */
-    if (xmlThrDefMutex == NULL)
-        xmlInitGlobals();
+    //if (xmlThrDefMutex == NULL)
+    //    xmlInitGlobals();
 
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
 
 #ifdef LIBXML_DOCB_ENABLED
     initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
@@ -558,7 +558,7 @@
        gs->xmlOutputBufferCreateFilenameValue = xmlOutputBufferCreateFilenameValueThrDef;
     memset(&gs->xmlLastError, 0, sizeof(xmlError));
 
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 }
 
 /**
@@ -567,21 +567,21 @@
  */
 void
 xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     xmlGenericErrorContextThrDef = ctx;
     if (handler != NULL)
        xmlGenericErrorThrDef = handler;
     else
        xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 }
 
 void
 xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     xmlGenericErrorContextThrDef = ctx;
     xmlStructuredErrorThrDef = handler;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 }
 
 /**
@@ -607,12 +607,12 @@
 {
     xmlRegisterNodeFunc old;
     
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     old = xmlRegisterNodeDefaultValueThrDef;
     
     __xmlRegisterCallbacks = 1;
     xmlRegisterNodeDefaultValueThrDef = func;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 
     return(old);
 }
@@ -640,12 +640,12 @@
 {
     xmlDeregisterNodeFunc old;
 
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     old = xmlDeregisterNodeDefaultValueThrDef;
     
     __xmlRegisterCallbacks = 1;
     xmlDeregisterNodeDefaultValueThrDef = func;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 
     return(old);
 }
@@ -655,14 +655,14 @@
 {
     xmlParserInputBufferCreateFilenameFunc old;
     
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     old = xmlParserInputBufferCreateFilenameValueThrDef;
     if (old == NULL) {
                old = __xmlParserInputBufferCreateFilename;
        }
 
     xmlParserInputBufferCreateFilenameValueThrDef = func;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 
     return(old);
 }
@@ -672,7 +672,7 @@
 {
     xmlOutputBufferCreateFilenameFunc old;
     
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     old = xmlOutputBufferCreateFilenameValueThrDef;
 #ifdef LIBXML_OUTPUT_ENABLED
     if (old == NULL) {
@@ -680,7 +680,7 @@
        }
 #endif
     xmlOutputBufferCreateFilenameValueThrDef = func;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
 
     return(old);
 }
@@ -794,10 +794,10 @@
 }
 xmlBufferAllocationScheme xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v) {
     xmlBufferAllocationScheme ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlBufferAllocSchemeThrDef;
     xmlBufferAllocSchemeThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -811,10 +811,10 @@
 }
 int xmlThrDefDefaultBufferSize(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlDefaultBufferSizeThrDef;
     xmlDefaultBufferSizeThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -848,10 +848,10 @@
 }
 int xmlThrDefDoValidityCheckingDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlDoValidityCheckingDefaultValueThrDef;
     xmlDoValidityCheckingDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -892,10 +892,10 @@
 }
 int xmlThrDefGetWarningsDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlGetWarningsDefaultValueThrDef;
     xmlGetWarningsDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -909,10 +909,10 @@
 }
 int xmlThrDefIndentTreeOutput(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlIndentTreeOutputThrDef;
     xmlIndentTreeOutputThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -926,10 +926,10 @@
 }
 const char * xmlThrDefTreeIndentString(const char * v) {
     const char * ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlTreeIndentStringThrDef;
     xmlTreeIndentStringThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -943,10 +943,10 @@
 }
 int xmlThrDefKeepBlanksDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlKeepBlanksDefaultValueThrDef;
     xmlKeepBlanksDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -960,10 +960,10 @@
 }
 int xmlThrDefLineNumbersDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlLineNumbersDefaultValueThrDef;
     xmlLineNumbersDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -977,10 +977,10 @@
 }
 int xmlThrDefLoadExtDtdDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlLoadExtDtdDefaultValueThrDef;
     xmlLoadExtDtdDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -994,10 +994,10 @@
 }
 int xmlThrDefParserDebugEntities(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlParserDebugEntitiesThrDef;
     xmlParserDebugEntitiesThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -1020,10 +1020,10 @@
 }
 int xmlThrDefPedanticParserDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlPedanticParserDefaultValueThrDef;
     xmlPedanticParserDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -1037,10 +1037,10 @@
 }
 int xmlThrDefSaveNoEmptyTags(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlSaveNoEmptyTagsThrDef;
     xmlSaveNoEmptyTagsThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
@@ -1054,10 +1054,10 @@
 }
 int xmlThrDefSubstituteEntitiesDefaultValue(int v) {
     int ret;
-    xmlMutexLock(xmlThrDefMutex);
+    xmlThreadDefMutexLock();
     ret = xmlSubstituteEntitiesDefaultValueThrDef;
     xmlSubstituteEntitiesDefaultValueThrDef = v;
-    xmlMutexUnlock(xmlThrDefMutex);
+    xmlThreadDefMutexUnlock();
     return ret;
 }
 
diff -urN libxml2-2.6.11/include/libxml/globals.h libxml2-2.6.11.ben/include/libxml/globals.h
--- libxml2-2.6.11/include/libxml/globals.h     2004-06-29 05:33:58.000000000 -0700
+++ libxml2-2.6.11.ben/include/libxml/globals.h 2004-08-20 10:27:38.000000000 -0700
@@ -127,7 +127,7 @@
 #ifdef __cplusplus
 }
 #endif
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 #ifdef __cplusplus
 extern "C" {
 #endif
diff -urN libxml2-2.6.11/include/libxml/Makefile.am libxml2-2.6.11.ben/include/libxml/Makefile.am
--- libxml2-2.6.11/include/libxml/Makefile.am   2004-03-04 08:20:42.000000000 -0800
+++ libxml2-2.6.11.ben/include/libxml/Makefile.am       2004-08-20 10:23:52.000000000 -0700
@@ -29,7 +29,6 @@
                xmlversion.h \
                DOCBparser.h \
                catalog.h \
-               threads.h \
                globals.h \
                c14n.h \
                xmlautomata.h \
diff -urN libxml2-2.6.11/include/libxml/threads_cb.h libxml2-2.6.11.ben/include/libxml/threads_cb.h
--- libxml2-2.6.11/include/libxml/threads_cb.h  1969-12-31 16:00:00.000000000 -0800
+++ libxml2-2.6.11.ben/include/libxml/threads_cb.h      2004-08-20 12:16:46.000000000 -0700
@@ -0,0 +1,50 @@
+
+
+#ifndef __THREADS_CALLBACKS__H__
+#define __THREADS_CALLBACKS__H__
+
+#include <libxml/xmlversion.h>
+#include <libxml/globals.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// External lock methods (callbacks)
+extern void (*xml_do_external_lock)(void* lock);
+extern void (*xml_do_external_unlock)(void* lock);
+
+// Recursive locks
+extern void (*xml_do_external_rlock)(void* rlock);
+extern void (*xml_do_external_runlock)(void* rlock);
+
+// Helper methods.
+extern int (*xml_get_thread_id)(void);
+
+extern void* mem_mutex_lock;
+extern void* thr_def_mutex_lock;
+extern void* catalog_mutex_rlock;
+
+
+int xmlIsMainThread();
+void xmlInitThreads(void);
+void xmlCleanupThreads(void);
+xmlGlobalStatePtr xmlGetGlobalState(void);
+
+int xmlGetThreadId(void);
+
+void xmlMemMutexLock(void);
+void xmlMemMutexUnlock(void);
+
+void xmlThreadDefMutexLock(void);
+void xmlThreadDefMutexUnlock(void);
+
+void xmlCatalogMutexLock(void);
+void xmlCatalogMutexUnlock(void);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff -urN libxml2-2.6.11/include/libxml/threads.h libxml2-2.6.11.ben/include/libxml/threads.h
--- libxml2-2.6.11/include/libxml/threads.h     2003-11-18 08:28:58.000000000 -0800
+++ libxml2-2.6.11.ben/include/libxml/threads.h 2004-08-20 10:31:35.000000000 -0700
@@ -8,6 +8,8 @@
  * Author: Daniel Veillard
  */
 
+#warning "Don't use me"
+
 #ifndef __XML_THREADS_H__
 #define __XML_THREADS_H__
 
diff -urN libxml2-2.6.11/include/libxml/xmlmemory.h libxml2-2.6.11.ben/include/libxml/xmlmemory.h
--- libxml2-2.6.11/include/libxml/xmlmemory.h   2004-02-09 04:28:17.000000000 -0800
+++ libxml2-2.6.11.ben/include/libxml/xmlmemory.h       2004-08-20 10:33:18.000000000 -0700
@@ -211,7 +211,7 @@
 
 #ifndef __XML_GLOBALS_H
 #ifndef __XML_THREADS_H__
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 #include <libxml/globals.h>
 #endif
 #endif
diff -urN libxml2-2.6.11/parser.c libxml2-2.6.11.ben/parser.c
--- libxml2-2.6.11/parser.c     2004-07-05 08:47:28.000000000 -0700
+++ libxml2-2.6.11.ben/parser.c 2004-08-20 10:36:52.000000000 -0700
@@ -43,7 +43,7 @@
 #include <string.h>
 #include <stdarg.h>
 #include <libxml/xmlmemory.h>
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 #include <libxml/globals.h>
 #include <libxml/tree.h>
 #include <libxml/parser.h>
diff -urN libxml2-2.6.11/threads.c libxml2-2.6.11.ben/threads.c
--- libxml2-2.6.11/threads.c    2003-11-18 05:41:00.000000000 -0800
+++ libxml2-2.6.11.ben/threads.c        2004-08-20 10:42:23.000000000 -0700
@@ -1,759 +1,4 @@
-/**
- * threads.c: set of generic threading related routines 
- *
- * See Copyright for the status of this software.
- *
- * Gary Pennington <Gary Pennington uk sun com>
- * daniel veillard com
- */
 
-#define IN_LIBXML
-#include "libxml.h"
 
-#include <string.h>
+/* Nothing here */
 
-#include <libxml/threads.h>
-#include <libxml/globals.h>
-
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifdef HAVE_PTHREAD_H
-#include <pthread.h>
-#endif
-
-#ifdef HAVE_WIN32_THREADS
-#include <windows.h>
-#ifndef HAVE_COMPILER_TLS
-#include <process.h>
-#endif
-#endif
-
-#ifdef HAVE_BEOS_THREADS
-#include <OS.h>
-#include <TLS.h>
-#endif
-
-#if defined(SOLARIS)
-#include <note.h>
-#endif
-
-/* #define DEBUG_THREADS */
-
-/*
- * TODO: this module still uses malloc/free and not xmlMalloc/xmlFree
- *       to avoid some crazyness since xmlMalloc/xmlFree may actually
- *       be hosted on allocated blocks needing them for the allocation ...
- */
-
-/*
- * xmlMutex are a simple mutual exception locks
- */
-struct _xmlMutex {
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_t lock;
-#elif defined HAVE_WIN32_THREADS
-    HANDLE mutex;
-#elif defined HAVE_BEOS_THREADS
-       sem_id sem;
-       thread_id tid;
-#else
-    int empty;
-#endif
-};
-
-/*
- * xmlRMutex are reentrant mutual exception locks
- */
-struct _xmlRMutex {
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_t lock;
-    unsigned int    held;
-    unsigned int    waiters;
-    pthread_t       tid;
-    pthread_cond_t  cv;
-#elif defined HAVE_WIN32_THREADS
-    CRITICAL_SECTION cs;
-    unsigned int count;
-#elif defined HAVE_BEOS_THREADS
-       xmlMutexPtr lock;
-       thread_id tid;
-       int32 count;
-#else
-    int empty;
-#endif
-};
-/*
- * This module still has some internal static data.
- *   - xmlLibraryLock a global lock
- *   - globalkey used for per-thread data
- */
-
-#ifdef HAVE_PTHREAD_H
-static pthread_key_t   globalkey;
-static pthread_t       mainthread;
-static pthread_once_t once_control = PTHREAD_ONCE_INIT;
-#elif defined HAVE_WIN32_THREADS
-#if defined(HAVE_COMPILER_TLS)
-static __declspec(thread) xmlGlobalState tlstate;
-static __declspec(thread) int tlstate_inited = 0;
-#else /* HAVE_COMPILER_TLS */
-static DWORD globalkey = TLS_OUT_OF_INDEXES;
-#endif /* HAVE_COMPILER_TLS */
-static DWORD mainthread;
-static int run_once_init = 1;
-/* endif HAVE_WIN32_THREADS */
-#elif defined HAVE_BEOS_THREADS
-int32 globalkey = 0;
-thread_id mainthread = 0;
-int32 run_once_init = 0;
-#endif
-
-static xmlRMutexPtr    xmlLibraryLock = NULL;
-#ifdef LIBXML_THREAD_ENABLED
-static void xmlOnceInit(void);
-#endif
-
-/**
- * xmlNewMutex:
- *
- * xmlNewMutex() is used to allocate a libxml2 token struct for use in
- * synchronizing access to data.
- *
- * Returns a new simple mutex pointer or NULL in case of error
- */
-xmlMutexPtr
-xmlNewMutex(void)
-{
-    xmlMutexPtr tok;
-
-    if ((tok = malloc(sizeof(xmlMutex))) == NULL)
-        return (NULL);
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_init(&tok->lock, NULL);
-#elif defined HAVE_WIN32_THREADS
-    tok->mutex = CreateMutex(NULL, FALSE, NULL);
-#elif defined HAVE_BEOS_THREADS
-       if ((tok->sem = create_sem(1, "xmlMutex")) < B_OK) {
-               free(tok);
-               return NULL;
-       }
-       tok->tid = -1;
-#endif
-    return (tok);
-}
-
-/**
- * xmlFreeMutex:
- * @tok:  the simple mutex
- *
- * xmlFreeMutex() is used to reclaim resources associated with a libxml2 token
- * struct.
- */
-void
-xmlFreeMutex(xmlMutexPtr tok)
-{
-    if (tok == NULL) return;
-
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_destroy(&tok->lock);
-#elif defined HAVE_WIN32_THREADS
-    CloseHandle(tok->mutex);
-#elif defined HAVE_BEOS_THREADS
-       delete_sem(tok->sem);
-#endif
-    free(tok);
-}
-
-/**
- * xmlMutexLock:
- * @tok:  the simple mutex
- *
- * xmlMutexLock() is used to lock a libxml2 token.
- */
-void
-xmlMutexLock(xmlMutexPtr tok)
-{
-    if (tok == NULL)
-        return;
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_lock(&tok->lock);
-#elif defined HAVE_WIN32_THREADS
-    WaitForSingleObject(tok->mutex, INFINITE);
-#elif defined HAVE_BEOS_THREADS
-       if (acquire_sem(tok->sem) != B_NO_ERROR) {
-#ifdef DEBUG_THREADS
-               xmlGenericError(xmlGenericErrorContext, "xmlMutexLock():BeOS:Couldn't aquire semaphore\n");
-               exit();
-#endif
-       }
-       tok->tid = find_thread(NULL);
-#endif
-
-}
-
-/**
- * xmlMutexUnlock:
- * @tok:  the simple mutex
- *
- * xmlMutexUnlock() is used to unlock a libxml2 token.
- */
-void
-xmlMutexUnlock(xmlMutexPtr tok)
-{
-    if (tok == NULL)
-        return;
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_unlock(&tok->lock);
-#elif defined HAVE_WIN32_THREADS
-    ReleaseMutex(tok->mutex);
-#elif defined HAVE_BEOS_THREADS
-       if (tok->tid == find_thread(NULL)) {
-               tok->tid = -1;
-               release_sem(tok->sem);
-       }
-#endif
-}
-
-/**
- * xmlNewRMutex:
- *
- * xmlRNewMutex() is used to allocate a reentrant mutex for use in
- * synchronizing access to data. token_r is a re-entrant lock and thus useful
- * for synchronizing access to data structures that may be manipulated in a
- * recursive fashion.
- *
- * Returns the new reentrant mutex pointer or NULL in case of error
- */
-xmlRMutexPtr
-xmlNewRMutex(void)
-{
-    xmlRMutexPtr tok;
-
-    if ((tok = malloc(sizeof(xmlRMutex))) == NULL)
-        return (NULL);
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_init(&tok->lock, NULL);
-    tok->held = 0;
-    tok->waiters = 0;
-    pthread_cond_init(&tok->cv, NULL);
-#elif defined HAVE_WIN32_THREADS
-    InitializeCriticalSection(&tok->cs);
-    tok->count = 0;
-#elif defined HAVE_BEOS_THREADS
-       if ((tok->lock = xmlNewMutex()) == NULL) {
-               free(tok);
-               return NULL;
-       }
-       tok->count = 0;
-#endif
-    return (tok);
-}
-
-/**
- * xmlFreeRMutex:
- * @tok:  the reentrant mutex
- *
- * xmlRFreeMutex() is used to reclaim resources associated with a
- * reentrant mutex.
- */
-void
-xmlFreeRMutex(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
-{
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_destroy(&tok->lock);
-#elif defined HAVE_WIN32_THREADS
-    DeleteCriticalSection(&tok->cs);
-#elif defined HAVE_BEOS_THREADS
-       xmlFreeMutex(tok->lock);
-#endif
-    free(tok);
-}
-
-/**
- * xmlRMutexLock:
- * @tok:  the reentrant mutex
- *
- * xmlRMutexLock() is used to lock a libxml2 token_r.
- */
-void
-xmlRMutexLock(xmlRMutexPtr tok)
-{
-    if (tok == NULL)
-        return;
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_lock(&tok->lock);
-    if (tok->held) {
-        if (pthread_equal(tok->tid, pthread_self())) {
-            tok->held++;
-            pthread_mutex_unlock(&tok->lock);
-            return;
-        } else {
-            tok->waiters++;
-            while (tok->held)
-                pthread_cond_wait(&tok->cv, &tok->lock);
-            tok->waiters--;
-        }
-    }
-    tok->tid = pthread_self();
-    tok->held = 1;
-    pthread_mutex_unlock(&tok->lock);
-#elif defined HAVE_WIN32_THREADS
-    EnterCriticalSection(&tok->cs);
-    ++tok->count;
-#elif defined HAVE_BEOS_THREADS
-       if (tok->lock->tid == find_thread(NULL)) {
-               tok->count++;
-               return;
-       } else {
-               xmlMutexLock(tok->lock);
-               tok->count = 1;
-       }
-#endif
-}
-
-/**
- * xmlRMutexUnlock:
- * @tok:  the reentrant mutex
- *
- * xmlRMutexUnlock() is used to unlock a libxml2 token_r.
- */
-void
-xmlRMutexUnlock(xmlRMutexPtr tok ATTRIBUTE_UNUSED)
-{
-    if (tok == NULL)
-        return;
-#ifdef HAVE_PTHREAD_H
-    pthread_mutex_lock(&tok->lock);
-    tok->held--;
-    if (tok->held == 0) {
-        if (tok->waiters)
-            pthread_cond_signal(&tok->cv);
-        tok->tid = 0;
-    }
-    pthread_mutex_unlock(&tok->lock);
-#elif defined HAVE_WIN32_THREADS
-    if (!--tok->count) 
-       LeaveCriticalSection(&tok->cs);
-#elif defined HAVE_BEOS_THREADS
-       if (tok->lock->tid == find_thread(NULL)) {
-               tok->count--;
-               if (tok->count == 0) {
-                       xmlMutexUnlock(tok->lock);
-               }
-               return;
-       }
-#endif
-}
-
-/************************************************************************
- *                                                                     *
- *                     Per thread global state handling                *
- *                                                                     *
- ************************************************************************/
-
-#ifdef LIBXML_THREAD_ENABLED
-/**
- * xmlFreeGlobalState:
- * @state:  a thread global state
- *
- * xmlFreeGlobalState() is called when a thread terminates with a non-NULL
- * global state. It is is used here to reclaim memory resources.
- */
-static void
-xmlFreeGlobalState(void *state)
-{
-    free(state);
-}
-
-/**
- * xmlNewGlobalState:
- *
- * xmlNewGlobalState() allocates a global state. This structure is used to
- * hold all data for use by a thread when supporting backwards compatibility
- * of libxml2 to pre-thread-safe behaviour.
- *
- * Returns the newly allocated xmlGlobalStatePtr or NULL in case of error
- */
-static xmlGlobalStatePtr
-xmlNewGlobalState(void)
-{
-    xmlGlobalState *gs;
-    
-    gs = malloc(sizeof(xmlGlobalState));
-    if (gs == NULL)
-       return(NULL);
-
-    memset(gs, 0, sizeof(xmlGlobalState));
-    xmlInitializeGlobalState(gs);
-    return (gs);
-}
-#endif /* LIBXML_THREAD_ENABLED */
-
-
-#ifdef HAVE_WIN32_THREADS
-#if !defined(HAVE_COMPILER_TLS)
-#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
-typedef struct _xmlGlobalStateCleanupHelperParams
-{
-    HANDLE thread;
-    void *memory;
-} xmlGlobalStateCleanupHelperParams;
-
-static void xmlGlobalStateCleanupHelper (void *p)
-{
-    xmlGlobalStateCleanupHelperParams *params = (xmlGlobalStateCleanupHelperParams *) p;
-    WaitForSingleObject(params->thread, INFINITE);
-    CloseHandle(params->thread);
-    xmlFreeGlobalState(params->memory);
-    free(params);
-    _endthread();
-}
-#else /* LIBXML_STATIC && !LIBXML_STATIC_FOR_DLL */
-
-typedef struct _xmlGlobalStateCleanupHelperParams
-{
-    void *memory;
-    struct _xmlGlobalStateCleanupHelperParams * prev;
-    struct _xmlGlobalStateCleanupHelperParams * next;
-} xmlGlobalStateCleanupHelperParams;
-
-static xmlGlobalStateCleanupHelperParams * cleanup_helpers_head = NULL;
-static CRITICAL_SECTION cleanup_helpers_cs;
-
-#endif /* LIBXMLSTATIC && !LIBXML_STATIC_FOR_DLL */
-#endif /* HAVE_COMPILER_TLS */
-#endif /* HAVE_WIN32_THREADS */
-
-#if defined HAVE_BEOS_THREADS
-/**
- * xmlGlobalStateCleanup:
- * @data: unused parameter
- *
- * Used for Beos only
- */
-void xmlGlobalStateCleanup(void *data)
-{
-       void *globalval = tls_get(globalkey);
-       if (globalval != NULL)
-               xmlFreeGlobalState(globalval);
-}
-#endif
-
-/**
- * xmlGetGlobalState:
- *
- * xmlGetGlobalState() is called to retrieve the global state for a thread.
- *
- * Returns the thread global state or NULL in case of error
- */
-xmlGlobalStatePtr
-xmlGetGlobalState(void)
-{
-#ifdef HAVE_PTHREAD_H
-    xmlGlobalState *globalval;
-
-    pthread_once(&once_control, xmlOnceInit);
-
-    if ((globalval = (xmlGlobalState *)
-               pthread_getspecific(globalkey)) == NULL) {
-        xmlGlobalState *tsd = xmlNewGlobalState();
-
-        pthread_setspecific(globalkey, tsd);
-        return (tsd);
-    }
-    return (globalval);
-#elif defined HAVE_WIN32_THREADS
-#if defined(HAVE_COMPILER_TLS)
-    if (!tlstate_inited) {
-       tlstate_inited = 1;
-       xmlInitializeGlobalState(&tlstate);
-    }
-    return &tlstate;
-#else /* HAVE_COMPILER_TLS */
-    xmlGlobalState *globalval;
-    xmlGlobalStateCleanupHelperParams * p;
-
-    if (run_once_init) { 
-       run_once_init = 0; 
-       xmlOnceInit(); 
-    }
-#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
-    globalval = (xmlGlobalState *)TlsGetValue(globalkey);
-#else
-    p = (xmlGlobalStateCleanupHelperParams*)TlsGetValue(globalkey);
-    globalval = (xmlGlobalState *)(p ? p->memory : NULL);
-#endif
-    if (globalval == NULL) {
-       xmlGlobalState *tsd = xmlNewGlobalState();
-       p = (xmlGlobalStateCleanupHelperParams *) malloc(sizeof(xmlGlobalStateCleanupHelperParams));
-       p->memory = tsd;
-#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
-       DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), 
-               GetCurrentProcess(), &p->thread, 0, TRUE, DUPLICATE_SAME_ACCESS);
-       TlsSetValue(globalkey, tsd);
-       _beginthread(xmlGlobalStateCleanupHelper, 0, p);
-#else
-       EnterCriticalSection(&cleanup_helpers_cs);      
-        if (cleanup_helpers_head != NULL) {
-            cleanup_helpers_head->prev = p;
-        }
-       p->next = cleanup_helpers_head;
-       p->prev = NULL;
-       cleanup_helpers_head = p;
-       TlsSetValue(globalkey, p);
-       LeaveCriticalSection(&cleanup_helpers_cs);      
-#endif
-
-       return (tsd);
-    }
-    return (globalval);
-#endif /* HAVE_COMPILER_TLS */
-#elif defined HAVE_BEOS_THREADS
-    xmlGlobalState *globalval;
-
-    xmlOnceInit();
-
-    if ((globalval = (xmlGlobalState *)
-               tls_get(globalkey)) == NULL) {
-        xmlGlobalState *tsd = xmlNewGlobalState();
-
-        tls_set(globalkey, tsd);
-        on_exit_thread(xmlGlobalStateCleanup, NULL);
-        return (tsd);
-    }
-    return (globalval);
-#else
-    return(NULL);
-#endif
-}
-
-/************************************************************************
- *                                                                     *
- *                     Library wide thread interfaces                  *
- *                                                                     *
- ************************************************************************/
-
-/**
- * xmlGetThreadId:
- *
- * xmlGetThreadId() find the current thread ID number
- *
- * Returns the current thread ID number
- */
-int
-xmlGetThreadId(void)
-{
-#ifdef HAVE_PTHREAD_H
-    return((int) pthread_self());
-#elif defined HAVE_WIN32_THREADS
-    return GetCurrentThreadId();
-#elif defined HAVE_BEOS_THREADS
-       return find_thread(NULL);
-#else
-    return((int) 0);
-#endif
-}
-
-/**
- * xmlIsMainThread:
- *
- * xmlIsMainThread() check whether the current thread is the main thread.
- *
- * Returns 1 if the current thread is the main thread, 0 otherwise
- */
-int
-xmlIsMainThread(void)
-{
-#ifdef HAVE_PTHREAD_H
-    pthread_once(&once_control, xmlOnceInit);
-#elif defined HAVE_WIN32_THREADS
-    if (run_once_init) { 
-       run_once_init = 0; 
-       xmlOnceInit (); 
-    }
-#elif defined HAVE_BEOS_THREADS
-       xmlOnceInit();
-#endif
-        
-#ifdef DEBUG_THREADS
-    xmlGenericError(xmlGenericErrorContext, "xmlIsMainThread()\n");
-#endif
-#ifdef HAVE_PTHREAD_H
-    return(mainthread == pthread_self());
-#elif defined HAVE_WIN32_THREADS
-    return(mainthread == GetCurrentThreadId ());
-#elif defined HAVE_BEOS_THREADS
-       return(mainthread == find_thread(NULL));
-#else
-    return(1);
-#endif
-}
-
-/**
- * xmlLockLibrary:
- *
- * xmlLockLibrary() is used to take out a re-entrant lock on the libxml2
- * library.
- */
-void
-xmlLockLibrary(void)
-{
-#ifdef DEBUG_THREADS
-    xmlGenericError(xmlGenericErrorContext, "xmlLockLibrary()\n");
-#endif
-    xmlRMutexLock(xmlLibraryLock);
-}
-
-/**
- * xmlUnlockLibrary:
- *
- * xmlUnlockLibrary() is used to release a re-entrant lock on the libxml2
- * library.
- */
-void
-xmlUnlockLibrary(void)
-{
-#ifdef DEBUG_THREADS
-    xmlGenericError(xmlGenericErrorContext, "xmlUnlockLibrary()\n");
-#endif
-    xmlRMutexUnlock(xmlLibraryLock);
-}
-
-/**
- * xmlInitThreads:
- *
- * xmlInitThreads() is used to to initialize all the thread related
- * data of the libxml2 library.
- */
-void
-xmlInitThreads(void)
-{
-#ifdef DEBUG_THREADS
-    xmlGenericError(xmlGenericErrorContext, "xmlInitThreads()\n");
-#endif
-#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || 
defined(LIBXML_STATIC_FOR_DLL))
-    InitializeCriticalSection(&cleanup_helpers_cs);
-#endif
-}
-
-/**
- * xmlCleanupThreads:
- *
- * xmlCleanupThreads() is used to to cleanup all the thread related
- * data of the libxml2 library once processing has ended.
- */
-void
-xmlCleanupThreads(void)
-{
-#ifdef DEBUG_THREADS
-    xmlGenericError(xmlGenericErrorContext, "xmlCleanupThreads()\n");
-#endif
-#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || 
defined(LIBXML_STATIC_FOR_DLL))
-    if (globalkey != TLS_OUT_OF_INDEXES) {
-       xmlGlobalStateCleanupHelperParams * p;
-       EnterCriticalSection(&cleanup_helpers_cs);
-       p = cleanup_helpers_head;
-       while (p != NULL) {
-               xmlGlobalStateCleanupHelperParams * temp = p;
-               p = p->next;
-               xmlFreeGlobalState(temp->memory);
-               free(temp);
-       }
-       cleanup_helpers_head = 0;
-       LeaveCriticalSection(&cleanup_helpers_cs);
-       TlsFree(globalkey);
-       globalkey = TLS_OUT_OF_INDEXES;
-    }
-    DeleteCriticalSection(&cleanup_helpers_cs);
-#endif
-}
-
-#ifdef LIBXML_THREAD_ENABLED
-/**
- * xmlOnceInit
- *
- * xmlOnceInit() is used to initialize the value of mainthread for use
- * in other routines. This function should only be called using
- * pthread_once() in association with the once_control variable to ensure
- * that the function is only called once. See man pthread_once for more
- * details.
- */
-static void
-xmlOnceInit(void) {
-#ifdef HAVE_PTHREAD_H
-    (void) pthread_key_create(&globalkey, xmlFreeGlobalState);
-    mainthread = pthread_self();
-#endif
-
-#if defined(HAVE_WIN32_THREADS)
-#if !defined(HAVE_COMPILER_TLS)
-    globalkey = TlsAlloc();
-#endif
-    mainthread = GetCurrentThreadId();
-#endif
-
-#ifdef HAVE_BEOS_THREADS
-       if (atomic_add(&run_once_init, 1) == 0) {
-               globalkey = tls_allocate();
-               tls_set(globalkey, NULL);
-               mainthread = find_thread(NULL);
-       } else
-               atomic_add(&run_once_init, -1);
-#endif
-}
-#endif
-
-/**
- * DllMain:
- * @hinstDLL: handle to DLL instance
- * @fdwReason: Reason code for entry
- * @lpvReserved: generic pointer (depends upon reason code)
- *
- * Entry point for Windows library. It is being used to free thread-specific
- * storage.
- *
- * Returns TRUE always
- */
-#if defined(HAVE_WIN32_THREADS) && !defined(HAVE_COMPILER_TLS) && (!defined(LIBXML_STATIC) || 
defined(LIBXML_STATIC_FOR_DLL))
-#if defined(LIBXML_STATIC_FOR_DLL)
-BOOL WINAPI xmlDllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 
-#else
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) 
-#endif
-{
-    switch(fdwReason) {
-    case DLL_THREAD_DETACH:
-       if (globalkey != TLS_OUT_OF_INDEXES) {
-           xmlGlobalState *globalval = NULL;
-           xmlGlobalStateCleanupHelperParams * p =
-               (xmlGlobalStateCleanupHelperParams*)TlsGetValue(globalkey);
-           globalval = (xmlGlobalState *)(p ? p->memory : NULL);
-            if (globalval) {
-                xmlFreeGlobalState(globalval);
-                TlsSetValue(globalkey,NULL);
-            }
-           if (p)
-           {
-               EnterCriticalSection(&cleanup_helpers_cs);
-                if (p == cleanup_helpers_head)
-                   cleanup_helpers_head = p->next;
-                else
-                   p->prev->next = p->next;
-                if (p->next != NULL)
-                    p->next->prev = p->prev;
-               LeaveCriticalSection(&cleanup_helpers_cs);
-               free(p);
-           }
-       }
-       break;
-    }
-    return TRUE;
-}
-#endif
diff -urN libxml2-2.6.11/threads_cb.c libxml2-2.6.11.ben/threads_cb.c
--- libxml2-2.6.11/threads_cb.c 1969-12-31 16:00:00.000000000 -0800
+++ libxml2-2.6.11.ben/threads_cb.c     2004-08-20 12:16:44.000000000 -0700
@@ -0,0 +1,85 @@
+#include <libxml/threads_cb.h>
+
+// External lock methods (callbacks)
+void (*xml_do_external_lock)(void* lock);
+void (*xml_do_external_unlock)(void* lock);
+
+// Recursive locks
+void (*xml_do_external_rlock)(void* rlock);
+void (*xml_do_external_runlock)(void* rlock);
+
+// Helper methods.
+int (*xml_get_thread_id)(void);
+
+void* mem_mutex_lock = NULL;
+void* thr_def_mutex_lock = NULL;
+void* catalog_mutex_rlock = NULL;
+
+
+
+
+// This should be implemented by libxml.
+
+int xmlGetThreadId(void) {
+   if (xml_get_thread_id) {
+      return (*xml_get_thread_id)();
+   }
+   return 0;
+}
+
+int xmlIsMainThread() {
+   // TODO:  Implement
+   return 1;
+}
+
+void xmlInitThreads(void) {
+   // Initialize hash table for global state?
+}
+void xmlCleanupThreads(void) {
+   // Destruct hash table for global state??
+}
+
+
+xmlGlobalStatePtr xmlGetGlobalState(void) {
+   // Maybe grab a lock, get thread ID, then use thread-id has a hash
+   // to get the allocated state???
+   //TODO:  Implement
+   return NULL;
+}
+
+
+void xmlMemMutexLock() {
+   if (mem_mutex_lock) {
+      xml_do_external_lock(mem_mutex_lock);
+   }
+}
+
+void xmlMemMutexUnlock() {
+   if (mem_mutex_lock) {
+      xml_do_external_unlock(mem_mutex_lock);
+   }
+}
+
+void xmlThreadDefMutexLock() {
+   if (thr_def_mutex_lock) {
+      xml_do_external_lock(thr_def_mutex_lock);
+   }
+}
+
+void xmlThreadDefMutexUnlock() {
+   if (thr_def_mutex_lock) {
+      xml_do_external_unlock(thr_def_mutex_lock);
+   }
+}
+
+void xmlCatalogMutexLock() {
+   if (catalog_mutex_rlock) {
+      xml_do_external_rlock(catalog_mutex_rlock);
+   }
+}
+
+void xmlCatalogMutexUnlock() {
+   if (catalog_mutex_rlock) {
+      xml_do_external_runlock(catalog_mutex_rlock);
+   }
+}
diff -urN libxml2-2.6.11/xmlmemory.c libxml2-2.6.11.ben/xmlmemory.c
--- libxml2-2.6.11/xmlmemory.c  2004-07-02 04:49:13.000000000 -0700
+++ libxml2-2.6.11.ben/xmlmemory.c      2004-08-20 10:58:21.000000000 -0700
@@ -46,12 +46,12 @@
 #include <libxml/globals.h>    /* must come before xmlmemory.h */
 #include <libxml/xmlmemory.h>
 #include <libxml/xmlerror.h>
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 
 static int xmlMemInitialized = 0;
 static unsigned long  debugMemSize = 0;
 static unsigned long  debugMaxMemSize = 0;
-static xmlMutexPtr xmlMemMutex = NULL;
+//static xmlMutexPtr xmlMemMutex = NULL;
 
 void xmlMallocBreakpoint(void);
 
@@ -183,14 +183,14 @@
     p->mh_type = MALLOC_TYPE;
     p->mh_file = file;
     p->mh_line = line;
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock(); //xmlMutexLock(xmlMemMutex);
     p->mh_number = ++block;
     debugMemSize += size;
     if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST
     debugmem_list_add(p);
 #endif
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock(); //xmlMutexUnlock(xmlMemMutex);
     
 #ifdef DEBUG_MEMORY
     xmlGenericError(xmlGenericErrorContext,
@@ -250,14 +250,14 @@
     p->mh_type = MALLOC_ATOMIC_TYPE;
     p->mh_file = file;
     p->mh_line = line;
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock(); //xmlMutexLock(xmlMemMutex);
     p->mh_number = ++block;
     debugMemSize += size;
     if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST
     debugmem_list_add(p);
 #endif
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock(); //xmlMutexUnlock(xmlMemMutex);
 
 #ifdef DEBUG_MEMORY
     xmlGenericError(xmlGenericErrorContext,
@@ -327,7 +327,7 @@
         goto error;
     }
     p->mh_tag = ~MEMTAG;
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock(); //xmlMutexLock(xmlMemMutex);
     debugMemSize -= p->mh_size;
 #ifdef DEBUG_MEMORY
     oldsize = p->mh_size;
@@ -335,7 +335,7 @@
 #ifdef MEM_LIST
     debugmem_list_delete(p);
 #endif
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock(); //xmlMutexLock(xmlMemMutex);
     
     p = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
     if (!p) {
@@ -353,13 +353,13 @@
     p->mh_size = size;
     p->mh_file = file;
     p->mh_line = line;
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock();
     debugMemSize += size;
     if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST
     debugmem_list_add(p);
 #endif
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock();
 
     TEST_POINT
 
@@ -426,7 +426,7 @@
     }
     p->mh_tag = ~MEMTAG;
     memset(target, -1, p->mh_size);
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock();
     debugMemSize -= p->mh_size;
 #ifdef DEBUG_MEMORY
     size = p->mh_size;
@@ -434,7 +434,7 @@
 #ifdef MEM_LIST
     debugmem_list_delete(p);
 #endif
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock();
 
     free(p);
 
@@ -484,14 +484,14 @@
     p->mh_type = STRDUP_TYPE;
     p->mh_file = file;
     p->mh_line = line;
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock();
     p->mh_number = ++block;
     debugMemSize += size;
     if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
 #ifdef MEM_LIST
     debugmem_list_add(p);
 #endif
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock();
     
     s = (char *) HDR_2_CLIENT(p);
     
@@ -632,7 +632,7 @@
             debugMemSize, debugMaxMemSize);
     fprintf(fp,"BLOCK  NUMBER   SIZE  TYPE\n");
     idx = 0;
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock();
     p = memlist;
     while (p) {
          fprintf(fp,"%-5u  %6lu %6lu ",idx++,p->mh_number,
@@ -645,7 +645,7 @@
            case REALLOC_ATOMIC_TYPE:fprintf(fp,"atomicrealloc() in ");break;
            default:
                fprintf(fp,"Unknow memory block, corruped maybe");
-               xmlMutexUnlock(xmlMemMutex);
+               xmlMemMutexUnlock();
                return;
         }
        if (p->mh_file != NULL) fprintf(fp,"%s(%d)", p->mh_file, p->mh_line);
@@ -660,7 +660,7 @@
         fprintf(fp,"\n");
         p = p->mh_next;
     }
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock();
 #else
     fprintf(fp,"Memory list not compiled (MEM_LIST not defined !)\n");
 #endif
@@ -735,7 +735,7 @@
        fprintf(fp,"      MEMORY ALLOCATED : %lu, MAX was %lu\n",
                debugMemSize, debugMaxMemSize);
 #ifdef MEM_LIST
-    xmlMutexLock(xmlMemMutex);
+    xmlMemMutexLock();
     if (nr > 0) {
        fprintf(fp,"NUMBER   SIZE  TYPE   WHERE\n");
        p = memlist;
@@ -759,7 +759,7 @@
            p = p->mh_next;
        }
     }
-    xmlMutexUnlock(xmlMemMutex);
+    xmlMemMutexUnlock();
 #endif /* MEM_LIST */    
 }
 
@@ -818,7 +818,7 @@
     */
      if (xmlMemInitialized) return(-1);
      xmlMemInitialized = 1;
-     xmlMemMutex = xmlNewMutex();
+     //xmlMemMutex = xmlNewMutex();
 
 #ifdef HAVE_STDLIB_H
      breakpoint = getenv("XML_MEM_BREAKPOINT");
@@ -854,8 +854,8 @@
     if (xmlMemInitialized == 0)
         return;
 
-    xmlFreeMutex(xmlMemMutex);
-    xmlMemMutex = NULL;
+    //xmlFreeMutex(xmlMemMutex);
+    //xmlMemMutex = NULL;
     xmlMemInitialized = 0;
 #ifdef DEBUG_MEMORY
      xmlGenericError(xmlGenericErrorContext,
diff -urN libxml2-2.6.11/xpath.c libxml2-2.6.11.ben/xpath.c
--- libxml2-2.6.11/xpath.c      2004-06-02 09:05:40.000000000 -0700
+++ libxml2-2.6.11.ben/xpath.c  2004-08-20 10:35:09.000000000 -0700
@@ -49,7 +49,7 @@
 #include <libxml/debugXML.h>
 #endif
 #include <libxml/xmlerror.h>
-#include <libxml/threads.h>
+#include <libxml/threads_cb.h>
 #include <libxml/globals.h>
 
 #define TODO                                                           \


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]