You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by bo...@apache.org on 2008/03/09 13:04:42 UTC

svn commit: r635226 [2/2] - in /xerces/c/trunk: ./ Projects/Win32/BCB6/Xerces-all/XercesLib/ Projects/Win32/BCC.551/Xerces-all/XercesLib/ Projects/Win32/VC6/xerces-all/XercesLib/ Projects/Win32/VC7.1/xerces-all/XercesLib/ Projects/Win32/VC8/xerces-all/...

Modified: xerces/c/trunk/src/xercesc/util/PlatformUtils.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/PlatformUtils.cpp?rev=635226&r1=635225&r2=635226&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/PlatformUtils.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/PlatformUtils.cpp Sun Mar  9 05:04:39 2008
@@ -71,20 +71,6 @@
 #	include <xercesc/util/MutexManagers/WindowsMutexMgr.hpp>
 #endif
 
-#include <xercesc/util/XMLAtomicOpMgr.hpp>
-#if XERCES_USE_ATOMICOPMGR_NOTHREAD
-#	include <xercesc/util/AtomicOpManagers/NoThreadAtomicOpMgr.hpp>
-#endif
-#if XERCES_USE_ATOMICOPMGR_POSIX
-#	include <xercesc/util/AtomicOpManagers/PosixAtomicOpMgr.hpp>
-#endif
-#if XERCES_USE_ATOMICOPMGR_MACOS
-#	include <xercesc/util/AtomicOpManagers/MacOSAtomicOpMgr.hpp>
-#endif
-#if XERCES_USE_ATOMICOPMGR_WINDOWS
-#	include <xercesc/util/AtomicOpManagers/WindowsAtomicOpMgr.hpp>
-#endif
-
 #include <xercesc/util/XMLNetAccessor.hpp>
 #if XERCES_USE_NETACCESSOR_CURL
 #	include <xercesc/util/NetAccessors/Curl/CurlNetAccessor.hpp>
@@ -177,11 +163,10 @@
 
 XMLFileMgr*             XMLPlatformUtils::fgFileMgr = 0;
 XMLMutexMgr*            XMLPlatformUtils::fgMutexMgr = 0;
-XMLAtomicOpMgr*         XMLPlatformUtils::fgAtomicOpMgr = 0;
 
-XMLMutex*				XMLPlatformUtils::fgAtomicMutex = 0;
+XMLMutex*               XMLPlatformUtils::fgAtomicMutex = 0;
 
-bool					XMLPlatformUtils::fgXMLChBigEndian = true;
+bool                    XMLPlatformUtils::fgXMLChBigEndian = true;
 
 // ---------------------------------------------------------------------------
 //  XMLPlatformUtils: Init/term methods
@@ -252,9 +237,8 @@
     fgXMLChBigEndian = (endianTest.ar[sizeof(XMLCh)-1] == 1);
 
 
-    // Initialize the platform-specific mutex file, and atomic op mgrs
+    // Initialize the platform-specific mutex and file mgrs
     fgMutexMgr		= makeMutexMgr(fgMemoryManager);
-    fgAtomicOpMgr	= makeAtomicOpMgr(fgMemoryManager);
     fgFileMgr		= makeFileMgr(fgMemoryManager);
 
 
@@ -327,10 +311,10 @@
     if (gInitFlag == 0)
         return;
 
-	gInitFlag--;
+    gInitFlag--;
 
-	if (gInitFlag > 0)
-		return;
+    if (gInitFlag > 0)
+	return;
 
     // Delete any net accessor that got installed
     delete fgNetAccessor;
@@ -351,21 +335,20 @@
     delete gSyncMutex;		gSyncMutex = 0;
     delete fgAtomicMutex;	fgAtomicMutex = 0;
 
