knoaman 2004/01/12 13:30:56 Modified: c/src/xercesc/dom/impl DOMNodeImpl.cpp Log: Use a global static mutex for locking when creating local static mutexes instead of compareAndSwap Revision Changes Path 1.27 +24 -9 xml-xerces/c/src/xercesc/dom/impl/DOMNodeImpl.cpp Index: DOMNodeImpl.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/dom/impl/DOMNodeImpl.cpp,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- DOMNodeImpl.cpp 23 Oct 2003 21:19:58 -0000 1.26 +++ DOMNodeImpl.cpp 12 Jan 2004 21:30:56 -0000 1.27 @@ -98,11 +98,16 @@ // ----------------------------------------------------------------------- // Reset the singleton gEmptyNodeList // ----------------------------------------------------------------------- -static DOMNodeListImpl *gEmptyNodeList; // make a singleton empty node list +static DOMNodeListImpl *gEmptyNodeList = 0; // make a singleton empty node list +static XMLMutex* gEmptyNodeListMutex = 0; + static void reinitEmptyNodeList() { delete gEmptyNodeList; gEmptyNodeList = 0; + + delete gEmptyNodeListMutex; + gEmptyNodeListMutex = 0; } // ----------------------------------------------------------------------- @@ -149,21 +154,31 @@ DOMNodeList *DOMNodeImpl::getChildNodes() const { + static XMLRegisterCleanup emptyNodeListCleanup; - if (gEmptyNodeList == 0) + if (!gEmptyNodeList) { - DOMNodeList *t = new DOMNodeListImpl(0); - if (XMLPlatformUtils::compareAndSwap((void **)&gEmptyNodeList, t, 0) != 0) + if (!gEmptyNodeListMutex) { - delete t; + XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); + + if (!gEmptyNodeListMutex) + gEmptyNodeListMutex = new XMLMutex; } - else + + // Use a faux scope to synchronize while we do this { - emptyNodeListCleanup.registerCleanup(reinitEmptyNodeList); - } + XMLMutexLock lock(gEmptyNodeListMutex); + if (!gEmptyNodeList) + { + gEmptyNodeList = new DOMNodeListImpl(0); + emptyNodeListCleanup.registerCleanup(reinitEmptyNodeList); + } + } } + return (DOMNodeList *)gEmptyNodeList; };
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]