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 2009/02/18 06:51:29 UTC

svn commit: r745390 - in /xerces/c/branches/xerces-3.0/src/xercesc/util: MutexManagers/WindowsMutexMgr.cpp Mutexes.cpp Mutexes.hpp

Author: borisk
Date: Wed Feb 18 05:51:29 2009
New Revision: 745390

URL: http://svn.apache.org/viewvc?rev=745390&view=rev
Log:
Rework the XMLMutex fix one more time. This time, wrap the critical section
in WindowsMutexMgr into an XMemory type so that it keeps track of the
memory manager automatically. This way we avoid the second allocation and
remain binary-compatible with 3.0.0.

Modified:
    xerces/c/branches/xerces-3.0/src/xercesc/util/MutexManagers/WindowsMutexMgr.cpp
    xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.cpp
    xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.hpp

Modified: xerces/c/branches/xerces-3.0/src/xercesc/util/MutexManagers/WindowsMutexMgr.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/src/xercesc/util/MutexManagers/WindowsMutexMgr.cpp?rev=745390&r1=745389&r2=745390&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/src/xercesc/util/MutexManagers/WindowsMutexMgr.cpp (original)
+++ xerces/c/branches/xerces-3.0/src/xercesc/util/MutexManagers/WindowsMutexMgr.cpp Wed Feb 18 05:51:29 2009
@@ -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.
@@ -21,11 +21,20 @@
 
 #include <windows.h>
 
+#include <xercesc/util/XMemory.hpp>
 #include <xercesc/util/MutexManagers/WindowsMutexMgr.hpp>
 #include <xercesc/framework/MemoryManager.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
+// Wrap up the critical section with XMemory
+//
+class CSWrap: public XMemory
+{
+public:
+  CRITICAL_SECTION cs;
+};
+
 WindowsMutexMgr::WindowsMutexMgr()
 {
 }
@@ -39,33 +48,38 @@
 XMLMutexHandle
 WindowsMutexMgr::create(MemoryManager* const manager)
 {
-    CRITICAL_SECTION* newCS=(CRITICAL_SECTION*)manager->allocate(sizeof(CRITICAL_SECTION));
-    InitializeCriticalSection(newCS);
-    return newCS;
+    CSWrap* mutex = new (manager) CSWrap;
+    InitializeCriticalSection(&mutex->cs);
+    return mutex;
 }
 
 
 void
-WindowsMutexMgr::destroy(XMLMutexHandle mtx, MemoryManager* const manager)
+WindowsMutexMgr::destroy(XMLMutexHandle mtx, MemoryManager* const)
 {
-    ::DeleteCriticalSection((LPCRITICAL_SECTION)mtx);
-    manager->deallocate(mtx);
+    CSWrap* mutex = (CSWrap*)mtx;
+    if (mutex != 0)
+    {
+      ::DeleteCriticalSection(&mutex->cs);
+      delete mutex;
+    }
 }
 
 
 void
 WindowsMutexMgr::lock(XMLMutexHandle mtx)
 {
-    ::EnterCriticalSection((LPCRITICAL_SECTION)mtx);
+    CSWrap* mutex = (CSWrap*)mtx;
+    ::EnterCriticalSection(&mutex->cs);
 }
 
 
 void
 WindowsMutexMgr::unlock(XMLMutexHandle mtx)
 {
-    ::LeaveCriticalSection((LPCRITICAL_SECTION)mtx);
+    CSWrap* mutex = (CSWrap*)mtx;
+    ::LeaveCriticalSection(&mutex->cs);
 }
 
 
 XERCES_CPP_NAMESPACE_END
-

Modified: xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.cpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.cpp?rev=745390&r1=745389&r2=745390&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.cpp (original)
+++ xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.cpp Wed Feb 18 05:51:29 2009
@@ -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.
@@ -30,38 +30,24 @@
 
 XERCES_CPP_NAMESPACE_BEGIN
 
-struct MutexData: XMemory
-{
-  void*          fHandle;
-  MemoryManager* fManager;
-};
-
 // ---------------------------------------------------------------------------
 //  XMLMutex: Constructors and Destructor
 // ---------------------------------------------------------------------------
 XMLMutex::XMLMutex(MemoryManager* const manager) :
-    fData(0)
-{
-  fData = new (manager) MutexData;
 
-  if (fData)
-  {
-    ((MutexData*)fData)->fManager = manager;
+    fHandle(0)
+{
     // Ask the per-platform driver to make us a mutex
-    ((MutexData*)fData)->fHandle = XMLPlatformUtils::makeMutex(manager);
-  }
+    fHandle = XMLPlatformUtils::makeMutex(manager);
 }
 
 
 XMLMutex::~XMLMutex()
 {
-    if (fData)
+    if (fHandle)
     {
-      if (((MutexData*)fData)->fHandle)
-        XMLPlatformUtils::closeMutex(((MutexData*)fData)->fHandle,
-                                     ((MutexData*)fData)->fManager);
-
-      delete ((MutexData*)fData);
+        XMLPlatformUtils::closeMutex(fHandle);
+        fHandle = 0;
     }
 }
 
@@ -71,12 +57,12 @@
 // ---------------------------------------------------------------------------
 void XMLMutex::lock()
 {
-    XMLPlatformUtils::lockMutex(((MutexData*)fData)->fHandle);
+    XMLPlatformUtils::lockMutex(fHandle);
 }
 
 void XMLMutex::unlock()
 {
-    XMLPlatformUtils::unlockMutex(((MutexData*)fData)->fHandle);
+    XMLPlatformUtils::unlockMutex(fHandle);
 }
 
 

Modified: xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.hpp
URL: http://svn.apache.org/viewvc/xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.hpp?rev=745390&r1=745389&r2=745390&view=diff
==============================================================================
--- xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.hpp (original)
+++ xerces/c/branches/xerces-3.0/src/xercesc/util/Mutexes.hpp Wed Feb 18 05:51:29 2009
@@ -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.
@@ -56,10 +56,12 @@
     // -----------------------------------------------------------------------
     //  Private data members
     //
-    //  fData
-    //      Internal data structure (3.0.1 only).
+    //  fHandle
+    //      The raw mutex handle. Its just a void pointer so we do not
+    //      pass judgement on its value at all. We just pass it into the
+    //      platform utilities methods which knows what's really in it.
     // -----------------------------------------------------------------------
-    void*          fData;
+    void*   fHandle;
 
 
     // -----------------------------------------------------------------------



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