Author: borisk
Date: Sat Jul 12 23:19:46 2008
New Revision: 676265

URL: http://svn.apache.org/viewvc?rev=676265&view=rev
Log:
Use mutex to synchronize access to global document. Fixes XERCESC-1652.

Modified:
    xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentTypeImpl.cpp
    xerces/c/trunk/src/xercesc/util/XMLInitializer.hpp

Modified: xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentTypeImpl.cpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentTypeImpl.cpp?rev=676265&r1=676264&r2=676265&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentTypeImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/dom/impl/DOMDocumentTypeImpl.cpp Sat Jul 12 
23:19:46 2008
@@ -36,10 +36,13 @@
 
 XERCES_CPP_NAMESPACE_BEGIN
 
-static DOMDocument*       sDocument = 0;
+static DOMDocument* sDocument = 0;
+static XMLMutex*    sDocumentMutex = 0;
 
 void XMLInitializer::initializeDOMDocumentTypeImpl()
 {
+    sDocumentMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager);
+
     static const XMLCh gCoreStr[] = { chLatin_C, chLatin_o, chLatin_r, 
chLatin_e, chNull };
     DOMImplementation* impl =  
DOMImplementationRegistry::getDOMImplementation(gCoreStr);
     sDocument = impl->createDocument(); // document type object (DTD).
@@ -49,6 +52,9 @@
 {
     sDocument->release();
     sDocument = 0;
+
+    delete sDocumentMutex;
+    sDocumentMutex = 0;
 }
 
 DOMDocumentTypeImpl::DOMDocumentTypeImpl(DOMDocument *ownerDoc,
@@ -66,13 +72,16 @@
     fIntSubsetReading(false),
     fIsCreatedFromHeap(heap)
 {
-    if (ownerDoc) {
+    if (ownerDoc)
+    {
         fName = ((DOMDocumentImpl *)ownerDoc)->getPooledString(dtName);
         fEntities = new (ownerDoc) DOMNamedNodeMapImpl(this);
         fNotations= new (ownerDoc) DOMNamedNodeMapImpl(this);
         fElements = new (ownerDoc) DOMNamedNodeMapImpl(this);
     }
-    else {
+    else
+    {
+        XMLMutexLock lock(sDocumentMutex);
         DOMDocument* doc = sDocument;
         fName = ((DOMDocumentImpl *)doc)->getPooledString(dtName);
         fEntities = new (doc) DOMNamedNodeMapImpl(this);
@@ -135,7 +144,8 @@
             XMLPlatformUtils::fgMemoryManager->deallocate(newName);//delete[] 
newName;
     }
 
-    if (ownerDoc) {
+    if (ownerDoc)
+    {
         DOMDocumentImpl *docImpl = (DOMDocumentImpl *)ownerDoc;
         fPublicId = docImpl->cloneString(pubId);
         fSystemId = docImpl->cloneString(sysId);
@@ -144,7 +154,9 @@
         fNotations= new (ownerDoc) DOMNamedNodeMapImpl(this);
         fElements = new (ownerDoc) DOMNamedNodeMapImpl(this);
     }
-    else {
+    else
+    {
+        XMLMutexLock lock(sDocumentMutex);
         DOMDocument* doc = sDocument;
         fPublicId = ((DOMDocumentImpl*) doc)->cloneString(pubId);
         fSystemId = ((DOMDocumentImpl*) doc)->cloneString(sysId);
@@ -197,7 +209,10 @@
     if (castToNodeImpl(this)->getOwnerDocument())
         newNode = new (castToNodeImpl(this)->getOwnerDocument(), 
DOMMemoryManager::DOCUMENT_TYPE_OBJECT) DOMDocumentTypeImpl(*this, false, deep);
     else
+    {
+        XMLMutexLock lock(sDocumentMutex);
         newNode = new (sDocument, DOMMemoryManager::DOCUMENT_TYPE_OBJECT) 
DOMDocumentTypeImpl(*this, false, deep);
+    }
 
     fNode.callUserDataHandlers(DOMUserDataHandler::NODE_CLONED, this, newNode);
     return newNode;
@@ -324,6 +339,7 @@
     if ((DOMDocumentImpl *)castToNodeImpl(this)->getOwnerDocument())
         fPublicId = ((DOMDocumentImpl 
*)castToNodeImpl(this)->getOwnerDocument())->cloneString(value);
     else {
+        XMLMutexLock lock(sDocumentMutex);
         fPublicId = ((DOMDocumentImpl *)sDocument)->cloneString(value);
     }
 }
@@ -333,6 +349,7 @@
     if ((DOMDocumentImpl *)castToNodeImpl(this)->getOwnerDocument())
         fSystemId = ((DOMDocumentImpl 
*)castToNodeImpl(this)->getOwnerDocument())->cloneString(value);
     else {
+        XMLMutexLock lock(sDocumentMutex);
         fSystemId = ((DOMDocumentImpl *)sDocument)->cloneString(value);
     }
 }
@@ -342,6 +359,7 @@
     if ((DOMDocumentImpl *)castToNodeImpl(this)->getOwnerDocument())
         fInternalSubset = ((DOMDocumentImpl 
*)castToNodeImpl(this)->getOwnerDocument())->cloneString(value);
     else {
+        XMLMutexLock lock(sDocumentMutex);
         fInternalSubset = ((DOMDocumentImpl *)sDocument)->cloneString(value);
     }
 }

Modified: xerces/c/trunk/src/xercesc/util/XMLInitializer.hpp
URL: 
http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLInitializer.hpp?rev=676265&r1=676264&r2=676265&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLInitializer.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLInitializer.hpp Sat Jul 12 23:19:46 2008
@@ -67,6 +67,8 @@
     // Note: The name of each function should be in the form
     // initialize<class-name>.
     //
+    // Note: In some cases order of initialization is important.
+    //
 
     //
     // Initialize



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to