From b844914335a32184e2bf5e166adef7c240e65a18 Mon Sep 17 00:00:00 2001 From: Tinny Ng <tng@apache.org> Date: Thu, 25 Oct 2001 15:20:31 +0000 Subject: [PATCH] Need to guard with NO_APP_THREADS when destroying the mutex. git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@173167 13f79535-47bb-0310-9956-ffa450edef68 --- src/util/Platforms/HPUX/HPPlatformUtils.cpp | 5 ++ .../Platforms/Linux/LinuxPlatformUtils.cpp | 37 ++++++------ .../Solaris/SolarisPlatformUtils.cpp | 56 +++++++++--------- .../UnixWare/UnixWarePlatformUtils.cpp | 57 ++++++++++--------- 4 files changed, 86 insertions(+), 69 deletions(-) diff --git a/src/util/Platforms/HPUX/HPPlatformUtils.cpp b/src/util/Platforms/HPUX/HPPlatformUtils.cpp index daf79c2b1..75b79ae1c 100644 --- a/src/util/Platforms/HPUX/HPPlatformUtils.cpp +++ b/src/util/Platforms/HPUX/HPPlatformUtils.cpp @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.17 2001/10/25 15:20:31 tng + * Need to guard with NO_APP_THREADS when destroying the mutex. + * * Revision 1.16 2001/10/23 23:10:00 peiyongz * [Bug#880] patch to PlatformUtils:init()/term() and related. from Mark Weaver * @@ -751,8 +754,10 @@ int XMLPlatformUtils::atomicDecrement(int &location) void XMLPlatformUtils::platformTerm() { +#if !defined(APP_NO_THREADS) // delete the mutex we created closeMutex(atomicOpsMutex.fHandle); atomicOpsMutex.fHandle = 0; +#endif } diff --git a/src/util/Platforms/Linux/LinuxPlatformUtils.cpp b/src/util/Platforms/Linux/LinuxPlatformUtils.cpp index b20914bae..aa4ed0d8d 100644 --- a/src/util/Platforms/Linux/LinuxPlatformUtils.cpp +++ b/src/util/Platforms/Linux/LinuxPlatformUtils.cpp @@ -1,37 +1,37 @@ /* * The Apache Software License, Version 1.1 - * + * * Copyright (c) 1999-2000 The Apache Software Foundation. All rights * reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * + * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this - * software without prior written permission. For written + * software without prior written permission. For written * permission, please contact apache\@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -45,7 +45,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== - * + * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation, and was * originally based on software copyright (c) 1999, International @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.21 2001/10/25 15:20:31 tng + * Need to guard with NO_APP_THREADS when destroying the mutex. + * * Revision 1.20 2001/10/23 23:10:48 peiyongz * [Bug#880] patch to PlatformUtils:init()/term() and related. from Mark Weaver * @@ -414,7 +417,7 @@ void XMLPlatformUtils::panic(const PanicReasons reason) reasonStr = "Cannot initialize the system or mutex"; fprintf(stderr, "%s\n", reasonStr); - + exit(-1); } @@ -546,10 +549,10 @@ XMLCh* XMLPlatformUtils::getFullPath(const XMLCh* const srcPath) // Use a local buffer that is big enough for the largest legal path char *absPath = new char[PATH_MAX]; - // get the absolute path - char* retPath = realpath(newSrc, absPath); + // get the absolute path + char* retPath = realpath(newSrc, absPath); ArrayJanitor<char> janText2(retPath); - + if (!retPath) { ThrowXML(XMLPlatformUtilsException, XMLExcepts::File_CouldNotGetBasePathName); @@ -734,8 +737,10 @@ int XMLPlatformUtils::atomicDecrement(int &location) void XMLPlatformUtils::platformTerm() { +#if !defined(APP_NO_THREADS) // delete the mutex we created closeMutex(atomicOpsMutex.fHandle); atomicOpsMutex.fHandle = 0; +#endif } diff --git a/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp b/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp index 5a3ed801d..4e33e599e 100644 --- a/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp +++ b/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp @@ -1,37 +1,37 @@ /* * The Apache Software License, Version 1.1 - * + * * Copyright (c) 1999-2000 The Apache Software Foundation. All rights * reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * + * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this - * software without prior written permission. For written + * software without prior written permission. For written * permission, please contact apache\@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -45,7 +45,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== - * + * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation, and was * originally based on software copyright (c) 1999, International @@ -216,7 +216,7 @@ XMLTransService* XMLPlatformUtils::makeTransService() // --------------------------------------------------------------------------- void XMLPlatformUtils::panic(const PanicReasons reason) { - + const char* reasonStr = "Unknown reason"; if (reason == Panic_NoTransService) reasonStr = "Could not load a transcoding service"; @@ -234,7 +234,7 @@ void XMLPlatformUtils::panic(const PanicReasons reason) reasonStr = "Cannot initialize the system or mutex"; fprintf(stderr, "%s\n", reasonStr); - + exit(-1); } @@ -285,7 +285,7 @@ unsigned int XMLPlatformUtils::fileSize(FileHandle theFile) return (unsigned int)retVal; } -FileHandle XMLPlatformUtils::openFile(const char* const fileName) +FileHandle XMLPlatformUtils::openFile(const char* const fileName) { FileHandle retVal = (FILE*)fopen( fileName , "rb" ); @@ -299,7 +299,7 @@ FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) const char* tmpFileName = XMLString::transcode(fileName); ArrayJanitor<char> janText((char*)tmpFileName); FileHandle retVal = (FILE*)fopen( tmpFileName , "rb" ); - + if (retVal == NULL) return 0; return retVal; @@ -340,7 +340,7 @@ void XMLPlatformUtils::resetFile(FileHandle theFile) #if defined (SOLARIS) extern "C" int ftime(struct timeb *); // Solaris headers missing this decl #endif - + unsigned long XMLPlatformUtils::getCurrentMillis() { timeb aTime; @@ -502,7 +502,7 @@ XMLCh* XMLPlatformUtils::weavePaths // ----------------------------------------------------------------------- -// Mutex methods +// Mutex methods // ----------------------------------------------------------------------- #if !defined (APP_NO_THREADS) @@ -516,14 +516,14 @@ static pthread_mutex_t* gAtomicOpMutex =0 ; void XMLPlatformUtils::platformInit() { // - // The gAtomicOpMutex mutex needs to be created - // because compareAndSwap and incrementlocation and decrementlocation + // The gAtomicOpMutex mutex needs to be created + // because compareAndSwap and incrementlocation and decrementlocation // does not have the atomic system calls for usage // 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 pthread_mutex_t; #if defined(XML_USE_DCE) if (pthread_mutex_init(gAtomicOpMutex, pthread_mutexattr_default)) { @@ -549,7 +549,7 @@ public: int recursionCount; pthread_t tid; - RecursiveMutex() { + RecursiveMutex() { if (pthread_mutex_init(&mutex, NULL)) ThrowXML(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotCreate); recursionCount = 0; @@ -653,12 +653,12 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) // ----------------------------------------------------------------------- // Miscellaneous synchronization methods // ----------------------------------------------------------------------- -//atomic system calls in Solaris is only restricted to kernel libraries -//So, to make operations thread safe we implement static mutex and lock +//atomic system calls in Solaris is only restricted to kernel libraries +//So, to make operations thread safe we implement static mutex and lock //the atomic operations. It makes the process slow but what's the alternative! -void* XMLPlatformUtils::compareAndSwap ( void** toFill , - const void* const newValue , +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , const void* const toCompare) { //return ((void*)cas32( (uint32_t*)toFill, (uint32_t)toCompare, (uint32_t)newValue) ); @@ -698,7 +698,7 @@ int XMLPlatformUtils::atomicDecrement(int &location) if (pthread_mutex_lock( gAtomicOpMutex)) panic(XMLPlatformUtils::Panic_SynchronizationErr); - + int tmp = --location; if (pthread_mutex_unlock( gAtomicOpMutex)) @@ -761,8 +761,10 @@ FileHandle XMLPlatformUtils::openStdInHandle() void XMLPlatformUtils::platformTerm() { +#if !defined(APP_NO_THREADS) pthread_mutex_destroy(gAtomicOpMutex); delete gAtomicOpMutex; gAtomicOpMutex = 0; +#endif } diff --git a/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp b/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp index 9532deac6..ab3e1c6c2 100644 --- a/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp +++ b/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp @@ -1,37 +1,37 @@ /* * The Apache Software License, Version 1.1 - * + * * Copyright (c) 1999-2000 The Apache Software Foundation. All rights * reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: - * + * * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * + * notice, this list of conditions and the following disclaimer. + * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. - * + * * 3. The end-user documentation included with the redistribution, - * if any, must include the following acknowledgment: + * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. - * + * * 4. The names "Xerces" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this - * software without prior written permission. For written + * software without prior written permission. For written * permission, please contact apache\@apache.org. - * + * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. - * + * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -45,7 +45,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== - * + * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation, and was * originally based on software copyright (c) 1999, International @@ -56,6 +56,9 @@ /* * $Log$ + * Revision 1.11 2001/10/25 15:20:31 tng + * Need to guard with NO_APP_THREADS when destroying the mutex. + * * Revision 1.10 2001/10/23 23:13:09 peiyongz * [Bug#880] patch to PlatformUtils:init()/term() and related. from Mark Weaver * @@ -267,7 +270,7 @@ void XMLPlatformUtils::panic(const PanicReasons reason) reasonStr = "Cannot initialize the system or mutex"; fprintf(stderr, "%s\n", reasonStr); - + exit(-1); } @@ -323,7 +326,7 @@ FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) const char* tmpFileName = XMLString::transcode(fileName); ArrayJanitor<char> janText((char*)tmpFileName); FileHandle retVal = (FILE*)fopen( tmpFileName , "rb" ); - + if (retVal == NULL) return 0; return retVal; @@ -332,7 +335,7 @@ FileHandle XMLPlatformUtils::openFile(const XMLCh* const fileName) FileHandle XMLPlatformUtils::openFile(const char* const fileName) { FileHandle retVal = (FILE*)fopen( fileName , "rb" ); - + if (retVal == NULL) return 0; return retVal; @@ -388,7 +391,7 @@ XMLCh* XMLPlatformUtils::weavePaths(const XMLCh* const basePath XMLString::copyString(tmpBuf, relativePath); return tmpBuf; } - + if (!*basePath) { XMLString::copyString(tmpBuf, relativePath); @@ -531,7 +534,7 @@ unsigned long XMLPlatformUtils::getCurrentMillis() // ----------------------------------------------------------------------- -// Mutex methods +// Mutex methods // ----------------------------------------------------------------------- #if !defined (APP_NO_THREADS) @@ -544,14 +547,14 @@ static pthread_mutex_t* gAtomicOpMutex =0 ; void XMLPlatformUtils::platformInit() { // - // The gAtomicOpMutex mutex needs to be created + // The gAtomicOpMutex mutex needs to be created // because compareAndSwap, atomicIncrement and atomicDecrement // does not have the atomic system calls for usage // 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 pthread_mutex_t; if (pthread_mutex_init(gAtomicOpMutex, NULL)) panic( XMLPlatformUtils::Panic_SystemInit ); @@ -564,7 +567,7 @@ public: int recursionCount; pthread_t tid; - RecursiveMutex() { + RecursiveMutex() { if (pthread_mutex_init(&mutex, NULL)) ThrowXML(XMLPlatformUtilsException, XMLExcepts::Mutex_CouldNotCreate); recursionCount = 0; @@ -633,12 +636,12 @@ void XMLPlatformUtils::unlockMutex(void* const mtxHandle) // ----------------------------------------------------------------------- // Miscellaneous synchronization methods // ----------------------------------------------------------------------- -//atomic system calls in UnixWare is only restricted to kernel libraries -//So, to make operations thread safe we implement static mutex and lock +//atomic system calls in UnixWare is only restricted to kernel libraries +//So, to make operations thread safe we implement static mutex and lock //the atomic operations. It makes the process slow but what's the alternative! -void* XMLPlatformUtils::compareAndSwap ( void** toFill , - const void* const newValue , +void* XMLPlatformUtils::compareAndSwap ( void** toFill , + const void* const newValue , const void* const toCompare) { if (pthread_mutex_lock( gAtomicOpMutex)) @@ -730,8 +733,10 @@ int XMLPlatformUtils::atomicDecrement(int &location) void XMLPlatformUtils::platformTerm() { +#if !defined (APP_NO_THREADS) // delete the mutex we created - closeMutex(atomicOpsMutex.fHandle); - atomicOpsMutex.fHandle = 0; + closeMutex(gAtomicOpMutex.fHandle); + gAtomicOpMutex.fHandle = 0; +#endif } -- GitLab