-	// Clean up statically allocated, lazily cleaned data in each class
-	// that has registered for it.
-	// Note that calling doCleanup() also unregisters the cleanup
-	// function, so that we are chewing the list down to nothing here
-	while (gXMLCleanupList)
-		gXMLCleanupList->doCleanup();
-
-	// Clean up the mutex for accessing gXMLCleanupList
-	delete gXMLCleanupListMutex;
-	gXMLCleanupListMutex = 0;
-
-	// Clean up our mgrs
-	delete fgFileMgr;		fgFileMgr = 0;
-	delete fgAtomicOpMgr;	fgAtomicOpMgr = 0;
-	delete fgMutexMgr;		fgMutexMgr = 0;
+    // Clean up statically allocated, lazily cleaned data in each class
+    // that has registered for it.
+    // Note that calling doCleanup() also unregisters the cleanup
+    // function, so that we are chewing the list down to nothing here
+    while (gXMLCleanupList)
+        gXMLCleanupList->doCleanup();
+
+    // Clean up the mutex for accessing gXMLCleanupList
+    delete gXMLCleanupListMutex;
+    gXMLCleanupListMutex = 0;
+
+    // Clean up our mgrs
+    delete fgFileMgr;		fgFileMgr = 0;
+    delete fgMutexMgr;		fgMutexMgr = 0;
 
     /***
      *  de-allocate resource
@@ -771,62 +754,6 @@
 
 	fgMutexMgr->unlock(mtx);
 }
-
-
-// -----------------------------------------------------------------------
-//  Miscellaneous synchronization methods
-// -----------------------------------------------------------------------
-XMLAtomicOpMgr* XMLPlatformUtils::makeAtomicOpMgr(MemoryManager* const memmgr)
-{
-	XMLAtomicOpMgr* mgr = NULL;
-
-	#if XERCES_USE_ATOMICOPMGR_NOTHREAD
-		mgr = new (memmgr) NoThreadAtomicOpMgr;
-	#elif XERCES_USE_ATOMICOPMGR_POSIX
-		mgr = new (memmgr) PosixAtomicOpMgr;
-	#elif XERCES_USE_ATOMICOPMGR_MACOS
-		mgr = new (memmgr) MacOSAtomicOpMgr;
-	#elif XERCES_USE_ATOMICOPMGR_WINDOWS
-		mgr = new (memmgr) WindowsAtomicOpMgr;
-	#else
-		#error No AtomicOp Manager configured for platform! You must configure it.
-	#endif
-
-	return mgr;
-}
-
-
-void* XMLPlatformUtils::compareAndSwap(void**            toFill
-                                     , const void* const newValue
-                                     , const void* const toCompare)
-{
-    if (!fgAtomicOpMgr)
-		ThrowXML(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero);
-
-	return fgAtomicOpMgr->compareAndSwap(toFill, newValue, toCompare);
-}
-
-
-/* These two routines are disabled pending further comment. They are unused in Xerces at present.
-int XMLPlatformUtils::atomicIncrement(int &location)
-{
-    if (!fgAtomicOpMgr)
-		ThrowXML(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero);
-
-	return fgAtomicOpMgr->increment(location);
-}
-
-
-int XMLPlatformUtils::atomicDecrement(int &location)
-{
-    if (!fgAtomicOpMgr)
-		ThrowXML(XMLPlatformUtilsException, XMLExcepts::CPtr_PointerIsZero);
-
-	return fgAtomicOpMgr->decrement(location);
-}
-*/
-
-
 
 // ---------------------------------------------------------------------------
 //  XMLPlatformUtils: Msg support methods

Modified: xerces/c/trunk/src/xercesc/util/PlatformUtils.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/PlatformUtils.hpp?rev=635226&r1=635225&r2=635226&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/PlatformUtils.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/PlatformUtils.hpp Sun Mar  9 05:04:39 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -28,7 +28,6 @@
 
 #include <xercesc/util/XMLFileMgr.hpp>
 #include <xercesc/util/XMLMutexMgr.hpp>
-#include <xercesc/util/XMLAtomicOpMgr.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -104,14 +103,14 @@
 
     /** The Panic Handler
       *
-      *   This is the application provided panic handler. 
+      *   This is the application provided panic handler.
       */
     static PanicHandler*        fgUserPanicHandler;
-    
+
     /** The Panic Handler
       *
-      *   This is the default panic handler. 
-      */    
+      *   This is the default panic handler.
+      */
     static PanicHandler*        fgDefaultPanicHandler;
 
     /** The configurable memory manager
@@ -120,15 +119,20 @@
       *   application, a default implementation is used.
       */
     static MemoryManager*       fgMemoryManager;
