[prev in list] [next in list] [prev in thread] [next in thread]
List: xerces-cvs
Subject: cvs commit: xml-xerces/c/tests/DOM/DOMTest DTest.cpp
From: andyh () locus ! apache ! org
Date: 2000-01-29 0:39:10
[Download RAW message or body]
andyh 00/01/28 16:39:09
Modified: c/samples/DOMPrint DOMPrint.cpp
c/src/dom DOMString.cpp DOMStringImpl.hpp
c/tests/DOM/DOMMemTest DOMMemTest.cpp
c/tests/DOM/DOMTest DTest.cpp
Log:
Redo synchronization in DOMStringHandle allocator. There
was a bug in the use of Compare and Swap. Switched to mutexes.
Changed a few plain deletes to delete [].
Revision Changes Path
1.4 +7 -5 xml-xerces/c/samples/DOMPrint/DOMPrint.cpp
Index: DOMPrint.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/samples/DOMPrint/DOMPrint.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DOMPrint.cpp 1999/12/03 00:14:52 1.3
+++ DOMPrint.cpp 2000/01/29 00:39:08 1.4
@@ -56,6 +56,12 @@
/**
* $Log: DOMPrint.cpp,v $
+ * Revision 1.4 2000/01/29 00:39:08 andyh
+ * Redo synchronization in DOMStringHandle allocator. There
+ * was a bug in the use of Compare and Swap. Switched to mutexes.
+ *
+ * Changed a few plain deletes to delete [].
+ *
* Revision 1.3 1999/12/03 00:14:52 andyh
* Removed transcoding stuff, replaced with DOMString::transcode.
*
@@ -233,7 +239,6 @@
{
cerr << "An error occured during parsing\n Message: "
<< DOMString(e.getMessage()) << endl;
- // << StrX(e.getMessage()) << endl;
errorsOccured = true;
}
@@ -449,7 +454,6 @@
default:
// If it is none of the special characters, print it as such
- // target << StrX(&chars[index], 1);
target << toWrite.substringData(index, 1);
break;
}
@@ -470,10 +474,8 @@
// ---------------------------------------------------------------------------
ostream& operator<<(ostream& target, const DOMString& s)
{
- //if (s.length() > 0)
- // target << StrX(s.rawBuffer(), s.length());
char *p = s.transcode();
target << p;
- delete p;
+ delete [] p;
return target;
}
1.8 +60 -50 xml-xerces/c/src/dom/DOMString.cpp
Index: DOMString.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/DOMString.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- DOMString.cpp 2000/01/18 19:55:37 1.7
+++ DOMString.cpp 2000/01/29 00:39:08 1.8
@@ -56,6 +56,12 @@
/**
* $Log: DOMString.cpp,v $
+ * Revision 1.8 2000/01/29 00:39:08 andyh
+ * Redo synchronization in DOMStringHandle allocator. There
+ * was a bug in the use of Compare and Swap. Switched to mutexes.
+ *
+ * Changed a few plain deletes to delete [].
+ *
* Revision 1.7 2000/01/18 19:55:37 andyh
* Remove dependencies on XMLStdout and err, as these are about
* to stop working.
@@ -189,66 +195,72 @@
// memory allocator.
+//
+// There is one global mutex that is used to synchronize access to the
+// allocator free list for DOMStringHandles. This function gets that
+// mutex, and will create it on the first attempt to get it.
+//
+XMLMutex& DOMStringHandle::getMutex()
+{
+ static XMLMutex* DOMStringHandleMutex = 0;
+ if (!DOMStringHandleMutex)
+ {
+ XMLMutex* tmpMutex = new XMLMutex;
+ if (XMLPlatformUtils::compareAndSwap((void**)&DOMStringHandleMutex, tmpMutex, 0))
+ {
+ // Someone beat us to it, so let's clean up ours
+ delete tmpMutex;
+ }
+ }
+ return *DOMStringHandleMutex;
+}
+
+
+//
+// Operator new for DOMStringHandles. Called implicitly from the
+// DOMStringHandle constructor.
+//
void *DOMStringHandle::operator new(size_t sizeToAlloc)
{
assert(sizeToAlloc == sizeof(DOMStringHandle));
void *retPtr;
- void *oldFreeListPtr;
-
- do
+ XMLMutexLock lock(&getMutex()); // Lock the DOMStringHandle mutex for
+ // the duration of this function.
+
+ if (freeListPtr == 0)
{
- retPtr = freeListPtr; // In the common case, freeListPtr points
- // to an available string handle, and
- // this will be the block we return.
-
- if (retPtr == 0)
- {
- // Uncommon case. The free list of string handles is empty
- // and we must allocate a new batch of them, using
- // the system's operator new.
- //
- // Link all but one of these new StringHandles into our free list by
- // deleting them with DOMStringHandle::operator delete.
- // Unconditionally return the one that we didn't put in the free list.
- //
- // There is a remote chance that two threads could see the free list
- // as empty at about the same time and both fall into this code.
- // No great harm will result - the free list will have twice the
- // usual number of new free handles added to it. It's not worth
- // any added code complexity to prevent it from happening.
- DOMStringHandle *dsg =
- ::new DOMStringHandle[allocGroupSize];
- int i;
- for (i=1; i<allocGroupSize-1; i++)
- delete &dsg[i];
-
- return &dsg[0];
- }
-
- // Thread-safe (atomic) update of freeListPtr.
- oldFreeListPtr = XMLPlatformUtils::compareAndSwap(&freeListPtr, *(void **)retPtr, retPtr);
- }
- // This loop will normally exit the first time through. It will only repeat if,
- // in a multi-threaded environment, some second thread updated the free list ptr
- // in the interval between when we looked at it (retPtr = freeListPtr;) and when
- // we attempted to update it ourselves with the compareAndSwap().
- while (oldFreeListPtr != retPtr);
-
+ // Uncommon case. The free list of string handles is empty
+ // Allocate a new batch of them, using the system's
+ // operator new to get a chunk of memory.
+ //
+ // Link all of these new StringHandles into our free list
+ //
+ DOMStringHandle *dsg =
+ ::new DOMStringHandle[allocGroupSize];
+ int i;
+ for (i=0; i<allocGroupSize-1; i++) {
+ *(void **)&dsg[i] = freeListPtr;
+ freeListPtr = &dsg[i];
+ }
+ }
+
+ retPtr = freeListPtr;
+ freeListPtr = *(void **)freeListPtr;
+
return retPtr;
};
-
+//
+// Operator delete for DOMStringHandles. Called implicitly from the
+// Destructor for DOMStringHandle.
+//
void DOMStringHandle::operator delete(void *pMem)
{
- void *initialFreeListPtr;
- void *oldFreeListPtr;
- do
- {
- *(void **)pMem = initialFreeListPtr = freeListPtr;
- oldFreeListPtr = XMLPlatformUtils::compareAndSwap(&freeListPtr, pMem, initialFreeListPtr);
- }
- while (oldFreeListPtr != initialFreeListPtr);
+ XMLMutexLock lock(&getMutex()); // Lock the DOMStringHandle mutex for the
+ // duration of this function.
+ *(void **)pMem = freeListPtr;
+ freeListPtr = pMem;
};
@@ -783,7 +795,7 @@
fputs(pc, stdout);
delete [] buffer;
- delete pc;
+ delete [] pc;
};
};
1.3 +5 -0 xml-xerces/c/src/dom/DOMStringImpl.hpp
Index: DOMStringImpl.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/dom/DOMStringImpl.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DOMStringImpl.hpp 2000/01/12 19:55:14 1.2
+++ DOMStringImpl.hpp 2000/01/29 00:39:08 1.3
@@ -59,6 +59,12 @@
/**
* $Log: DOMStringImpl.hpp,v $
+ * Revision 1.3 2000/01/29 00:39:08 andyh
+ * Redo synchronization in DOMStringHandle allocator. There
+ * was a bug in the use of Compare and Swap. Switched to mutexes.
+ *
+ * Changed a few plain deletes to delete [].
+ *
* Revision 1.2 2000/01/12 19:55:14 aruna1
* Included header for size_t
*
@@ -79,6 +85,7 @@
#include <util/XML4CDefs.hpp>
+#include <util/Mutexes.hpp>
#include <stdio.h>
@@ -113,6 +120,7 @@
~DOMStringHandle() {};
private:
inline DOMStringHandle() {};
+ static inline XMLMutex &getMutex();
};
1.10 +9 -7 xml-xerces/c/tests/DOM/DOMMemTest/DOMMemTest.cpp
Index: DOMMemTest.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/tests/DOM/DOMMemTest/DOMMemTest.cpp,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DOMMemTest.cpp 2000/01/22 01:38:32 1.9
+++ DOMMemTest.cpp 2000/01/29 00:39:09 1.10
@@ -66,6 +66,12 @@
/**
* $Log: DOMMemTest.cpp,v $
+ * Revision 1.10 2000/01/29 00:39:09 andyh
+ * Redo synchronization in DOMStringHandle allocator. There
+ * was a bug in the use of Compare and Swap. Switched to mutexes.
+ *
+ * Changed a few plain deletes to delete [].
+ *
* Revision 1.9 2000/01/22 01:38:32 andyh
* Remove compiler warnings in DOM impl classes
*
@@ -163,7 +169,7 @@
char *pMessage = XMLString::transcode(toCatch.getMessage());
fprintf(stderr, "Error during XMLPlatformUtils::Initialize(). \n"
" Message is: %s\n", pMessage);
- delete pMessage;
+ delete [] pMessage;
return -1;
}
@@ -780,7 +786,7 @@
DOMString DOMTestStr = testStr;
char *roundTripString = DOMTestStr.transcode();
TASSERT(strcmp(testStr, roundTripString) == 0);
- delete roundTripString;
+ delete [] roundTripString;
}
TESTEPILOG;
@@ -954,8 +960,6 @@
-
-
//
// CreateElementNS methods
//
@@ -1198,6 +1202,7 @@
//
TESTPROLOG;
{
+
// Set up an initial (root element only) document.
//
DOM_DOMImplementation impl;
@@ -1226,19 +1231,19 @@
DOM_Attr attre = doc.createAttributeNS("http://nse", "attrb");
rootEl.setAttributeNodeNS(attre);
-
//
// Check that the attribute nodes were created with the correct properties.
//
- TASSERT(attra.getNodeName().equals("a.attra"));
+ TASSERT(attra.getNodeName().equals("a:attra"));
TASSERT(attra.getNamespaceURI().equals("http://nsa"));
TASSERT(attra.getLocalName().equals("attra"));
- TASSERT(attra.getName().equals("a.attra"));
+ TASSERT(attra.getName().equals("a:attra"));
TASSERT(attra.getNodeType() == DOM_Node::ATTRIBUTE_NODE);
TASSERT(attra.getNodeValue().equals(""));
TASSERT(attra.getPrefix().equals("a"));
TASSERT(attra.getSpecified() == true);
TASSERT(attra.getValue().equals(""));
+
}
TESTEPILOG;
1.4 +9 -1 xml-xerces/c/tests/DOM/DOMTest/DTest.cpp
Index: DTest.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/tests/DOM/DOMTest/DTest.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DTest.cpp 2000/01/19 21:40:58 1.3
+++ DTest.cpp 2000/01/29 00:39:09 1.4
@@ -56,6 +56,12 @@
/**
* $Log: DTest.cpp,v $
+ * Revision 1.4 2000/01/29 00:39:09 andyh
+ * Redo synchronization in DOMStringHandle allocator. There
+ * was a bug in the use of Compare and Swap. Switched to mutexes.
+ *
+ * Changed a few plain deletes to delete [].
+ *
* Revision 1.3 2000/01/19 21:40:58 andyh
* Remove a few remaining dependencies on the (now defunct)
* XML StdOut stream.
@@ -84,6 +90,12 @@
/**
* $Log: DTest.cpp,v $
+ * Revision 1.4 2000/01/29 00:39:09 andyh
+ * Redo synchronization in DOMStringHandle allocator. There
+ * was a bug in the use of Compare and Swap. Switched to mutexes.
+ *
+ * Changed a few plain deletes to delete [].
+ *
* Revision 1.3 2000/01/19 21:40:58 andyh
* Remove a few remaining dependencies on the (now defunct)
* XML StdOut stream.
@@ -478,7 +490,7 @@
catch (const XMLException& toCatch) {
char *pMessage = XMLString::transcode(toCatch.getMessage());
fprintf(stderr, "Error during initialization! \n %s \n", pMessage);
- delete pMessage;
+ delete [] pMessage;
return;
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic