knoaman 2004/01/08 20:39:56 Modified: c/src/xercesc/framework XMLValidator.cpp c/src/xercesc/internal XMLScanner.cpp c/src/xercesc/util XMLException.cpp PlatformUtils.hpp PlatformUtils.cpp Log: Use a global static mutex for locking when creating local static mutexes instead of compareAndSwap. Revision Changes Path 1.7 +23 -22 xml-xerces/c/src/xercesc/framework/XMLValidator.cpp Index: XMLValidator.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/framework/XMLValidator.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XMLValidator.cpp 24 Dec 2003 15:24:13 -0000 1.6 +++ XMLValidator.cpp 9 Jan 2004 04:39:56 -0000 1.7 @@ -56,6 +56,9 @@ /** * $Log$ + * Revision 1.7 2004/01/09 04:39:56 knoaman + * Use a global static mutex for locking when creating local static mutexes instead of compareAndSwap. + * * Revision 1.6 2003/12/24 15:24:13 cargilld * More updates to memory management so that the static memory manager. * @@ -158,14 +161,11 @@ { if (!sMsgMutex) { - XMLMutex* tmpMutex = new XMLMutex; - if (XMLPlatformUtils::compareAndSwap((void**)&sMsgMutex, tmpMutex, 0)) - { - // Someone beat us to it, so let's clean up ours - delete tmpMutex; - } - else + XMLMutexLock lockInit(XMLPlatformUtils::fgAtomicMutex); + + if (!sMsgMutex) { + sMsgMutex = new XMLMutex; validatorMutexCleanup.registerCleanup(XMLValidator::reinitMsgMutex); } } @@ -175,22 +175,23 @@ static XMLMsgLoader& getMsgLoader() { - - // Lock the mutex - XMLMutexLock lockInit(&gValidatorMutex()); - if (!sMsgLoader) - { - sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgValidityDomain); - if (!sMsgLoader) - XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); - - // - // Register this XMLMsgLoader for cleanup at Termination. - // - msgLoaderCleanup.registerCleanup(XMLValidator::reinitMsgLoader); - - } + { + // Lock the mutex + XMLMutexLock lockInit(&gValidatorMutex()); + + if (!sMsgLoader) + { + sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgValidityDomain); + if (!sMsgLoader) + XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); + + // + // Register this XMLMsgLoader for cleanup at Termination. + // + msgLoaderCleanup.registerCleanup(XMLValidator::reinitMsgLoader); + } + } return *sMsgLoader; } 1.60 +15 -21 xml-xerces/c/src/xercesc/internal/XMLScanner.cpp Index: XMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.cpp,v retrieving revision 1.59 retrieving revision 1.60 diff -u -r1.59 -r1.60 --- XMLScanner.cpp 31 Dec 2003 15:40:00 -0000 1.59 +++ XMLScanner.cpp 9 Jan 2004 04:39:56 -0000 1.60 @@ -122,23 +122,14 @@ // static XMLMutex& gScannerMutex() { - - if (!sScannerMutex) + if (!sRegistered) { - XMLMutex* tmpMutex = new XMLMutex; - if (XMLPlatformUtils::compareAndSwap((void**)&sScannerMutex, tmpMutex, 0)) - { - // Someone beat us to it, so let's clean up ours - delete tmpMutex; - } - - // Now lock it and try to register it - XMLMutexLock lock(sScannerMutex); + XMLMutexLock lockInit(XMLPlatformUtils::fgAtomicMutex); - // If we got here first, then register it and set the registered flag if (!sRegistered) { - scannerMutexCleanup.registerCleanup(XMLScanner::reinitScannerMutex); + sScannerMutex = new XMLMutex; + scannerMutexCleanup.registerCleanup(XMLScanner::reinitScannerMutex); sRegistered = true; } } @@ -147,17 +138,20 @@ static XMLMsgLoader& gScannerMsgLoader() { - XMLMutexLock lockInit(&gScannerMutex()); - - // If we haven't loaded our message yet, then do that if (!gMsgLoader) { - gMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain); + XMLMutexLock lockInit(&gScannerMutex()); + + // If we haven't loaded our message yet, then do that if (!gMsgLoader) - XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); + { + gMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgXMLErrDomain); + if (!gMsgLoader) + XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); - // Register this object to be cleaned up at termination - cleanupMsgLoader.registerCleanup(XMLScanner::reinitMsgLoader); + // Register this object to be cleaned up at termination + cleanupMsgLoader.registerCleanup(XMLScanner::reinitMsgLoader); + } } return *gMsgLoader; 1.11 +28 -30 xml-xerces/c/src/xercesc/util/XMLException.cpp Index: XMLException.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/XMLException.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- XMLException.cpp 29 Dec 2003 22:52:36 -0000 1.10 +++ XMLException.cpp 9 Jan 2004 04:39:56 -0000 1.11 @@ -95,7 +95,7 @@ // --------------------------------------------------------------------------- static XMLMsgLoader* sMsgLoader = 0; static XMLRegisterCleanup msgLoaderCleanup; - +static bool sScannerMutexRegistered = false; static XMLMutex* sMsgMutex = 0; static XMLRegisterCleanup msgMutexCleanup; @@ -109,21 +109,16 @@ // static XMLMutex& gMsgMutex() { - - if (!sMsgMutex) + if (!sScannerMutexRegistered) { - XMLMutex* tmpMutex = new XMLMutex; - if (XMLPlatformUtils::compareAndSwap((void**)&sMsgMutex, tmpMutex, 0)) - { - // Some other thread beat us to it, so let's clean up ours. - delete tmpMutex; - } - else + XMLMutexLock lockInit(XMLPlatformUtils::fgAtomicMutex); + + if (!sScannerMutexRegistered) { - // This is the real mutex. Register it for cleanup at Termination. - msgMutexCleanup.registerCleanup(XMLException::reinitMsgMutex); + sMsgMutex = new XMLMutex; + msgMutexCleanup.registerCleanup(XMLException::reinitMsgMutex); + sScannerMutexRegistered = true; } - } return *sMsgMutex; @@ -135,21 +130,23 @@ // static XMLMsgLoader& gGetMsgLoader() { - - // Lock the message loader mutex and load the text - XMLMutexLock lockInit(&gMsgMutex()); - - // Fault it in on first request if (!sMsgLoader) { - sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain); - if (!sMsgLoader) - XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); + // Lock the message loader mutex and load the text + XMLMutexLock lockInit(&gMsgMutex()); - // - // Register this XMLMsgLoader for cleanup at Termination. - // - msgLoaderCleanup.registerCleanup(XMLException::reinitMsgLoader); + // Fault it in on first request + if (!sMsgLoader) + { + sMsgLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain); + if (!sMsgLoader) + XMLPlatformUtils::panic(PanicHandler::Panic_CantLoadMsgDomain); + + // + // Register this XMLMsgLoader for cleanup at Termination. + // + msgLoaderCleanup.registerCleanup(XMLException::reinitMsgLoader); + } } // We got it, so return it @@ -353,8 +350,9 @@ // ----------------------------------------------------------------------- void XMLException::reinitMsgMutex() { - delete sMsgMutex; - sMsgMutex = 0; + delete sMsgMutex; + sMsgMutex = 0; + sScannerMutexRegistered = false; } // ----------------------------------------------------------------------- @@ -362,8 +360,8 @@ // ----------------------------------------------------------------------- void XMLException::reinitMsgLoader() { - delete sMsgLoader; - sMsgLoader = 0; + delete sMsgLoader; + sMsgLoader = 0; } XERCES_CPP_NAMESPACE_END 1.23 +4 -1 xml-xerces/c/src/xercesc/util/PlatformUtils.hpp Index: PlatformUtils.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/PlatformUtils.hpp,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- PlatformUtils.hpp 24 Dec 2003 15:24:13 -0000 1.22 +++ PlatformUtils.hpp 9 Jan 2004 04:39:56 -0000 1.23 @@ -71,6 +71,7 @@ class XMLNetAccessor; class XMLTransService; class MemoryManager; +class XMLMutex; // // For internal use only @@ -161,6 +162,8 @@ * there is no reason, nor facility, to override it. */ static MemoryManager* fgArrayMemoryManager; + + static XMLMutex* fgAtomicMutex; //@} 1.17 +9 -0 xml-xerces/c/src/xercesc/util/PlatformUtils.cpp Index: PlatformUtils.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/util/PlatformUtils.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- PlatformUtils.cpp 17 Dec 2003 00:18:35 -0000 1.16 +++ PlatformUtils.cpp 9 Jan 2004 04:39:56 -0000 1.17 @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.17 2004/01/09 04:39:56 knoaman + * Use a global static mutex for locking when creating local static mutexes instead of compareAndSwap. + * * Revision 1.16 2003/12/17 00:18:35 cargilld * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data. * @@ -230,6 +233,7 @@ MemoryManagerArrayImpl gArrayMemoryManager; MemoryManager* XMLPlatformUtils::fgArrayMemoryManager = &gArrayMemoryManager; bool XMLPlatformUtils::fgMemMgrAdopted = true; +XMLMutex* XMLPlatformUtils::fgAtomicMutex = 0; // --------------------------------------------------------------------------- // XMLPlatformUtils: Init/term methods @@ -302,6 +306,7 @@ // Create the mutex for the static data cleanup list gXMLCleanupListMutex = new XMLMutex; + fgAtomicMutex = new XMLMutex; // // Ask the per-platform code to make the desired transcoding service for @@ -385,6 +390,10 @@ // Clean up the sync mutex delete gSyncMutex; gSyncMutex = 0; + + // Clean up mutex + delete fgAtomicMutex; + fgAtomicMutex = 0; // Clean up statically allocated, lazily cleaned data in each class // that has registered for it.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]