-    
+
     static XMLFileMgr*          fgFileMgr;
     static XMLMutexMgr*         fgMutexMgr;
-    static XMLAtomicOpMgr*      fgAtomicOpMgr;
-    
+
+    /** Global mutex for fast or infrequent operations.
+      *
+      *   Use this mutex only for fast (e.g., increment an integer,
+      *   check flag, etc.) or infrequent (e.g., once-off initialization)
+      *   operations.
+      */
     static XMLMutex*            fgAtomicMutex;
-    
+
     static bool                 fgXMLChBigEndian;
-    
+
     //@}
 
 
@@ -157,8 +161,8 @@
       *          as well.
       *
       * panicHandler: application's panic handler, application owns this handler.
-      *               Application shall make sure that the plugged panic handler persists 
-      *               through the call to XMLPlatformUtils::terminate().       
+      *               Application shall make sure that the plugged panic handler persists
+      *               through the call to XMLPlatformUtils::terminate().
       *
       * memoryManager: plugged-in memory manager which is owned by user
       *                applications. Applications must make sure that the
@@ -192,14 +196,14 @@
       * In case the default panic handler does not support a particular
       * platform, the platform specific panic hanlding shall be implemented
       * here </p>.
-      * 
+      *
       * @param reason The enumeration that defines the cause of the failure
       */
     static void panic
     (
         const   PanicHandler::PanicReasons    reason
     );
-    
+
     //@}
 
     /** @name File Methods */
@@ -210,7 +214,7 @@
       * @param manager The MemoryManager to use to allocate objects
       */
     static XMLFileMgr* makeFileMgr(MemoryManager* const manager);
-    
+
     /** Get the current file position
       *
       * This must be implemented by the per-platform driver, which should
@@ -407,12 +411,12 @@
         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
     );
 
-    /** Gets the current working directory 
+    /** Gets the current working directory
       *
-      * This must be implemented by the per-platform driver. It returns 
-      * the current working directory is. 
+      * This must be implemented by the per-platform driver. It returns
+      * the current working directory is.
       * @param manager The MemoryManager to use to allocate objects
-      * @return Returns the current working directory. 
+      * @return Returns the current working directory.
       *         This is dyanmically allocated and must be deleted
       *         by the caller when its no longer needed! The memory returned
       *         will be allocated using the static memory manager, if users
@@ -427,7 +431,7 @@
 
     /** Check if a charater is a slash
       *
-      * This must be implemented by the per-platform driver. 
+      * This must be implemented by the per-platform driver.
       *
       * @param c the character to be examined
       *
@@ -435,20 +439,20 @@
       *         false otherwise
       */
     static inline bool isAnySlash(XMLCh c);
