You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by kn...@apache.org on 2003/10/20 17:56:48 UTC
cvs commit: xml-xerces/c/src/xercesc/validators/datatype DatatypeValidatorFactory.cpp
knoaman 2003/10/20 08:56:48
Modified: c/src/xercesc/validators/datatype
DatatypeValidatorFactory.cpp
Log:
Fix multithreading problem.
Revision Changes Path
1.18 +37 -10 xml-xerces/c/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp
Index: DatatypeValidatorFactory.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/datatype/DatatypeValidatorFactory.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- DatatypeValidatorFactory.cpp 17 Oct 2003 21:13:05 -0000 1.17
+++ DatatypeValidatorFactory.cpp 20 Oct 2003 15:56:48 -0000 1.18
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.18 2003/10/20 15:56:48 knoaman
+ * Fix multithreading problem.
+ *
* Revision 1.17 2003/10/17 21:13:05 peiyongz
* Implement Serialization/Deserialization
*
@@ -390,6 +393,14 @@
// ---------------------------------------------------------------------------
+// Local static data
+// ---------------------------------------------------------------------------
+static bool sBuiltInRegistryMutexRegistered = false;
+static XMLMutex* sBuiltInRegistryMutex = 0;
+static XMLRegisterCleanup builtInRegistryCleanup;
+
+
+// ---------------------------------------------------------------------------
// DatatypeValidatorFactory: Static member data
// ---------------------------------------------------------------------------
RefHashTableOf<DatatypeValidator>* DatatypeValidatorFactory::fBuiltInRegistry = 0;
@@ -425,8 +436,14 @@
// Notification that lazy data has been deleted
// -----------------------------------------------------------------------
void DatatypeValidatorFactory::reinitRegistry() {
- delete fBuiltInRegistry;
- fBuiltInRegistry = 0;
+
+ delete fBuiltInRegistry;
+ fBuiltInRegistry = 0;
+
+ // delete local static data
+ delete sBuiltInRegistryMutex;
+ sBuiltInRegistryMutex = 0;
+ sBuiltInRegistryMutexRegistered = false;
}
// ---------------------------------------------------------------------------
@@ -434,17 +451,23 @@
// ---------------------------------------------------------------------------
void DatatypeValidatorFactory::expandRegistryToFullSchemaSet()
{
- static XMLRegisterCleanup builtInRegistryCleanup;
- // Initialize common Schema/DTD Datatype validator set if not initialized
- if (fBuiltInRegistry == 0) {
- RefHashTableOf<DatatypeValidator>* t = new RefHashTableOf<DatatypeValidator>(29);
- if (XMLPlatformUtils::compareAndSwap((void **)&fBuiltInRegistry, t, 0) != 0)
+ if (!sBuiltInRegistryMutexRegistered)
+ {
+ XMLMutex* tmpMutex = new XMLMutex;
+ if (XMLPlatformUtils::compareAndSwap((void**)&sBuiltInRegistryMutex, tmpMutex, 0))
{
- delete t;
+ // Someone beat us to it, so let's clean up ours
+ delete tmpMutex;
}
- else
+
+ // Now lock it and try to register it
+ XMLMutexLock lock(sBuiltInRegistryMutex);
+
+ // If we got here first, then register it and set the registered flag
+ if (!sBuiltInRegistryMutexRegistered)
{
- builtInRegistryCleanup.registerCleanup(reinitRegistry);
+ //Initialize common Schema/DTD Datatype validator set
+ fBuiltInRegistry = new RefHashTableOf<DatatypeValidator>(29);
DatatypeValidator *dv = new StringDatatypeValidator();
dv->setTypeName(SchemaSymbols::fgDT_STRING, SchemaSymbols::fgURI_SCHEMAFORSCHEMA);
@@ -725,6 +748,10 @@
createDatatypeValidator(SchemaSymbols::fgDT_POSITIVEINTEGER,
getDatatypeValidator(SchemaSymbols::fgDT_NONNEGATIVEINTEGER),
facets, 0, false, 0, false);
+
+ // register cleanup method
+ builtInRegistryCleanup.registerCleanup(reinitRegistry);
+ sBuiltInRegistryMutexRegistered = true;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org