diff --git a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp index 5c5630e61d7e1d4cb905c32726989b728bdc9fe9..70e45f02113aa86f7708a7ae42e6b779939e25e3 100644 --- a/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp +++ b/Projects/Win32/VC6/xerces-all/XercesLib/XercesLib.dsp @@ -903,6 +903,10 @@ SOURCE=..\..\..\..\..\src\xercesc\util\XMLMsgLoader.hpp # End Source File # Begin Source File +SOURCE=..\..\..\..\..\src\xercesc\util\XMLMutexHolder.hpp +# End Source File +# Begin Source File + SOURCE=..\..\..\..\..\src\xercesc\util\XMLNetAccessor.hpp # End Source File # Begin Source File diff --git a/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj b/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj index c53e5252c498d9fd517eccae02e6767f6c9cfd06..c30f58370f3857c25c94c8bc44299bc41c3994a2 100644 --- a/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj +++ b/Projects/Win32/VC7.1/xerces-all/XercesLib/XercesLib.vcproj @@ -575,6 +575,9 @@ <File RelativePath="..\..\..\..\..\src\xercesc\util\XMLFloat.hpp"> </File> + <File + RelativePath="..\..\..\..\..\src\xercesc\util\XMLHolder.hpp"> + </File> <File RelativePath="..\..\..\..\..\src\xercesc\util\XMLIBM1047Transcoder.cpp"> </File> diff --git a/Projects/Win32/VC7/xerces-all/XercesLib/XercesLib.vcproj b/Projects/Win32/VC7/xerces-all/XercesLib/XercesLib.vcproj index 4a3e437ba458360549a3feefdaafae18c1d925bf..767471e47d2467b0c6fa0f342f1c49a716ed25f2 100644 --- a/Projects/Win32/VC7/xerces-all/XercesLib/XercesLib.vcproj +++ b/Projects/Win32/VC7/xerces-all/XercesLib/XercesLib.vcproj @@ -457,7 +457,7 @@ </File> <File RelativePath="..\..\..\..\..\src\xercesc\util\XMLInitializer.hpp"> - </File> + </File> <File RelativePath="..\..\..\..\..\src\xercesc\util\XMLInteger.hpp"> </File> @@ -467,6 +467,9 @@ <File RelativePath="..\..\..\..\..\src\xercesc\util\XMLMsgLoader.hpp"> </File> + <File + RelativePath="..\..\..\..\..\src\xercesc\util\XMLMutexHolder.hpp"> + </File> <File RelativePath="..\..\..\..\..\src\xercesc\util\XMLNetAccessor.hpp"> </File> @@ -1369,16 +1372,16 @@ RelativePath="..\..\..\..\..\src\xercesc\parsers\DOMBuilderImpl.hpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLReaderImpl.cpp"> + RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLFilterImpl.cpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLReaderImpl.hpp"> + RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLFilterImpl.hpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLFilterImpl.cpp"> + RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLReaderImpl.cpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLFilterImpl.hpp"> + RelativePath="..\..\..\..\..\src\xercesc\parsers\SAX2XMLReaderImpl.hpp"> </File> <File RelativePath="..\..\..\..\..\src\xercesc\parsers\SAXParser.cpp"> @@ -1976,10 +1979,10 @@ RelativePath="..\..\..\..\..\src\xercesc\sax2\DefaultHandler.hpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\sax2\SAX2XMLReader.hpp"> + RelativePath="..\..\..\..\..\src\xercesc\sax2\SAX2XMLFilter.hpp"> </File> <File - RelativePath="..\..\..\..\..\src\xercesc\sax2\SAX2XMLFilter.hpp"> + RelativePath="..\..\..\..\..\src\xercesc\sax2\SAX2XMLReader.hpp"> </File> <File RelativePath="..\..\..\..\..\src\xercesc\sax2\XMLReaderFactory.hpp"> diff --git a/src/xercesc/dom/deprecated/DOMString.cpp b/src/xercesc/dom/deprecated/DOMString.cpp index 0dde90de56f1aa858bfbb792479644596615abaa..cf62f32e4c2bfe0dd6aa8efc42415661d65350d1 100644 --- a/src/xercesc/dom/deprecated/DOMString.cpp +++ b/src/xercesc/dom/deprecated/DOMString.cpp @@ -92,7 +92,7 @@ XMLMutex& DOMStringHandle::getMutex() { if (!DOMStringHandleMutex) { - XMLMutex* tmpMutex = new XMLMutex; + XMLMutex* tmpMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); if (XMLPlatformUtils::compareAndSwap((void**)&DOMStringHandleMutex, tmpMutex, 0)) { // Someone beat us to it, so let's clean up ours diff --git a/src/xercesc/dom/impl/DOMImplementationImpl.cpp b/src/xercesc/dom/impl/DOMImplementationImpl.cpp index 85201ea7f6618eac38c11a698c16af11fda7b4cb..9d3acddd7e3f1a7bbe2e603d3fe2ab1053cfcd7a 100644 --- a/src/xercesc/dom/impl/DOMImplementationImpl.cpp +++ b/src/xercesc/dom/impl/DOMImplementationImpl.cpp @@ -91,7 +91,7 @@ static XMLMutex& getMutex4DOM() // If we got here first, then register it and set the registered flag if (!sMutex4DOM) { - sMutex4DOM = new XMLMutex; + sMutex4DOM = new XMLMutex(XMLPlatformUtils::fgMemoryManager); mutex4DOMCleanup.registerCleanup(reinitMutex4DOM); } } diff --git a/src/xercesc/dom/impl/DOMImplementationRegistry.cpp b/src/xercesc/dom/impl/DOMImplementationRegistry.cpp index 12cafc4096cc2b443285328a8446581c0706d40b..40af32a1e81fca63dd9385462f705dbca6a78c72 100644 --- a/src/xercesc/dom/impl/DOMImplementationRegistry.cpp +++ b/src/xercesc/dom/impl/DOMImplementationRegistry.cpp @@ -90,7 +90,7 @@ XMLMutex& getDOMImplSrcVectorMutex() if (!gDOMImplSrcVectorMutex) { - gDOMImplSrcVectorMutex = new XMLMutex; + gDOMImplSrcVectorMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); cleanupDOMImplSrcVectorMutex.registerCleanup(reinitDOMImplSrcVectorMutex); } } @@ -101,7 +101,7 @@ XMLMutex& getDOMImplSrcVectorMutex() void XMLInitializer::initializeDOMImplementationRegistry() { // mutex - gDOMImplSrcVectorMutex = new XMLMutex; + gDOMImplSrcVectorMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); if (gDOMImplSrcVectorMutex) { cleanupDOMImplSrcVectorMutex.registerCleanup(reinitDOMImplSrcVectorMutex); } diff --git a/src/xercesc/dom/impl/DOMNodeImpl.cpp b/src/xercesc/dom/impl/DOMNodeImpl.cpp index 783ee6089764cf5cdf8240abd58daf6cc70aa845..344c13402f13ad4eed679eade137e633e162af81 100644 --- a/src/xercesc/dom/impl/DOMNodeImpl.cpp +++ b/src/xercesc/dom/impl/DOMNodeImpl.cpp @@ -134,7 +134,7 @@ DOMNodeList *DOMNodeImpl::getChildNodes() const { XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); if (!gEmptyNodeListMutex) - gEmptyNodeListMutex = new XMLMutex; + gEmptyNodeListMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); } // Use a faux scope to synchronize while we do this diff --git a/src/xercesc/dom/impl/DOMNormalizer.cpp b/src/xercesc/dom/impl/DOMNormalizer.cpp index 874ec56c650d58ab1d2f5dae89ac202f18452c8d..4dfe637e637680b9611c52d7fbed7b6e73d7ea83 100644 --- a/src/xercesc/dom/impl/DOMNormalizer.cpp +++ b/src/xercesc/dom/impl/DOMNormalizer.cpp @@ -86,7 +86,7 @@ static XMLMutex& gNormalizerMutex() // If we got here first, then register it and set the registered flag if (!sRegistered) { - sNormalizerMutex = new XMLMutex; + sNormalizerMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); normalizerMutexCleanup.registerCleanup(DOMNormalizer::reinitNormalizerMutex); sRegistered = true; } diff --git a/src/xercesc/framework/XMLValidator.cpp b/src/xercesc/framework/XMLValidator.cpp index b897babc69c5efaba0e397c549f96e2bb8d0e582..f3f3588cc0c24a031f8904d0f318e836afb595b5 100644 --- a/src/xercesc/framework/XMLValidator.cpp +++ b/src/xercesc/framework/XMLValidator.cpp @@ -132,7 +132,7 @@ static XMLMutex& gValidatorMutex() if (!sMsgMutex) { - sMsgMutex = new XMLMutex; + sMsgMutex = new (XMLPlatformUtils::fgMemoryManager) XMLMutex(XMLPlatformUtils::fgMemoryManager); validatorMutexCleanup.registerCleanup(XMLValidator::reinitMsgMutex); } } diff --git a/src/xercesc/framework/psvi/XSValue.cpp b/src/xercesc/framework/psvi/XSValue.cpp index 6fcd78524c407cf0b7b5a564357e4258e9c26662..db8b849b23f6a6c9fdf3fea4c8cdddfa3231116d 100644 --- a/src/xercesc/framework/psvi/XSValue.cpp +++ b/src/xercesc/framework/psvi/XSValue.cpp @@ -234,7 +234,7 @@ static XMLMutex& gXSValueMutex() if (!sXSValueMutext) { - sXSValueMutext = new XMLMutex; + sXSValueMutext = new (XMLPlatformUtils::fgMemoryManager) XMLMutex(XMLPlatformUtils::fgMemoryManager); XSValueRegExCleanup.registerCleanup(XSValue::reinitMutex); } } diff --git a/src/xercesc/internal/XMLScanner.cpp b/src/xercesc/internal/XMLScanner.cpp index 19e0c268effecb9ce75a3914768d4bfe4dcfb16d..f15f2dcb851c6d11d5e98e467dec9075f76727ed 100644 --- a/src/xercesc/internal/XMLScanner.cpp +++ b/src/xercesc/internal/XMLScanner.cpp @@ -89,7 +89,7 @@ static XMLMutex& gScannerMutex() if (!sRegistered) { - sScannerMutex = new XMLMutex; + sScannerMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); scannerMutexCleanup.registerCleanup(XMLScanner::reinitScannerMutex); sRegistered = true; } @@ -127,7 +127,7 @@ void XMLInitializer::initializeScannerMsgLoader() cleanupMsgLoader.registerCleanup(XMLScanner::reinitMsgLoader); } - sScannerMutex = new XMLMutex; + sScannerMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); if (sScannerMutex) { scannerMutexCleanup.registerCleanup(XMLScanner::reinitScannerMutex); sRegistered = true; diff --git a/src/xercesc/util/EncodingValidator.cpp b/src/xercesc/util/EncodingValidator.cpp index 42da91315573b867fb960307bf6ee88fb9d821d3..1388eba292869bcda695e9aac8706980bb688c9f 100644 --- a/src/xercesc/util/EncodingValidator.cpp +++ b/src/xercesc/util/EncodingValidator.cpp @@ -78,7 +78,7 @@ static XMLMutex& getEncValMutex() // If we got here first, then register it and set the registered flag if (!sEncValMutex) { - sEncValMutex = new XMLMutex; + sEncValMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); encValRegistryCleanup.registerCleanup(reinitEncValMutex); } } diff --git a/src/xercesc/util/Makefile.in b/src/xercesc/util/Makefile.in index 9cf57459ea8db5db6dc0fc899c8ba0fcb6bb3f26..1eb485127d0cdd4ced56c382f250bc3e7480577e 100644 --- a/src/xercesc/util/Makefile.in +++ b/src/xercesc/util/Makefile.in @@ -541,6 +541,7 @@ UTIL_CPP_PUBHEADERS = \ XMLInitializer.hpp \ XMLInteger.hpp \ XMLMsgLoader.hpp \ + XMLMutexHolder.hpp \ XMLNetAccessor.hpp \ XMLNumber.hpp \ XMLRegisterCleanup.hpp \ @@ -581,6 +582,7 @@ C_FILES = \ ValueStackOf.c \ ValueVectorOf.c \ XMLDeleterFor.c \ + XMLMutexHolder.c \ LogicalPath.c UTIL_CPP_OBJECTS = \ diff --git a/src/xercesc/util/Mutexes.cpp b/src/xercesc/util/Mutexes.cpp index 02ed49b5c9b437dc1169e0aa8bf203d620da3919..8a8e8a0082f9fa3494dfc91f6037e6254cbe065e 100644 --- a/src/xercesc/util/Mutexes.cpp +++ b/src/xercesc/util/Mutexes.cpp @@ -59,12 +59,12 @@ XERCES_CPP_NAMESPACE_BEGIN // --------------------------------------------------------------------------- // XMLMutex: Constructors and Destructor // --------------------------------------------------------------------------- -XMLMutex::XMLMutex() : +XMLMutex::XMLMutex(MemoryManager* const manager) : fHandle(0) { // Ask the per-platform driver to make us a mutex - fHandle = XMLPlatformUtils::makeMutex(); + fHandle = XMLPlatformUtils::makeMutex(manager); } diff --git a/src/xercesc/util/Mutexes.hpp b/src/xercesc/util/Mutexes.hpp index 7bca56ca3b73b806162c85f6a563c44960f9c376..896998da9f9bb03b442107f2efa16dbfab663189 100644 --- a/src/xercesc/util/Mutexes.hpp +++ b/src/xercesc/util/Mutexes.hpp @@ -55,6 +55,7 @@ #define MUTEXES_HPP #include <xercesc/util/XMemory.hpp> +#include <xercesc/util/PlatformUtils.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -64,7 +65,7 @@ public : // ----------------------------------------------------------------------- // Constructors and Destructor // ----------------------------------------------------------------------- - XMLMutex(); + XMLMutex(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); ~XMLMutex(); diff --git a/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp b/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp index 36ca0801cec383157c7a0ffe3cf8cd8a2632737e..7e2bfd766b1573c0958fc82c6743cf910e87c26c 100644 --- a/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp +++ b/src/xercesc/util/NetAccessors/WinSock/BinHTTPURLInputStream.cpp @@ -276,7 +276,7 @@ BinHTTPURLInputStream::BinHTTPURLInputStream(const XMLURL& urlSource, const XMLN { if (!fInitMutex) { - XMLMutex* tmpMutex = new XMLMutex(); + XMLMutex* tmpMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); if (XMLPlatformUtils::compareAndSwap((void**)&fInitMutex, tmpMutex, 0)) { // Someone beat us to it, so let's clean up ours diff --git a/src/xercesc/util/PlatformUtils.cpp b/src/xercesc/util/PlatformUtils.cpp index 89a10da2068db3f9d848bae8a43b86d32c59b2ce..6b2d51e4cee6ef038567ad93f7ac22238a2d3389 100644 --- a/src/xercesc/util/PlatformUtils.cpp +++ b/src/xercesc/util/PlatformUtils.cpp @@ -270,11 +270,11 @@ void XMLPlatformUtils::Initialize(const char* const locale platformInit(); // Create the local sync mutex - gSyncMutex = new XMLMutex; + gSyncMutex = new XMLMutex(fgMemoryManager); // Create the mutex for the static data cleanup list - gXMLCleanupListMutex = new XMLMutex; - fgAtomicMutex = new XMLMutex; + gXMLCleanupListMutex = new XMLMutex(fgMemoryManager); + fgAtomicMutex = new XMLMutex(fgMemoryManager); // // Ask the per-platform code to make the desired transcoding service for diff --git a/src/xercesc/util/PlatformUtils.hpp b/src/xercesc/util/PlatformUtils.hpp index 0435485e2b8cffa068115c2ed91e3e1d9f6b6f9e..f113480926842ac3c428e999e87fb3ebdad98ea9 100644 --- a/src/xercesc/util/PlatformUtils.hpp +++ b/src/xercesc/util/PlatformUtils.hpp @@ -537,8 +537,10 @@ public : * the actual content of the passed mutex handle is. The returned * handle pointer will be eventually passed to closeMutex() which is * also implemented by the platform driver. + * + * @param manager The MemoryManager to use to allocate objects */ - static void* makeMutex(); + static void* makeMutex(MemoryManager* manager = XMLPlatformUtils::fgMemoryManager); /** Unlocks a mutex * diff --git a/src/xercesc/util/Platforms/AIX/AIXPlatformUtils.cpp b/src/xercesc/util/Platforms/AIX/AIXPlatformUtils.cpp index 546c5f9a00e9937a578d822285f8797c64b9fcb5..66191640667d394a22a198bab2db1df59b30d182 100644 --- a/src/xercesc/util/Platforms/AIX/AIXPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/AIX/AIXPlatformUtils.cpp @@ -44,6 +44,7 @@ #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/PanicHandler.hpp> @@ -80,7 +81,7 @@ void XMLPlatformUtils::platformInit() XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -96,11 +97,11 @@ XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) { - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; } #else { - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; } #endif @@ -115,11 +116,11 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -361,64 +362,77 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // Mutex methods // ----------------------------------------------------------------------- #ifndef APP_NO_THREADS + +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle == NULL) return; - if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + + MutexHolderType* const holder = MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { - ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); + delete holder; + + ThrowXMLwithMemMgr( + XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotDestroy, + fgMemoryManager); } - if ( (pthread_mutex_t*)mtxHandle) - delete (pthread_mutex_t*) mtxHandle; + + delete holder; } void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle == NULL) return; - if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } - } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - if (mutex == NULL) - { - panic(PanicHandler::Panic_MutexErr); - } - pthread_mutexattr_t* attr = new pthread_mutexattr_t; + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + #if defined(XML_USE_DCE) - pthread_mutexattr_create(attr); - pthread_mutexattr_setkind_np(attr, MUTEX_RECURSIVE_NP); - if (pthread_mutex_init(mutex, *attr)) + pthread_mutexattr_create(&attr); + pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP); + if (pthread_mutex_init(&holder->fInstance, attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_delete(attr); + pthread_mutexattr_delete(&attr); #else - pthread_mutexattr_init(attr); + pthread_mutexattr_init(&attr); #if defined(XML_AIX43) - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); #else - pthread_mutexattr_setkind_np(attr, MUTEX_RECURSIVE_NP); + pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP); #endif - if (pthread_mutex_init(mutex, attr)) + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); + pthread_mutexattr_destroy(&attr); #endif - delete attr; - return (void*)(mutex); + + return holder; } void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle == NULL) return; - if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -426,20 +440,20 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) #else // #ifndef APP_NO_THREADS -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/BeOS/BeOSPlatformUtils.cpp b/src/xercesc/util/Platforms/BeOS/BeOSPlatformUtils.cpp index bd4139bc2eb6133f6d832ea5d9b26e9ce92b6e50..5ee517800fd4b8433369a18cc59d1de7a1e35478 100644 --- a/src/xercesc/util/Platforms/BeOS/BeOSPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/BeOS/BeOSPlatformUtils.cpp @@ -143,7 +143,7 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -162,12 +162,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -194,13 +194,13 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined (XML_USE_GNU_TRANSCODER) - return new IconvGNUTransService; + return new (fgMemoryManager) IconvGNUTransService; #else // Use native transcoding services. // same as -DXML_USE_NATIVE_TRANSCODER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -466,25 +466,30 @@ void XMLPlatformUtils::platformInit() // mutex creation that must be broken. if(!atomicOpsMutex) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex(); + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE_NP); - if (pthread_mutex_init(mutex, attr)) + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); - delete attr; - return (void*)(mutex); + pthread_mutexattr_destroy(&attr); + + return holder } @@ -492,12 +497,20 @@ void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { - ThrowXMLwithMemMgr(XMLPlatformUtilsException, - XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); + delete holder; + + ThrowXMLwithMemMgr( + XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotDestroy, + fgMemoryManager); } - delete (pthread_mutex_t*) mtxHandle; + + delete holder; } } @@ -506,7 +519,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -518,7 +531,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -563,20 +576,20 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/Cygwin/CygwinPlatformUtils.cpp b/src/xercesc/util/Platforms/Cygwin/CygwinPlatformUtils.cpp index 996cb79fc923d2ed140401b9f4859ba6025d6f5a..33a53e55d5954ee31e634914e12d3142d43a3138 100755 --- a/src/xercesc/util/Platforms/Cygwin/CygwinPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Cygwin/CygwinPlatformUtils.cpp @@ -49,6 +49,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -93,9 +94,9 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #elif defined (XML_USE_NETACCESSOR_LIBWWW) - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); #else return 0; #endif @@ -114,12 +115,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -146,15 +147,15 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined (XML_USE_GNU_TRANSCODER) - return new IconvGNUTransService; + return new (fgMemoryManager) IconvGNUTransService; #elif defined (XML_USE_CYGWIN_TRANSCODER) - return new CygwinTransService; + return new (fgMemoryManager) CygwinTransService; #else // Use native transcoding services. // same as -DXML_USE_NATIVE_TRANSCODER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -464,27 +465,33 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<CRITICAL_SECTION> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - CRITICAL_SECTION* newCS = new CRITICAL_SECTION; - ::InitializeCriticalSection(newCS); - return newCS; + MutexHolderType* const holder = new (manager) MutexHolderType; + + InitializeCriticalSection(&holder->fInstance); + + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { - ::DeleteCriticalSection((LPCRITICAL_SECTION)mtxHandle); - delete (CRITICAL_SECTION*)mtxHandle; + MutexHolderType* const holder = MutexHolderType::castTo(mtxHandle); + + ::DeleteCriticalSection(&holder->fInstance); + delete holder; } void XMLPlatformUtils::lockMutex(void* const mtxHandle) { - ::EnterCriticalSection((LPCRITICAL_SECTION)mtxHandle); + ::EnterCriticalSection(&MutexHolderType::castTo(mtxHandle)->fInstance); } void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { - ::LeaveCriticalSection((LPCRITICAL_SECTION)mtxHandle); + ::LeaveCriticalSection(&MutexHolderType::castTo(mtxHandle)->fInstance); } void* XMLPlatformUtils::compareAndSwap (void** toFill, @@ -522,20 +529,20 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp b/src/xercesc/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp index ee82b8d179a79a2550fda445b097e9f48abaa04b..64b05094d3845f10a4b447ee287cf81737231581 100644 --- a/src/xercesc/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/FreeBSD/FreeBSDPlatformUtils.cpp @@ -127,6 +127,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -164,7 +165,7 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -183,12 +184,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -215,11 +216,11 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #else // Use native transcoding services. // same as -DXML_USE_INMEM_MESSAGELOADER - return new IconvFBSDTransService; + return new (fgMemoryManager) IconvFBSDTransService; #endif } @@ -512,38 +513,48 @@ void XMLPlatformUtils::platformInit() // mutex creation that must be broken. if(!atomicOpsMutex) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex(); + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); - if (pthread_mutex_init(mutex, attr)) + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); - delete attr; - return (void*)(mutex); + pthread_mutexattr_destroy(&attr); + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } - delete (pthread_mutex_t*)mtxHandle; + delete holder; } } @@ -552,7 +563,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -564,7 +575,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -609,7 +620,7 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } diff --git a/src/xercesc/util/Platforms/HPUX/HPPlatformUtils.cpp b/src/xercesc/util/Platforms/HPUX/HPPlatformUtils.cpp index 7152dce0a98607dc00b8b87aa2e1cb088119bf2f..036c4a8519cc6eaba81023fafca365be43b7648f 100644 --- a/src/xercesc/util/Platforms/HPUX/HPPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/HPUX/HPPlatformUtils.cpp @@ -163,6 +163,7 @@ #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/Mutexes.hpp> #include <dl.h> #include <stdio.h> @@ -223,7 +224,7 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -242,12 +243,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -272,12 +273,12 @@ XMLTransService* XMLPlatformUtils::makeTransService() { #if defined (XML_USE_ICU_TRANSCODER) - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #else // Use native transcoding services. // same as -DXML_USE_INMEM_MESSAGELOADER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif @@ -541,6 +542,8 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // --------------------------------------------------------------------------- // XMLPlatformUtils: Platform init method // --------------------------------------------------------------------------- +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + static XMLMutex *atomicOpsMutex = 0; void XMLPlatformUtils::platformInit() @@ -552,48 +555,56 @@ void XMLPlatformUtils::platformInit() // mutex creation that must be broken. if(!atomicOpsMutex) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex(); - if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); } } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; #if defined(XML_USE_DCE) - pthread_mutexattr_create(attr); - pthread_mutexattr_setkind_np(attr, MUTEX_RECURSIVE_NP); - if (pthread_mutex_init(mutex, *attr)) + pthread_mutexattr_create(&attr); + pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP); + if (pthread_mutex_init(&holder->fInstance, attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_delete(attr); + pthread_mutexattr_delete(&attr); #else - pthread_mutexattr_init(attr); - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); - if (pthread_mutex_init(mutex, attr)) + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); + pthread_mutexattr_destroy(&attr); #endif - delete attr; - return (void*) mutex; + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { - pthread_mutex_t* mutex = (pthread_mutex_t *) mtxHandle; - if (mutex != NULL) + if (mtxHandle != NULL) { - if (pthread_mutex_destroy(mutex)) + MutexHolderType* const holder = MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) + { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); - delete mutex; + } + + delete holder; } } @@ -601,7 +612,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t *) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -612,7 +623,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t *) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -657,20 +668,20 @@ void XMLPlatformUtils::platformInit() { } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/IRIX/IRIXPlatformUtils.cpp b/src/xercesc/util/Platforms/IRIX/IRIXPlatformUtils.cpp index 6f3468e13f9b97c57d3f9d1b5827cd617b20d96f..c35a60d0b13dee63817db646ff7430ffa0691a5e 100644 --- a/src/xercesc/util/Platforms/IRIX/IRIXPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/IRIX/IRIXPlatformUtils.cpp @@ -158,6 +158,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -195,7 +196,7 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -212,12 +213,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -244,11 +245,11 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #else // Use native transcoding services. // same as -DXML_USE_INMEM_MESSAGELOADER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -535,9 +536,9 @@ void XMLPlatformUtils::platformInit() if(!atomicOpsMutex) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex(); + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } @@ -558,7 +559,7 @@ void XMLPlatformUtils::platformTerm() } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { if (arena) { usema_t* sema = usnewsema (arena, 1); @@ -627,9 +628,9 @@ void XMLPlatformUtils::platformInit() // mutex creation that must be broken. if(!atomicOpsMutex) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex(); + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } @@ -642,32 +643,41 @@ void XMLPlatformUtils::platformTerm() atomicOpsMutex = 0; } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); - if (pthread_mutex_init(mutex, attr)) + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); - delete attr; - return (void*)(mutex); + pthread_mutexattr_destroy(&attr); + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } - delete (pthread_mutex_t*) mtxHandle; + delete holder; } } @@ -676,7 +686,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -688,7 +698,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } diff --git a/src/xercesc/util/Platforms/Interix/InterixPlatformUtils.cpp b/src/xercesc/util/Platforms/Interix/InterixPlatformUtils.cpp index 5832b709d9fc780309fe98da7a0c64237b519d37..1aa31df576a5ef27ef0c9e97144074e0b487e576 100644 --- a/src/xercesc/util/Platforms/Interix/InterixPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Interix/InterixPlatformUtils.cpp @@ -54,6 +54,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -94,7 +95,7 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -113,12 +114,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -145,13 +146,13 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined (XML_USE_GNU_TRANSCODER) - return new IconvGNUTransService; + return new (fgMemoryManager) IconvGNUTransService; #else // Use native transcoding services. // same as -DXML_USE_NATIVE_TRANSCODER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -417,38 +418,47 @@ void XMLPlatformUtils::platformInit() // mutex creation that must be broken. if ( atomicOpsMutex == 0 ) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex; + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); - if (pthread_mutex_init(mutex, attr)) + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); - delete attr; - return (void*)(mutex); + pthread_mutexattr_destroy(&attr); + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } - delete (pthread_mutex_t*) mtxHandle; + delete holder; } } @@ -457,7 +467,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -469,7 +479,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -514,20 +524,20 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/Linux/LinuxPlatformUtils.cpp b/src/xercesc/util/Platforms/Linux/LinuxPlatformUtils.cpp index f2f4956e31cf7e2beb2c29b7f29cb27ffcc1b6cd..e960adc5a767f4652d168331c25827d42fa54abc 100644 --- a/src/xercesc/util/Platforms/Linux/LinuxPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Linux/LinuxPlatformUtils.cpp @@ -205,6 +205,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -247,9 +248,9 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #elif defined (XML_USE_NETACCESSOR_LIBWWW) - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); #else return 0; #endif @@ -268,12 +269,12 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -300,13 +301,13 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined (XML_USE_GNU_TRANSCODER) - return new IconvGNUTransService; + return new (fgMemoryManager) IconvGNUTransService; #else // Use native transcoding services. // same as -DXML_USE_NATIVE_TRANSCODER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -572,38 +573,48 @@ void XMLPlatformUtils::platformInit() // mutex creation that must be broken. if ( atomicOpsMutex == 0 ) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex; + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); - pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE_NP); - if (pthread_mutex_init(mutex, attr)) + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP); + + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); - delete attr; - return (void*)(mutex); + pthread_mutexattr_destroy(&attr); + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } - delete (pthread_mutex_t*) mtxHandle; + delete holder; } } @@ -612,7 +623,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -624,7 +635,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -669,20 +680,20 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.cpp b/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.cpp index ccc2bdac2d3b28845a716e211ff7a8e82d0ebdfa..04ce1938185dbbe2513359c01b082125c5a67818 100644 --- a/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.cpp @@ -201,7 +201,7 @@ XMLPlatformUtils::openFile(const char* const fileName if (!gFileSystemCompatible) ThrowXMLwithMemMgr1(XMLPlatformUtilsException, XMLExcepts::File_CouldNotOpenFile, fileName, manager); - Janitor<XMLMacAbstractFile> file(XMLMakeMacFile()); + Janitor<XMLMacAbstractFile> file(XMLMakeMacFile(manager)); return (file->open(fileName, false)) ? file.release() : NULL; } @@ -214,7 +214,7 @@ XMLPlatformUtils::openFile(const XMLCh* const fileName, MemoryManager* const man if (!gFileSystemCompatible) ThrowXMLwithMemMgr1(XMLPlatformUtilsException, XMLExcepts::File_CouldNotOpenFile, fileName, manager); - Janitor<XMLMacAbstractFile> file(XMLMakeMacFile()); + Janitor<XMLMacAbstractFile> file(XMLMakeMacFile(manager)); return (file->open(fileName, false)) ? file.release() : NULL; } @@ -390,7 +390,7 @@ XMLPlatformUtils::getCurrentMillis() // --------------------------------------------------------------------------- void* -XMLPlatformUtils::makeMutex() +XMLPlatformUtils::makeMutex(MemoryManager*) { if (gHasMPAPIs) { @@ -586,13 +586,13 @@ XMLPlatformUtils::makeNetAccessor() #if (defined(USE_URLACCESSCF)) // Use the URLAccess code that relies only on CoreFoundation - return new MacOSURLAccessCF; + return new (fgMemoryManager) MacOSURLAccessCF; #elif (defined(USE_URLACCESS)) // Only try to use URLAccess if it's actually available if (URLAccessAvailable()) - return new MacOSURLAccess; + return new (fgMemoryManager) MacOSURLAccess; #elif (defined(XML_USE_NETACCESSOR_SOCKET)) - return new SocketNetAccessor; + return new (fgMemoryManager) SocketNetAccessor; #endif // No netaccessor available--we can live with it, but you won't @@ -609,7 +609,7 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) { #if (defined(XML_USE_INMEMORY_MSGLOADER) || defined(XML_USE_INMEM_MESSAGELOADER)) - return new InMemMsgLoader(msgDomain); + return new (fgMemoryManager) InMemMsgLoader(msgDomain); #else #error You must provide a message loader return 0; @@ -627,10 +627,10 @@ XMLTransService* XMLPlatformUtils::makeTransService() { #if defined (XML_USE_ICU_TRANSCODER) - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif (defined(XML_USE_MACOS_UNICODECONVERTER) || defined(XML_USE_NATIVE_TRANSCODER)) if (MacOSUnicodeConverter::IsMacOSUnicodeConverterSupported()) - return new MacOSUnicodeConverter; + return new (fgMemoryManager) MacOSUnicodeConverter; #else #error You must provide a transcoding service implementation #endif @@ -735,14 +735,14 @@ ConvertSlashToColon(char* p, std::size_t charCount) // Factory method to make an appropriate subclass of XMLMacAbstractFile // for our use XMLMacAbstractFile* -XMLMakeMacFile(void) +XMLMakeMacFile(MemoryManager* manager) { XMLMacAbstractFile* result = NULL; if (gUsePosixFiles) - result = new XMLMacPosixFile; + result = new (manager) XMLMacPosixFile; else - result = new XMLMacCarbonFile; + result = new (manager) XMLMacCarbonFile; return result; } diff --git a/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.hpp b/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.hpp index a0e02354f424e9b3b23cbd0fb90ea18b4f0a8df4..0c8d6bd33f7649751d28072ab018275ed79577f4 100644 --- a/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.hpp +++ b/src/xercesc/util/Platforms/MacOS/MacOSPlatformUtils.hpp @@ -53,7 +53,7 @@ XERCES_CPP_NAMESPACE_BEGIN // Factory method to create an appropriate concrete object // descended from XMLMacAbstractFile. -XMLUTIL_EXPORT XMLMacAbstractFile* XMLMakeMacFile(void); +XMLUTIL_EXPORT XMLMacAbstractFile* XMLMakeMacFile(MemoryManager* manager); // Convert fom FSRef/FSSpec to a Unicode character string path. // Note that you'll need to delete [] that string after you're done with it! diff --git a/src/xercesc/util/Platforms/NetBSD/NetBSDPlatformUtils.cpp b/src/xercesc/util/Platforms/NetBSD/NetBSDPlatformUtils.cpp index de444a6b4bdea7a55c2737c4914165a1fef0caa8..9104ded89218b07de83c2aae0f6dbfd620cddc83 100644 --- a/src/xercesc/util/Platforms/NetBSD/NetBSDPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/NetBSD/NetBSDPlatformUtils.cpp @@ -45,6 +45,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -111,7 +112,7 @@ static void WriteUStrStdOut( const XMLCh* const toWrite) XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -132,10 +133,10 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #else // same as -DXML_USE_INMEM_MESSAGELOADER - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -162,11 +163,11 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) // Use ICU transcoding services. // same as -DXML_USE_ICU_MESSAGELOADER - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #else // Use native transcoding services. // same as -DXML_USE_INMEM_MESSAGELOADER - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -480,25 +481,30 @@ void XMLPlatformUtils::platformInit() if(!atomicOpsMutex) { - atomicOpsMutex = new (fgMemoryManager) XMLMutex(); + atomicOpsMutex = new (fgMemoryManager) XMLMutex(fgMemoryManager); if (atomicOpsMutex->fHandle == 0) - atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(); + atomicOpsMutex->fHandle = XMLPlatformUtils::makeMutex(fgMemoryManager); } } -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); + MutexHolderType* const holder = new (manager) MutexHolderType; + + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); pthread_mutexattr_settype(attr, PTHREAD_MUTEX_RECURSIVE); if (pthread_mutex_init(mutex, attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } pthread_mutexattr_destroy(attr); - delete attr; - return (void*)(mutex); + + return holder; } @@ -506,12 +512,17 @@ void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_destroy((pthread_mutex_t*) mtxHandle)) + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } - delete (pthread_mutex_t*)mtxHandle; + delete holder; } } @@ -520,7 +531,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_lock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -532,7 +543,7 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { if (mtxHandle != NULL) { - if (pthread_mutex_unlock((pthread_mutex_t*) mtxHandle)) + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -577,20 +588,20 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/OS2/OS2PlatformUtils.cpp b/src/xercesc/util/Platforms/OS2/OS2PlatformUtils.cpp index e35eca4d0f3c94b39cd1ba35492aafe573476695..7a46ea2989bb1248b2b619b2062edbd7659e60b1 100644 --- a/src/xercesc/util/Platforms/OS2/OS2PlatformUtils.cpp +++ b/src/xercesc/util/Platforms/OS2/OS2PlatformUtils.cpp @@ -267,7 +267,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) #endif } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { #if ! defined(APP_NO_THREADS) HMTX hRet; // Mutex Handle @@ -378,7 +378,7 @@ void XMLPlatformUtils::panic(const PanicHandler::PanicReasons reason) XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) { #if defined(XML_USE_INMEMORY_MSGLOADER) - return new InMemMsgLoader(msgDomain); + return new (fgMemoryManager) InMemMsgLoader(msgDomain); #else return 0; #endif @@ -392,9 +392,9 @@ XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() XMLTransService* XMLPlatformUtils::makeTransService() { #if defined(XML_USE_ICU_TRANSCODER) - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined(XML_USE_ICONV_TRANSCODER) - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #else return 0; #endif diff --git a/src/xercesc/util/Platforms/OS390/OS390PlatformUtils.cpp b/src/xercesc/util/Platforms/OS390/OS390PlatformUtils.cpp index d4de40ba1c106b5f3abfe8a7bdbb386d77b4b0f7..2e970bea2b032ba1761db2a389cd2552c1470096 100644 --- a/src/xercesc/util/Platforms/OS390/OS390PlatformUtils.cpp +++ b/src/xercesc/util/Platforms/OS390/OS390PlatformUtils.cpp @@ -45,6 +45,7 @@ #include <string.h> #include <unistd.h> #include <limits.h> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -140,7 +141,7 @@ void XMLPlatformUtils::platformInit() XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -157,11 +158,11 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -185,16 +186,16 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) { - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; } #elif defined (XML_USE_UNICONV390_TRANSCODER) { - return new Uniconv390TransService; + return new (fgMemoryManager) Uniconv390TransService; } #else { - return new Iconv390TransService; + return new (fgMemoryManager) Iconv390TransService; } #endif @@ -957,21 +958,25 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // locking mechanism is developed // ----------------------------------------------------------------------- #ifndef APP_NO_THREADS +typedef XMLHolder<pthread_mutex_t PThreadMutexHolderType; +typedef XMLHolder<int> IntMutexHolderType; + void XMLPlatformUtils::closeMutex(void* const mtxHandle) { if (mtxHandle == NULL) return; if (isPosixEnabled) { - if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + PThreadMutexHolderType* const holder = PThreadMutexHolderType::castTo(mtxHandle); + if (pthread_mutex_destroy(&holder->fInstance)) { + delete holder; + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); } - if ( (pthread_mutex_t*)mtxHandle) - delete (pthread_mutex_t*) mtxHandle; + delete holder; } // __isPosixOn else { - if ( (int*)mtxHandle) - delete (int*) mtxHandle; + delete IntMutexHolderType::castTo(mtxHandle); } } void XMLPlatformUtils::lockMutex(void* const mtxHandle) @@ -979,7 +984,7 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) if (mtxHandle == NULL) return; if (isPosixEnabled) { - if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + if (pthread_mutex_lock(&PThreadMutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } @@ -987,40 +992,42 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) else { int locked = 1, unlocked; + int* mutex = + &IntMutexHolderType::castTo(mtxHandle)->fInstance; + do { unlocked = 0; - compareAndSwap( (void**) &mtxHandle, (void*) locked, (void*) unlocked ); + compareAndSwap( (void**) &mutex, (void*) locked, (void*) unlocked ); } while( unlocked != 0 ); } return; } -void* XMLPlatformUtils::makeMutex() + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { if (isPosixEnabled) { - pthread_mutex_t* mutex = new pthread_mutex_t; - if (mutex == NULL) - { - panic(PanicHandler::Panic_MutexErr); - } + PThreadMutexHolderType* const holder = new (manager) PThreadMutexHolderType; - pthread_mutexattr_t* attr = new pthread_mutexattr_t; - pthread_mutexattr_init(attr); - pthread_mutexattr_setkind_np(attr, __MUTEX_RECURSIVE); - if (pthread_mutex_init(mutex, attr)) + pthread_mutexattr_t attr; + pthread_mutexattr_init(&attr); + pthread_mutexattr_setkind_np(&attr, __MUTEX_RECURSIVE); + if (pthread_mutex_init(&holder->fInstance, &attr)) { + delete holder; + panic(PanicHandler::Panic_MutexErr); } - pthread_mutexattr_destroy(attr); - delete attr; + pthread_mutexattr_destroy(&attr); - return (void*)(mutex); + return holder; } // __isPosixOn - else { - int* mutex = new int; - *mutex = 0; - return (void*)(mutex); + else + { + IntMutexHolderType* holder = new (manager) IntMutexHolderType; + holder->fInstance = 0; + return holder; } } void XMLPlatformUtils::unlockMutex(void* const mtxHandle) @@ -1028,33 +1035,36 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) if (mtxHandle == NULL) return; if (isPosixEnabled) { - if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + if (pthread_mutex_unlock(&PThreadMutexHolderType::castTo(mtxHandle)->fInstance)) { panic(PanicHandler::Panic_MutexErr); } } // __isPosixOn else { - if (*(int*) mtxHandle == 0 ) - *(int*) mtxHandle = 0; + int& mutex = + IntMutexHolderType::castTo(mtxHandle)->fInstance; + + if (mutex == 0) + mutex = 0; } } #else // #ifndef APP_NO_THREADS -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } diff --git a/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp b/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp index fb95c762a07d6156b85f192005476f757af35dea..aae6528a156da9032aaca2d53efc38bb4df6b975 100644 --- a/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp +++ b/src/xercesc/util/Platforms/OS400/OS400PlatformUtils.cpp @@ -82,7 +82,7 @@ char* PackingRepText(const char * const repText1, XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -100,15 +100,15 @@ XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) { - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; } #elif defined (XML_USE_ICONV400_TRANSCODER) { - return new Iconv400TransService; + return new (fgMemoryManager) Iconv400TransService; } #else { - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; } #endif @@ -123,13 +123,13 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined(XML_USE_MSGFILE_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #elif defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -683,7 +683,11 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // ----------------------------------------------------------------------- #if !defined (APP_NO_THREADS) -static pthread_mutex_t* gAtomicOpMutex =0 ; + +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +static MutexHolderType* gAtomicOpMutex = 0; + void XMLPlatformUtils::platformInit() { // @@ -694,12 +698,11 @@ void XMLPlatformUtils::platformInit() // circular dependency between compareAndExchange() and // mutex creation that must be broken. - gAtomicOpMutex = new pthread_mutex_t; + gAtomicOpMutex = new (fgMemoryManager) MutexHolderType; - if (pthread_mutex_init(gAtomicOpMutex, NULL)) { + if (pthread_mutex_init(&gAtomicOpMutex->fInstance, NULL)) { delete gAtomicOpMutex; gAtomicOpMutex = 0; - panic( PanicHandler::Panic_SystemInit ); } } @@ -710,8 +713,11 @@ public: pthread_mutex_t mutex; int recursionCount; pthread_t tid; + MemoryManager* fManager; - RecursiveMutex() { + RecursiveMutex(MemoryManager* manager) : + fManager(manager) + { if (pthread_mutex_init(&mutex, NULL)) XMLPlatformUtils::panic(PanicHandler::Panic_MutexErr); recursionCount = 0; @@ -722,7 +728,7 @@ public: ~RecursiveMutex() { if (pthread_mutex_destroy(&mutex)) - ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, XMLPlatformUtils::fgMemoryManager); + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, manager); } void lock() { @@ -750,9 +756,9 @@ public: } }; -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - return new RecursiveMutex; + return new (manager) RecursiveMutex(manager); } @@ -795,14 +801,14 @@ void* XMLPlatformUtils::compareAndSwap ( void** toFill , // the below calls are temporarily made till the above functions are part of user library // Currently its supported only in the kernel mode - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); void *retVal = *toFill; if (*toFill == toCompare) *toFill = (void *)newValue; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return retVal; @@ -844,20 +850,20 @@ void XMLPlatformUtils::platformInit() // do nothing } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* constmanager) { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } @@ -903,7 +909,7 @@ FileHandle XMLPlatformUtils::openStdInHandle(MemoryManager* const manager) void XMLPlatformUtils::platformTerm() { #if !defined (APP_NO_THREADS) - pthread_mutex_destroy(gAtomicOpMutex); + pthread_mutex_destroy(&gAtomicOpMutex->fInstance); delete gAtomicOpMutex; gAtomicOpMutex = 0; #endif diff --git a/src/xercesc/util/Platforms/OpenServer/OpenServerPlatformUtils.cpp b/src/xercesc/util/Platforms/OpenServer/OpenServerPlatformUtils.cpp index ab1763421b6d24655427b2bc960d3898ccaebef1..f5a6d1e65a15ee9e93625c831b7ddf9d317e713b 100644 --- a/src/xercesc/util/Platforms/OpenServer/OpenServerPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/OpenServer/OpenServerPlatformUtils.cpp @@ -94,6 +94,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -141,11 +142,11 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -163,9 +164,9 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_LIBWWW) - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); #else - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #endif } @@ -180,9 +181,9 @@ XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() XMLTransService* XMLPlatformUtils::makeTransService() { #if defined (XML_USE_ICU_TRANSCODER) - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #else - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; #endif } @@ -436,7 +437,9 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // --------------------------------------------------------------------------- #if !defined (APP_NO_THREADS) -static pthread_mutex_t* gAtomicOpMutex = 0; +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +static MutexHolderType* gAtomicOpMutex = 0; // --------------------------------------------------------------------------- // XMLPlatformUtils: Platform init method @@ -448,9 +451,9 @@ void XMLPlatformUtils::platformInit() // Normally, mutexes are created on first use, but there is a // circular dependency between compareAndExchange() and // mutex creation that must be broken. - gAtomicOpMutex = new pthread_mutex_t; + gAtomicOpMutex = new (fgMemoryManager) MutexHolderType; - if (pthread_mutex_init(gAtomicOpMutex, NULL)) + if (pthread_mutex_init(&gAtomicOpMutex->fInstance, NULL)) { delete gAtomicOpMutex; gAtomicOpMutex = 0; @@ -467,18 +470,21 @@ public: pthread_mutex_t mutex; int recursionCount; pthread_t tid; + MemoryManager* const fMemoryManager; - RecursiveMutex() { + RecursiveMutex(MemoryManager* manager) : + mutex(), + recursionCount(0), + tid(0), + fMemoryManager(manager) { if (pthread_mutex_init(&mutex, NULL)) XMLPlatformUtils::panic(PanicHandler::Panic_MutexErr); - recursionCount = 0; - tid = 0; } ~RecursiveMutex() { if (pthread_mutex_destroy(&mutex)) ThrowXMLwithMemMgr(XMLPlatformUtilsException, - XMLExcepts::Mutex_CouldNotDestroy, XMLPlatformUtils::fgMemoryManager); + XMLExcepts::Mutex_CouldNotDestroy, fMemoryManager); } void lock() { @@ -503,9 +509,9 @@ public: } }; -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - return new RecursiveMutex; + return new (manager) RecursiveMutex(manager); } void XMLPlatformUtils::closeMutex(void* const mtxHandle) @@ -546,14 +552,14 @@ void* XMLPlatformUtils::compareAndSwap(void** toFill, const void* const newValue, const void* const toCompare) { - if (pthread_mutex_lock(gAtomicOpMutex)) + if (pthread_mutex_lock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); void *retVal = *toFill; if (*toFill == toCompare) *toFill = (void *)newValue; - if (pthread_mutex_unlock(gAtomicOpMutex)) + if (pthread_mutex_unlock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return retVal; @@ -561,12 +567,12 @@ void* XMLPlatformUtils::compareAndSwap(void** toFill, int XMLPlatformUtils::atomicIncrement(int &location) { - if (pthread_mutex_lock(gAtomicOpMutex)) + if (pthread_mutex_lock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = ++location; - if (pthread_mutex_unlock(gAtomicOpMutex)) + if (pthread_mutex_unlock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -574,12 +580,12 @@ int XMLPlatformUtils::atomicIncrement(int &location) int XMLPlatformUtils::atomicDecrement(int &location) { - if (pthread_mutex_lock(gAtomicOpMutex)) + if (pthread_mutex_lock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = --location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -602,20 +608,20 @@ void XMLPlatformUtils::platformInit() // ----------------------------------------------------------------------- // Mutex- and atomic operation methods // ----------------------------------------------------------------------- -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } @@ -648,7 +654,7 @@ int XMLPlatformUtils::atomicDecrement(int &location) void XMLPlatformUtils::platformTerm() { #if !defined (APP_NO_THREADS) - pthread_mutex_destroy(gAtomicOpMutex); + pthread_mutex_destroy(&gAtomicOpMutex->fInstance); delete gAtomicOpMutex; gAtomicOpMutex = 0; #else diff --git a/src/xercesc/util/Platforms/QNX/QNXPlatformUtils.cpp b/src/xercesc/util/Platforms/QNX/QNXPlatformUtils.cpp index 34f9014f13cc0a4f8f50198d7bf64cdd81aacee3..94ee9c360115a04f7124fa743b56f54db17510d9 100644 --- a/src/xercesc/util/Platforms/QNX/QNXPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/QNX/QNXPlatformUtils.cpp @@ -34,6 +34,7 @@ #include <xercesc/util/Janitor.hpp> #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/RuntimeException.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLExceptMsgs.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> @@ -253,41 +254,63 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // Mutex methods // --------------------------------------------------------------------------- -void* XMLPlatformUtils::makeMutex() +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { pthread_mutexattr_t attr; pthread_mutexattr_init( &attr ); pthread_mutexattr_setrecursive( &attr, PTHREAD_RECURSIVE_ENABLE ); - pthread_mutex_t *mutex = new pthread_mutex_t; - if( pthread_mutex_init( mutex, &attr ) != EOK ) { - delete mutex; + + MutexHolderType* const holder = new (manager) MutexHolderType; + + if( pthread_mutex_init( &holder->fInstance, &attr ) != EOK ) { + delete holder; panic(PanicHandler::Panic_MutexErr); } pthread_mutexattr_destroy( &attr ); - return mutex; + return holder; } void XMLPlatformUtils::closeMutex(void* const mtxHandle) { - if( mtxHandle == NULL || pthread_mutex_destroy( (pthread_mutex_t *)mtxHandle ) != EOK ) { - ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotClose, fgMemoryManager); + if (mtxHandle != NULL) + { + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) + { + delete holder; + + ThrowXMLwithMemMgr(XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); + } + delete holder; } - delete mtxHandle; } void XMLPlatformUtils::lockMutex(void* const mtxHandle) { - if( mtxHandle == NULL || pthread_mutex_lock( (pthread_mutex_t *)mtxHandle ) != EOK ) { - panic(PanicHandler::Panic_MutexErr); + if (mtxHandle != NULL) + { + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) + { + panic(PanicHandler::Panic_MutexErr); + } } } void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { - if( mtxHandle == NULL || pthread_mutex_unlock( (pthread_mutex_t *)mtxHandle ) != EOK ) { - panic(PanicHandler::Panic_MutexErr); + if (mtxHandle != NULL) + { + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) + { + panic(PanicHandler::Panic_MutexErr); + } } } @@ -340,9 +363,9 @@ int XMLPlatformUtils::atomicDecrement(int &location) XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_LIBWWW) - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); #else - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #endif } @@ -355,9 +378,9 @@ XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) { #if defined (XML_USE_ICU_MESSAGELOADER) - return new ICUMsgLoader(msgDomain); + return new (fgMemoryManager) ICUMsgLoader(msgDomain); #else - return new InMemMsgLoader(msgDomain); + return new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } @@ -371,9 +394,9 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) XMLTransService* XMLPlatformUtils::makeTransService() { #if defined (XML_USE_ICU_TRANSCODER) - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined (XML_USE_GNU_TRANSCODER) - return new IconvGNUTransService; + return new (fgMemoryManager) IconvGNUTransService; #else #error You must provide a transcoding service implementation #endif diff --git a/src/xercesc/util/Platforms/Solaris/SolarisPlatformUtils.cpp b/src/xercesc/util/Platforms/Solaris/SolarisPlatformUtils.cpp index 45a77b8922ef6e7c340a144b715310bf2257a593..bf03a06f3f3271bf1a28dc3eb06b3435079a1389 100644 --- a/src/xercesc/util/Platforms/Solaris/SolarisPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Solaris/SolarisPlatformUtils.cpp @@ -49,6 +49,7 @@ #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -90,9 +91,9 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_LIBWWW) - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); #elif defined (XML_USE_NETACCESSOR_SOCKET) - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); #else return 0; #endif @@ -111,11 +112,11 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -140,15 +141,15 @@ XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) { - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; } #elif defined (XML_USE_ICONV_TRANSCODER) { - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; } #else // Use Native transcoding service { - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; } #endif @@ -389,7 +390,9 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // XMLPlatformUtils: Platform init method // --------------------------------------------------------------------------- -static pthread_mutex_t* gAtomicOpMutex =0 ; +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +static MutexHolderType* gAtomicOpMutex = 0; void XMLPlatformUtils::platformInit() { @@ -401,42 +404,41 @@ void XMLPlatformUtils::platformInit() // circular dependency between compareAndExchange() and // mutex creation that must be broken. - gAtomicOpMutex = new pthread_mutex_t; + gAtomicOpMutex = new (fgMemoryManager) MutexHolderType; #if defined(XML_USE_DCE) - if (pthread_mutex_init(gAtomicOpMutex, pthread_mutexattr_default)) { - delete gAtomicOpMutex; - gAtomicOpMutex = 0; - panic( PanicHandler::Panic_SystemInit ); - } + if (pthread_mutex_init(&gAtomicOpMutex->fInstance, pthread_mutexattr_default)) { #else // XML_USE_DCE - if (pthread_mutex_init(gAtomicOpMutex, NULL)) { - delete gAtomicOpMutex; - gAtomicOpMutex = 0; + if (pthread_mutex_init(&gAtomicOpMutex->fInstance, NULL)) { +#endif // XML_USE_DCE + delete gAtomicOpMutex; + gAtomicOpMutex = 0; panic( PanicHandler::Panic_SystemInit ); } -#endif // XML_USE_DCE } #ifndef XML_USE_DCE // inlining the class with dce threading causes segmentation fault -class RecursiveMutex +class RecursiveMutex : public XMemory { public: - pthread_mutex_t mutex; - int recursionCount; - pthread_t tid; - - RecursiveMutex() { + pthread_mutex_t mutex; + int recursionCount; + pthread_t tid; + MemoryManager* const fMemoryManager; + + RecursiveMutex(MemoryManager* manager) : + mutex(), + recursionCount(0), + tid(0), + fMemoryManager(manager) { if (pthread_mutex_init(&mutex, NULL)) XMLPlatformUtils::panic(PanicHandler::Panic_MutexErr); - recursionCount = 0; - tid = 0; } ~RecursiveMutex() { if (pthread_mutex_destroy(&mutex)) - ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, XMLPlatformUtils::fgMemoryManager); + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fMemoryManager); } void lock() { @@ -463,25 +465,27 @@ public: }; #endif // ifndef XML_USE_DCE -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { #if defined(XML_USE_DCE) - pthread_mutex_t* mutex = new pthread_mutex_t; - if (mutex == NULL) + + MutexHolderType* const holder = new (manager) MutexHolderType; + + if (holder == NULL) { panic(PanicHandler::Panic_MutexErr); } pthread_mutexattr_t attr; pthread_mutexattr_create(&attr); pthread_mutexattr_setkind_np(&attr, MUTEX_RECURSIVE_NP); - if (pthread_mutex_init(mutex, attr)) + if (pthread_mutex_init(&holder->fInstance, attr)) { panic(PanicHandler::Panic_MutexErr); } pthread_mutexattr_delete(&attr); - return (void*)(mutex); + return holder; #else - return new RecursiveMutex; + return new (manager) RecursiveMutex(manager); #endif } @@ -491,8 +495,8 @@ void XMLPlatformUtils::closeMutex(void* const mtxHandle) if (mtxHandle == NULL) return; #if defined(XML_USE_DCE) - pthread_mutex_t *rm = (pthread_mutex_t *)mtxHandle; - pthread_mutex_destroy(rm); + MutexHolderType *rm = MutexHolderType::castTo(mtxHandle); + pthread_mutex_destroy(&rm->fInstance); #else RecursiveMutex *rm = (RecursiveMutex *)mtxHandle; #endif @@ -505,8 +509,9 @@ void XMLPlatformUtils::lockMutex(void* const mtxHandle) if (mtxHandle == NULL) return; #if defined(XML_USE_DCE) - pthread_mutex_t *rm = (pthread_mutex_t *)mtxHandle; - pthread_mutex_lock(rm); + MutexHolderType *rm = MutexHolderType::castTo(mtxHandle); + + pthread_mutex_lock(&rm->fInstance); #else RecursiveMutex *rm = (RecursiveMutex *)mtxHandle; rm->lock(); @@ -518,8 +523,9 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) if (mtxHandle == NULL) return; #if defined(XML_USE_DCE) - pthread_mutex_t *rm = (pthread_mutex_t *)mtxHandle; - pthread_mutex_unlock(rm); + MutexHolderType *rm = MutexHolderType::castTo(mtxHandle); + + pthread_mutex_unlock(&rm->fInstance); #else RecursiveMutex *rm = (RecursiveMutex *)mtxHandle; rm->unlock(); @@ -541,14 +547,14 @@ void* XMLPlatformUtils::compareAndSwap ( void** toFill , // the below calls are temporarily made till the above functions are part of user library // Currently its supported only in the kernel mode - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); void *retVal = *toFill; if (*toFill == toCompare) *toFill = (void *)newValue; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return retVal; @@ -558,12 +564,12 @@ int XMLPlatformUtils::atomicIncrement(int &location) { //return (int)atomic_add_32_nv( (uint32_t*)&location, 1); - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = ++location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -572,12 +578,12 @@ int XMLPlatformUtils::atomicDecrement(int &location) { //return (int)atomic_add_32_nv( (uint32_t*)&location, -1); - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = --location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock(&gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -589,20 +595,20 @@ void XMLPlatformUtils::platformInit() { } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } @@ -638,7 +644,7 @@ FileHandle XMLPlatformUtils::openStdInHandle(MemoryManager* const manager) void XMLPlatformUtils::platformTerm() { #if !defined(APP_NO_THREADS) - pthread_mutex_destroy(gAtomicOpMutex); + pthread_mutex_destroy(&gAtomicOpMutex->fInstance); delete gAtomicOpMutex; gAtomicOpMutex = 0; #endif diff --git a/src/xercesc/util/Platforms/Tandem/TandemPlatformUtils.cpp b/src/xercesc/util/Platforms/Tandem/TandemPlatformUtils.cpp index b1899a554a4ee762d481b794ea47e40600f81c2e..a5a744e746403f519dd05f0270d8f774e451888c 100644 --- a/src/xercesc/util/Platforms/Tandem/TandemPlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Tandem/TandemPlatformUtils.cpp @@ -94,6 +94,7 @@ #include <sys/timeb.h> #include <string.h> #include <xercesc/util/OutOfMemoryException.hpp> +#include <xercesc/util/XMLHolder.hpp> #if defined (XML_USE_ICU_MESSAGELOADER) #include <xercesc/util/MsgLoaders/ICU/ICUMsgLoader.hpp> @@ -123,11 +124,11 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -312,49 +313,60 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // ----------------------------------------------------------------------- // Mutex methods // ----------------------------------------------------------------------- + +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + void XMLPlatformUtils::closeMutex(void* const mtxHandle) { - if (mtxHandle == NULL) - return; - if (pthread_mutex_destroy( (pthread_mutex_t*)mtxHandle)) + if (mtxHandle != NULL) { - throw XMLPlatformUtilsException("Could not destroy a mutex"); + MutexHolderType* const holder = + MutexHolderType::castTo(mtxHandle); + + if (pthread_mutex_destroy(&holder->fInstance)) + { + delete holder; + + ThrowXMLwithMemMgr(XMLPlatformUtilsException, + XMLExcepts::Mutex_CouldNotDestroy, fgMemoryManager); + } + delete holder; } - if ( (pthread_mutex_t*)mtxHandle) - delete (pthread_mutex_t*) mtxHandle; } + void XMLPlatformUtils::lockMutex(void* const mtxHandle) { - if (mtxHandle == NULL) - return; - if (pthread_mutex_lock( (pthread_mutex_t*)mtxHandle)) + if (mtxHandle != NULL) { - throw XMLPlatformUtilsException("Could not lock a mutex"); + if (pthread_mutex_lock(&MutexHolderType::castTo(mtxHandle)->fInstance)) + { + panic(PanicHandler::Panic_MutexErr); + } } - } -void* XMLPlatformUtils::makeMutex() + +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - pthread_mutex_t* mutex = new pthread_mutex_t; - if (mutex == NULL) - { - throw XMLPlatformUtilsException("Could not initialize a mutex"); - } + MutexHolderType* const holder = new (manager) MutexHolderType; - if (pthread_mutex_init(mutex, NULL)) + if (pthread_mutex_init(&holder->fInstance, NULL)) { - throw XMLPlatformUtilsException("Could not create a mutex"); + delete holder; + + panic(PanicHandler::Panic_MutexErr); } - return (void*)(mutex); + return holder; } + void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { - if (mtxHandle == NULL) - return; - if (pthread_mutex_unlock( (pthread_mutex_t*)mtxHandle)) + if (mtxHandle != NULL) { - throw XMLPlatformUtilsException("Could not unlock a mutex"); + if (pthread_mutex_unlock(&MutexHolderType::castTo(mtxHandle)->fInstance)) + { + panic(PanicHandler::Panic_MutexErr); + } } } diff --git a/src/xercesc/util/Platforms/Tru64/Tru64PlatformUtils.cpp b/src/xercesc/util/Platforms/Tru64/Tru64PlatformUtils.cpp index b2da68b211c048d020180899589daee777b462b4..56384c20bc9160f6e5e82f73efa2d9f7a5c95d82 100644 --- a/src/xercesc/util/Platforms/Tru64/Tru64PlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Tru64/Tru64PlatformUtils.cpp @@ -35,6 +35,7 @@ #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUni.hpp> #include <xercesc/util/XMLUniDefs.hpp> @@ -83,11 +84,11 @@ XERCES_CPP_NAMESPACE_BEGIN XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() #if defined (XML_USE_NETACCESSOR_LIBWWW) { - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); } #elif defined (XML_USE_NETACCESSOR_SOCKET) { - return new SocketNetAccessor(); + return new (fgMemoryManager) SocketNetAccessor(); } #else { @@ -106,11 +107,11 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) try { #if defined (XML_USE_ICU_MESSAGELOADER) - retVal = new ICUMsgLoader(msgDomain); + retVal = new (fgMemoryManager) ICUMsgLoader(msgDomain); #elif defined (XML_USE_ICONV_MESSAGELOADER) - retVal = new MsgCatalogLoader(msgDomain); + retVal = new (fgMemoryManager) MsgCatalogLoader(msgDomain); #else - retVal = new InMemMsgLoader(msgDomain); + retVal = new (fgMemoryManager) InMemMsgLoader(msgDomain); #endif } catch(const OutOfMemoryException&) @@ -134,15 +135,15 @@ XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) XMLTransService* XMLPlatformUtils::makeTransService() #if defined (XML_USE_ICU_TRANSCODER) { - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; } #elif defined (XML_USE_ICONV_TRANSCODER) { - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; } #else // Use Native transcoding service { - return new IconvTransService; + return new (fgMemoryManager) IconvTransService; } #endif @@ -387,7 +388,9 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // XMLPlatformUtils: Platform init method // --------------------------------------------------------------------------- -static pthread_mutex_t* gAtomicOpMutex =0 ; +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +static MutexHolderType* gAtomicOpMutex = 0; void XMLPlatformUtils::platformInit() { @@ -399,9 +402,10 @@ void XMLPlatformUtils::platformInit() // circular dependency between compareAndExchange() and // mutex creation that must be broken. - gAtomicOpMutex = new pthread_mutex_t; + gAtomicOpMutex = new (fgMemoryManager) MutexHolderType; + - if (pthread_mutex_init(gAtomicOpMutex, NULL)) { + if (pthread_mutex_init(&gAtomicOpMutex->fInstance, NULL)) { delete gAtomicOpMutex; gAtomicOpMutex = 0; panic( PanicHandler::Panic_SystemInit ); @@ -420,19 +424,22 @@ public: pthread_mutex_t mutex; int recursionCount; pthread_t tid; + MemoryManager* const fMemoryManager; - RecursiveMutex() + RecursiveMutex(MemoryManager* manager) : + mutex(), + recursionCount(0), + tid(0), + fMemoryManager(manager) { if (pthread_mutex_init(&mutex, NULL)) XMLPlatformUtils::panic(PanicHandler::Panic_MutexErr); - recursionCount = 0; - tid = 0; } ~RecursiveMutex() { if (pthread_mutex_destroy(&mutex)) - ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, XMLPlatformUtils::fgMemoryManager); + ThrowXMLwithMemMgr(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotDestroy, fMemoryManager); } void lock() @@ -460,9 +467,9 @@ public: } }; -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - return new RecursiveMutex; + return new (manager) RecursiveMutex(manager); } @@ -506,14 +513,14 @@ void* XMLPlatformUtils::compareAndSwap (void** toFill, // the below calls are temporarily made till the above functions are part of user library // Currently its supported only in the kernel mode - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); void *retVal = *toFill; if (*toFill == toCompare) *toFill = (void *)newValue; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return retVal; @@ -523,12 +530,12 @@ int XMLPlatformUtils::atomicIncrement(int &location) { //return (int)atomic_add_32_nv( (uint32_t*)&location, 1); - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = ++location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -537,12 +544,12 @@ int XMLPlatformUtils::atomicDecrement(int &location) { //return (int)atomic_add_32_nv( (uint32_t*)&location, -1); - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = --location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -555,20 +562,20 @@ void XMLPlatformUtils::platformInit() // do nothing } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } @@ -604,7 +611,7 @@ FileHandle XMLPlatformUtils::openStdInHandle(MemoryManager* const manager) void XMLPlatformUtils::platformTerm() { #if !defined (APP_NO_THREADS) - pthread_mutex_destroy(gAtomicOpMutex); + pthread_mutex_destroy(&gAtomicOpMutex->fInstance); delete gAtomicOpMutex; gAtomicOpMutex = 0; #endif diff --git a/src/xercesc/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp b/src/xercesc/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp index 4c0c84cd7c30cf07443915409402d9b9f185af53..308631ba430347bcfcfca11f632b51b9c58cf173 100644 --- a/src/xercesc/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp +++ b/src/xercesc/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp @@ -139,6 +139,7 @@ #include <xercesc/util/RuntimeException.hpp> #include <xercesc/util/Janitor.hpp> #include <xercesc/util/Mutexes.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> #include <xercesc/util/XMLUni.hpp> @@ -491,7 +492,9 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // --------------------------------------------------------------------------- // XMLPlatformUtils: Platform init method // --------------------------------------------------------------------------- -static pthread_mutex_t* gAtomicOpMutex =0 ; +typedef XMLHolder<pthread_mutex_t> MutexHolderType; + +static MutexHolderType* gAtomicOpMutex = 0; void XMLPlatformUtils::platformInit() { @@ -503,10 +506,14 @@ void XMLPlatformUtils::platformInit() // circular dependency between compareAndExchange() and // mutex creation that must be broken. - gAtomicOpMutex = new pthread_mutex_t; + gAtomicOpMutex = new (fgMemoryManager) MutexHolderType; - if (pthread_mutex_init(gAtomicOpMutex, NULL)) + if (pthread_mutex_init(&gAtomicOpMutex->fInstance, NULL)) + { + delete gAtomicOpMutex; + gAtomicOpMutex = 0; panic( PanicHandler::Panic_SystemInit ); + } } class RecursiveMutex : public XMemory @@ -593,14 +600,14 @@ void* XMLPlatformUtils::compareAndSwap ( void** toFill , const void* const newValue , const void* const toCompare) { - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); void *retVal = *toFill; if (*toFill == toCompare) *toFill = (void *)newValue; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); @@ -609,12 +616,12 @@ void* XMLPlatformUtils::compareAndSwap ( void** toFill , int XMLPlatformUtils::atomicIncrement(int &location) { - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = ++location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -622,12 +629,12 @@ int XMLPlatformUtils::atomicIncrement(int &location) int XMLPlatformUtils::atomicDecrement(int &location) { - if (pthread_mutex_lock( gAtomicOpMutex)) + if (pthread_mutex_lock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); int tmp = --location; - if (pthread_mutex_unlock( gAtomicOpMutex)) + if (pthread_mutex_unlock( &gAtomicOpMutex->fInstance)) panic(PanicHandler::Panic_SynchronizationErr); return tmp; @@ -639,20 +646,20 @@ void XMLPlatformUtils::platformInit() { } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager*) { return 0; } -void XMLPlatformUtils::closeMutex(void* const mtxHandle) +void XMLPlatformUtils::closeMutex(void* const) { } -void XMLPlatformUtils::lockMutex(void* const mtxHandle) +void XMLPlatformUtils::lockMutex(void* const) { } -void XMLPlatformUtils::unlockMutex(void* const mtxHandle) +void XMLPlatformUtils::unlockMutex(void* const) { } @@ -684,7 +691,7 @@ void XMLPlatformUtils::platformTerm() { #if !defined (APP_NO_THREADS) // delete the mutex we created - pthread_mutex_destroy(gAtomicOpMutex); + pthread_mutex_destroy(&gAtomicOpMutex->fInstance); delete gAtomicOpMutex; gAtomicOpMutex = 0; #endif diff --git a/src/xercesc/util/Platforms/Win32/Win32PlatformUtils.cpp b/src/xercesc/util/Platforms/Win32/Win32PlatformUtils.cpp index 0e4397f961fb06b604c5db334862d3bca08094c7..ce609e8163165d4ee5b849bc0799e47db5db7878 100644 --- a/src/xercesc/util/Platforms/Win32/Win32PlatformUtils.cpp +++ b/src/xercesc/util/Platforms/Win32/Win32PlatformUtils.cpp @@ -24,6 +24,8 @@ #include <xercesc/util/Janitor.hpp> #include <xercesc/util/PlatformUtils.hpp> #include <xercesc/util/RuntimeException.hpp> +#include <xercesc/util/XMemory.hpp> +#include <xercesc/util/XMLHolder.hpp> #include <xercesc/util/XMLExceptMsgs.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/XMLUniDefs.hpp> @@ -638,34 +640,40 @@ unsigned long XMLPlatformUtils::getCurrentMillis() } +typedef XMLHolder<CRITICAL_SECTION> MutexHolderType; + // --------------------------------------------------------------------------- // Mutex methods // --------------------------------------------------------------------------- void XMLPlatformUtils::closeMutex(void* const mtxHandle) { - ::DeleteCriticalSection((LPCRITICAL_SECTION)mtxHandle); - delete (CRITICAL_SECTION*)mtxHandle; + MutexHolderType* const holder = MutexHolderType::castTo(mtxHandle); + + ::DeleteCriticalSection(&holder->fInstance); + delete holder; } void XMLPlatformUtils::lockMutex(void* const mtxHandle) { - ::EnterCriticalSection((LPCRITICAL_SECTION)mtxHandle); + ::EnterCriticalSection(&MutexHolderType::castTo(mtxHandle)->fInstance); } -void* XMLPlatformUtils::makeMutex() +void* XMLPlatformUtils::makeMutex(MemoryManager* manager) { - CRITICAL_SECTION* newCS = new CRITICAL_SECTION; - InitializeCriticalSection(newCS); - return newCS; + MutexHolderType* const holder = new (manager) MutexHolderType; + + InitializeCriticalSection(&holder->fInstance); + + return holder; } void XMLPlatformUtils::unlockMutex(void* const mtxHandle) { - ::LeaveCriticalSection((LPCRITICAL_SECTION)mtxHandle); + ::LeaveCriticalSection(&MutexHolderType::castTo(mtxHandle)->fInstance); } @@ -745,9 +753,9 @@ int XMLPlatformUtils::atomicDecrement(int &location) XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() { #if defined (XML_USE_NETACCESSOR_LIBWWW) - return new LibWWWNetAccessor(); + return new (fgMemoryManager) LibWWWNetAccessor(); #elif defined (XML_USE_NETACCESSOR_WINSOCK) - return new WinSockNetAccessor(); + return new (fgMemoryManager) WinSockNetAccessor(); #else return 0; #endif @@ -762,11 +770,11 @@ XMLNetAccessor* XMLPlatformUtils::makeNetAccessor() XMLMsgLoader* XMLPlatformUtils::loadAMsgSet(const XMLCh* const msgDomain) { #if defined (XML_USE_INMEM_MESSAGELOADER) - return new InMemMsgLoader(msgDomain); + return new (fgMemoryManager) InMemMsgLoader(msgDomain); #elif defined (XML_USE_WIN32_MSGLOADER) - return new Win32MsgLoader(msgDomain); + return new (fgMemoryManager) Win32MsgLoader(msgDomain); #elif defined (XML_USE_ICU_MESSAGELOADER) - return new ICUMsgLoader(msgDomain); + return new (fgMemoryManager) ICUMsgLoader(msgDomain); #else #error You must provide a message loader #endif @@ -788,11 +796,11 @@ XMLTransService* XMLPlatformUtils::makeTransService() // to our DLL. // #if defined (XML_USE_ICU_TRANSCODER) - return new ICUTransService; + return new (fgMemoryManager) ICUTransService; #elif defined (XML_USE_WIN32_TRANSCODER) - return new Win32TransService; + return new (fgMemoryManager) Win32TransService; #elif defined (XML_USE_CYGWIN_TRANSCODER) - return new CygwinTransService; + return new (fgMemoryManager) CygwinTransService; #else #error You must provide a transcoding service implementation #endif diff --git a/src/xercesc/util/SynchronizedStringPool.cpp b/src/xercesc/util/SynchronizedStringPool.cpp index 72254ccbdd53799b146e05dee538610c4a0afbf1..5713906563034db7e2929c56792b1bc3de79f965 100644 --- a/src/xercesc/util/SynchronizedStringPool.cpp +++ b/src/xercesc/util/SynchronizedStringPool.cpp @@ -45,6 +45,7 @@ XMLSynchronizedStringPool::XMLSynchronizedStringPool(const XMLStringPool *constP XMLStringPool(modulus, manager) , fConstPool(constPool) + , fMutex(manager) { } diff --git a/src/xercesc/util/XMLException.cpp b/src/xercesc/util/XMLException.cpp index dd8e5690a8f9400edec2392d90f0f96aacf1dcdd..47ddc8fd7c3df221823918a8128ebbcd23d8813b 100644 --- a/src/xercesc/util/XMLException.cpp +++ b/src/xercesc/util/XMLException.cpp @@ -59,7 +59,7 @@ static XMLMutex& gMsgMutex() if (!sScannerMutexRegistered) { - sMsgMutex = new XMLMutex; + sMsgMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); msgMutexCleanup.registerCleanup(XMLException::reinitMsgMutex); sScannerMutexRegistered = true; } diff --git a/src/xercesc/util/regx/RangeTokenMap.cpp b/src/xercesc/util/regx/RangeTokenMap.cpp index b4615c0b968f6c4855ac661b0f9c3a62dad69743..ed290f8736de7953159cd86cd5dfd52a1b8a35c8 100644 --- a/src/xercesc/util/regx/RangeTokenMap.cpp +++ b/src/xercesc/util/regx/RangeTokenMap.cpp @@ -128,7 +128,7 @@ static XMLMutex& getRangeTokMapMutex() // If we got here first, then register it and set the registered flag if (!sRangeTokMapMutex) { - sRangeTokMapMutex = new XMLMutex; + sRangeTokMapMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); rangeTokMapRegistryCleanup.registerCleanup(reinitRangeTokMapMutex); } } @@ -142,7 +142,7 @@ RangeTokenMap* RangeTokenMap::fInstance = 0; void XMLInitializer::initializeRangeTokenMap() { - RangeTokenMap::fInstance = new RangeTokenMap(); + RangeTokenMap::fInstance = new RangeTokenMap(XMLPlatformUtils::fgMemoryManager); if (RangeTokenMap::fInstance) { rangeTokMapInstanceCleanup.registerCleanup(RangeTokenMap::reinitInstance); @@ -170,17 +170,18 @@ RangeTokenElemMap::~RangeTokenElemMap() // --------------------------------------------------------------------------- // RangeTokenMap: Constructors and Destructor // --------------------------------------------------------------------------- -RangeTokenMap::RangeTokenMap() : +RangeTokenMap::RangeTokenMap(MemoryManager* manager) : fTokenRegistry(0) , fRangeMap(0) , fCategories(0) , fTokenFactory(0) + , fMutex(manager) { try { - fTokenRegistry = new RefHashTableOf<RangeTokenElemMap>(109); - fRangeMap = new RefHashTableOf<RangeFactory>(29); - fCategories = new XMLStringPool(109); - fTokenFactory = new TokenFactory(); + fTokenRegistry = new (manager) RefHashTableOf<RangeTokenElemMap>(109, manager); + fRangeMap = new (manager) RefHashTableOf<RangeFactory>(29, manager); + fCategories = new (manager) XMLStringPool(109, manager); + fTokenFactory = new (manager) TokenFactory(manager); initializeRegistry(); } catch(...) { @@ -362,7 +363,7 @@ RangeTokenMap* RangeTokenMap::instance() if (!fInstance) { - fInstance = new RangeTokenMap(); + fInstance = new RangeTokenMap(XMLPlatformUtils::fgMemoryManager); rangeTokMapInstanceCleanup.registerCleanup(RangeTokenMap::reinitInstance); } } diff --git a/src/xercesc/util/regx/RangeTokenMap.hpp b/src/xercesc/util/regx/RangeTokenMap.hpp index 8835346f2bb13bb491d7c5c39785a49cc50566e7..ffffc0c7d1f076bd617482a066b45a46521a8a1e 100644 --- a/src/xercesc/util/regx/RangeTokenMap.hpp +++ b/src/xercesc/util/regx/RangeTokenMap.hpp @@ -107,7 +107,7 @@ protected: // ----------------------------------------------------------------------- // Constructor and destructors // ----------------------------------------------------------------------- - RangeTokenMap(); + RangeTokenMap(MemoryManager* manager); ~RangeTokenMap(); // ----------------------------------------------------------------------- diff --git a/src/xercesc/util/regx/RegxParser.cpp b/src/xercesc/util/regx/RegxParser.cpp index bd495a311371e1429bf8890a2423a4fe99ad4051..2ce910b68c0901f4d99449e9b50c94ebe6348c57 100644 --- a/src/xercesc/util/regx/RegxParser.cpp +++ b/src/xercesc/util/regx/RegxParser.cpp @@ -167,8 +167,6 @@ Token* RegxParser::parse(const XMLCh* const regxStr, const int options) { return 0; } - XMLMutexLock lockInit(&fMutex); - fOptions = options; fOffset = 0; fNoGroups = 1; diff --git a/src/xercesc/util/regx/RegxParser.hpp b/src/xercesc/util/regx/RegxParser.hpp index 817e93c04e601a8671011ee6ac6d936fef71be01..2e4000d153c4f5e8b8625919b0fdee77d2c92bbf 100644 --- a/src/xercesc/util/regx/RegxParser.hpp +++ b/src/xercesc/util/regx/RegxParser.hpp @@ -29,7 +29,6 @@ // --------------------------------------------------------------------------- #include <xercesc/util/RefVectorOf.hpp> #include <xercesc/util/XMLUniDefs.hpp> -#include <xercesc/util/Mutexes.hpp> XERCES_CPP_NAMESPACE_BEGIN @@ -203,7 +202,6 @@ private: XMLCh* fString; RefVectorOf<ReferencePosition>* fReferences; TokenFactory* fTokenFactory; - XMLMutex fMutex; }; diff --git a/src/xercesc/validators/DTD/DTDGrammar.cpp b/src/xercesc/validators/DTD/DTDGrammar.cpp index ecd37bdc73e0e19d0694308bf0981e0cdc574fa0..d92b0c48464a29a3f5d1cbf2d4aa50d24193b6f0 100644 --- a/src/xercesc/validators/DTD/DTDGrammar.cpp +++ b/src/xercesc/validators/DTD/DTDGrammar.cpp @@ -291,7 +291,7 @@ void DTDGrammar::resetEntityDeclPool() { { XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); if (!sEntityPoolMutex) - sEntityPoolMutex = new XMLMutex; + sEntityPoolMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); } // Use a faux scope to synchronize while we do this diff --git a/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp b/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp index aa86c4ab40949793454b826002f5e90a0986f4a3..b9f1c26eef83a6801d4f15bb37b72c597ba39fe7 100644 --- a/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp +++ b/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp @@ -375,7 +375,7 @@ void DatatypeValidatorFactory::expandRegistryToFullSchemaSet() { XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); if (!sBuiltInRegistryMutex) - sBuiltInRegistryMutex = new XMLMutex; + sBuiltInRegistryMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); } // Use a faux scope to synchronize while we do this diff --git a/src/xercesc/validators/schema/ComplexTypeInfo.cpp b/src/xercesc/validators/schema/ComplexTypeInfo.cpp index c5137efeb1a55a4f939a6972c77b4f1bef67bd06..8a2dbc6854cc2f8d97a57090f748a0b2b45c4822 100644 --- a/src/xercesc/validators/schema/ComplexTypeInfo.cpp +++ b/src/xercesc/validators/schema/ComplexTypeInfo.cpp @@ -261,7 +261,7 @@ ComplexTypeInfo* ComplexTypeInfo::getAnyType(unsigned int emptyNSId) { XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); if (!sAnyTypeMutex) - sAnyTypeMutex = new XMLMutex; + sAnyTypeMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); } // Use a faux scope to synchronize while we do this diff --git a/src/xercesc/validators/schema/GeneralAttributeCheck.cpp b/src/xercesc/validators/schema/GeneralAttributeCheck.cpp index 459a5dfdce6fd23e188db92f08e9c0ae7e712a35..7132c4630ef9a56512b99af8ed69448b2ade035f 100644 --- a/src/xercesc/validators/schema/GeneralAttributeCheck.cpp +++ b/src/xercesc/validators/schema/GeneralAttributeCheck.cpp @@ -264,7 +264,7 @@ void GeneralAttributeCheck::mapElements() XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex); if (!sGeneralAttCheckMutex) - sGeneralAttCheckMutex = new XMLMutex; + sGeneralAttCheckMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); } // Use a faux scope to synchronize while we do this diff --git a/src/xercesc/validators/schema/XSDErrorReporter.cpp b/src/xercesc/validators/schema/XSDErrorReporter.cpp index 5d814a49cc525acd913beaf56c6f120dfaee7b40..2833a031d946040d8a61df23fb8d1ceea958e579 100644 --- a/src/xercesc/validators/schema/XSDErrorReporter.cpp +++ b/src/xercesc/validators/schema/XSDErrorReporter.cpp @@ -111,7 +111,7 @@ static XMLMutex& getErrRprtrMutex() if (!sErrRprtrMutex) { - sErrRprtrMutex = new XMLMutex; + sErrRprtrMutex = new XMLMutex(XMLPlatformUtils::fgMemoryManager); errRprtrMutexCleanup.registerCleanup(reinitErrRprtrMutex); } }