-    
-    /** Remove occurences of the pair of dot slash 
+
+    /** Remove occurences of the pair of dot slash
       *
       * To remove the sequence, dot slash if it is part of the sequence,
       * slash dot slash.
       *
       * @param srcPath The path for which you want to remove the dot slash sequence.
       * @param manager The MemoryManager to use to allocate objects
-      * @return 
+      * @return
       */
     static void   removeDotSlash(XMLCh* const srcPath
         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
 
-    /** Remove occurences of the dot dot slash 
+    /** Remove occurences of the dot dot slash
       *
       * To remove the sequence, slash dot dot slash and its preceding path segment
       * if and only if the preceding path segment is not slash dot dot slash.
@@ -456,7 +460,7 @@
       * @param srcPath The path for which you want to remove the slash dot
       *        dot slash sequence and its preceding path segment.
       * @param manager The MemoryManager to use to allocate objects
-      * @return 
+      * @return
       */
     static void   removeDotDotSlash(XMLCh* const srcPath
         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
@@ -593,104 +597,6 @@
 
     //@}
 
-    /** @name Miscellaneous synchronization methods */
-    //@{
-
-    /** Factory method for creating MutexMgr object.
-      *
-      * This factory method creates an XMLAtomicOpMgr that will be used
-      * on the particular platform.
-      *
-      * @param manager The MemoryManager to use to allocate objects
-      */
-    static XMLAtomicOpMgr* makeAtomicOpMgr(MemoryManager* const manager);
-
-
-    /** Conditionally updates or returns a single word variable atomically
-      *
-      * This must be implemented by the per-platform driver. The
-      * compareAndSwap subroutine performs an atomic operation which
-      * compares the contents of a single word variable with a stored old
-      * value. If the values are equal, a new value is stored in the single
-      * word variable and the comparison value is returned; otherwise,
-      * no value is stored and the current contents of the stored location
-      * are returned.
-      *
-      * The compareAndSwap subroutine is useful when a word value must be
-      * updated only if it has not been changed since it was last read.
-      *
-      * Note: The word containing the single word variable must be aligned
-      * on a full word boundary.
-      *
-      * @param toFill Specifies the address of the single word variable
-      * @param newValue Specifies the new value to be conditionally assigned
-      * to the single word variable.
-      * @param toCompare Specifies the address of the old value to be checked
-      * against (and conditionally updated with) the value of the single word
-      * variable.
-      *
-      * @return Returns the initial contents of the single word variable.
-      */
-    static void* compareAndSwap
-    (
-                void**      toFill
-        , const void* const newValue
-        , const void* const toCompare
-    );
-
-    //@}
-
-
-    /** @name Atomic Increment and Decrement */
-    //@{
-
-    /** Increments a single word variable atomically.
-      *
-      * This must be implemented by the per-platform driver. The
-      * atomicIncrement subroutine increments one word in a single atomic
-      * operation. This operation is useful when a counter variable is shared
-      * between several threads or processes. When updating such a counter
-      * variable, it is important to make sure that the fetch, update, and
-      * store operations occur atomically (are not interruptible).
-      *
-      * @param location Specifies the address of the word variable to be
-      * incremented.
-      *
-      * @return The function return value is positive if the result of the
-      * operation was positive. Zero if the result of the operation was zero.
-      * Negative if the result of the operation was negative. Except for the
-      * zero case, the value returned may differ from the actual result of
-      * the operation - only the sign and zero/nonzero state is guaranteed
-      * to be correct.
-      
-      * disabled for now pending further comment (unused)
-    static int atomicIncrement(int& location);
-      */
-
-    /** Decrements a single word variable atomically.
-      *
-      * This must be implemented by the per-platform driver. The
-      * atomicDecrement subroutine increments one word in a single atomic
-      * operation. This operation is useful when a counter variable is shared
-      * between several threads or processes. When updating such a counter
-      * variable, it is important to make sure that the fetch, update, and
-      * store operations occur atomically (are not interruptible).
-      *
-      * @param location Specifies the address of the word variable to be
-      * decremented.
-      *
-      * @return The function return value is positive if the result of the
-      * operation was positive. Zero if the result of the operation was zero.
-      * Negative if the result of the operation was negative. Except for the
-      * zero case, the value returned may differ from the actual result of the
-      * operation - only the sign and zero/nonzero state is guaranteed to be
-      * correct.
-      
-      * disabled for now pending further comment (unused)
-    static int atomicDecrement(int& location);
-      */
-
-    //@}
 
     /** @name NEL Character Handling  */
     //@{
@@ -733,7 +639,7 @@
       */
     static bool isStrictIANAEncoding();
     //@}
-        
+
     /**
       * Aligns the specified pointer per platform block allocation
       * requirements.
@@ -845,10 +751,10 @@
 #else
     static const size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double);
 #endif
-    
+
     //    Calculate current alignment of pointer
     size_t current = ptrSize % alignment;
-    
+
     //    Adjust pointer alignment as needed
     return (current == 0)
          ? ptrSize

Modified: xerces/c/trunk/src/xercesc/util/TransService.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/TransService.cpp?rev=635226&r1=635225&r2=635226&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/TransService.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/TransService.cpp Sun Mar  9 05:04:39 2008
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,6 +34,7 @@
 #include <xercesc/util/XMLWin1252Transcoder.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xercesc/util/XMLUni.hpp>
+#include <xercesc/util/Mutexes.hpp>
 #include <xercesc/util/EncodingValidator.hpp>
 #include <xercesc/util/XMLRegisterCleanup.hpp>
 #include <xercesc/util/PlatformUtils.hpp>
@@ -73,29 +74,27 @@
 // ---------------------------------------------------------------------------
 XMLTransService::XMLTransService()
 {
-    if (!gMappings) {
-        RefHashTableOf<ENameMap>* t = new RefHashTableOf<ENameMap>(103);
+    if (!gMappings)
+    {
+        XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex);
 
-        if (XMLPlatformUtils::compareAndSwap((void **)&gMappings, t, 0) != 0)
-        {
-            delete t;
-        }
-        else
+        if (!gMappings)
         {
-            mappingsCleanup.registerCleanup(reinitMappings);
+          gMappings = new RefHashTableOf<ENameMap>(103);
+          mappingsCleanup.registerCleanup(reinitMappings);
         }
     }
 
-    if (!gMappingsRecognizer) {
-        RefVectorOf<ENameMap>* t = new RefVectorOf<ENameMap>(XMLRecognizer::Encodings_Count);
+    if (!gMappingsRecognizer)
+    {
+        XMLMutexLock lock(XMLPlatformUtils::fgAtomicMutex);
 
-        if (XMLPlatformUtils::compareAndSwap((void **)&gMappingsRecognizer, t, 0) != 0)
+        if (!gMappingsRecognizer)
         {
-            delete t;
-        }
-        else
-        {
-            mappingsRecognizerCleanup.registerCleanup(reinitMappingsRecognizer);
+          gMappingsRecognizer = new RefVectorOf<ENameMap>(
+            XMLRecognizer::Encodings_Count);
+
+          mappingsRecognizerCleanup.registerCleanup(reinitMappingsRecognizer);
         }
     }
 }
@@ -165,7 +164,7 @@
 
     // If we found it, then call the factory method for it
     if (ourMapping)
-	{		
+	{
        XMLTranscoder* temp = ourMapping->makeNew(blockSize, manager);
        resValue = temp ? XMLTransService::Ok : XMLTransService::InternalFailure;
        return temp;
@@ -204,7 +203,7 @@
     ENameMap* ourMapping = gMappingsRecognizer->elementAt(encodingEnum);
 
     // If we found it, then call the factory method for it
-    if (ourMapping)	{		
+    if (ourMapping)	{
        XMLTranscoder* temp = ourMapping->makeNew(blockSize, manager);
        resValue = temp ? XMLTransService::Ok : XMLTransService::InternalFailure;
        return temp;
@@ -533,7 +532,7 @@
                             , const XMLSize_t       blockSize
                             , MemoryManager* const  manager) :
       fBlockSize(blockSize)
-    , fEncodingName(0)    
+    , fEncodingName(0)
     , fMemoryManager(manager)
 {
     fEncodingName = XMLString::replicate(encodingName, fMemoryManager);

Modified: xerces/c/trunk/src/xercesc/util/XMemory.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMemory.cpp?rev=635226&r1=635225&r2=635226&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMemory.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMemory.cpp Sun Mar  9 05:04:39 2008
@@ -62,8 +62,9 @@
 {
     assert(manager != 0);
 	
-	size_t headerSize = XMLPlatformUtils::alignPointerForNewBlockAllocation(
-										sizeof(MemoryManager*));
+    size_t headerSize = XMLPlatformUtils::alignPointerForNewBlockAllocation(
+       sizeof(MemoryManager*));
+       
     void* const block = manager->allocate(headerSize + size);
     *(MemoryManager**)block = manager;
 
@@ -79,8 +80,8 @@
 {
     if (p != 0)
     {
-		size_t headerSize = XMLPlatformUtils::alignPointerForNewBlockAllocation(
-											sizeof(MemoryManager*));
+        size_t headerSize = XMLPlatformUtils::alignPointerForNewBlockAllocation(
+          sizeof(MemoryManager*));
         void* const block = (char*)p - headerSize;
 
         MemoryManager* const manager = *(MemoryManager**)block;



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org