[mapguide-commits] r1044 - branches/1.1.x/MgDev/Common/CoordinateSystem

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Jan 12 18:10:54 EST 2007


Author: brucedechant
Date: 2007-01-12 18:10:54 -0500 (Fri, 12 Jan 2007)
New Revision: 1044

Modified:
   branches/1.1.x/MgDev/Common/CoordinateSystem/CoordSys.cpp
   branches/1.1.x/MgDev/Common/CoordinateSystem/CriticalSection.h
Log:
Add critical sections around coordinate system APIs.

Modified: branches/1.1.x/MgDev/Common/CoordinateSystem/CoordSys.cpp
===================================================================
--- branches/1.1.x/MgDev/Common/CoordinateSystem/CoordSys.cpp	2007-01-12 22:53:47 UTC (rev 1043)
+++ branches/1.1.x/MgDev/Common/CoordinateSystem/CoordSys.cpp	2007-01-12 23:10:54 UTC (rev 1044)
@@ -48,14 +48,19 @@
     }
     ~CInitCPL()
     {
-        // free PROJ4 resources
-        pj_deallocate_grids();
+        {
+            // Lock all threads
+            AutoCriticalClass acc;
 
-        // free CPL resources
-        CSVDeaccess(NULL);
-        CPLFinderClean();
-        CPLCleanupTLS();
+            // free PROJ4 resources
+            pj_deallocate_grids();
 
+            // free CPL resources
+            CSVDeaccess(NULL);
+            CPLFinderClean();
+            CPLCleanupTLS();
+        }
+
         // free CoordinateSystem resources
         CCoordinateSystem::DeleteCatalog();
     }
@@ -232,6 +237,9 @@
 ///</summary>
 CCoordinateSystem::CCoordinateSystem(CREFSTRING ogcWkt)
 {
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         m_latLonSrs = NULL;
@@ -294,7 +302,7 @@
 
                 // Set the units
                 wchar_t* csUnits = Convert_Ascii_To_Wide(units);
-                m_units = csUnits;
+                m_units = (NULL == csUnits) ? L"" : csUnits;
                 delete [] csUnits;
                 csUnits = NULL;
 
@@ -417,7 +425,7 @@
                                     message += L" ";
                                     message += strError;
 
-                                    delete strError;
+                                    delete [] strError;
                                     strError = NULL;
                                 }
 
@@ -483,7 +491,7 @@
                             message += L" ";
                             message += strError;
 
-                            delete strError;
+                            delete [] strError;
                             strError = NULL;
                         }
 
@@ -588,7 +596,7 @@
                     message += L" ";
                     message += strError;
 
-                    delete strError;
+                    delete [] strError;
                     strError = NULL;
                 }
 
@@ -691,6 +699,9 @@
     x = 0.0;
     y = 0.0;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Check to see if the conversion is allowed, if not throw an exception
@@ -741,6 +752,9 @@
 ///</returns>
 void CCoordinateSystem::ConvertFromLonLat(double lon[], double lat[], double x[], double y[], int arraySize)
 {
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         double dCoords[3] = { 0.0, 0.0, 0.0 };
@@ -802,6 +816,9 @@
     lat = 0.0;
     lon = 0.0;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Check to see if the conversion is allowed, if not throw an exception
@@ -852,6 +869,9 @@
 ///</returns>
 void CCoordinateSystem::ConvertToLonLat(double x[], double y[], double lon[], double lat[], int arraySize)
 {
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         double dCoords[3] = { 0.0, 0.0, 0.0 };
@@ -1024,6 +1044,9 @@
         throw new CInvalidCoordinateSystemTypeException(L"CCoordinateSystem.MeasureGreatCircleDistance", __LINE__, __WFILE__, L"MeasureGreatCircleDistance does not work with Arbitrary coordinate systems.");
     }
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Calculate Great Circle distance using the following formula:
@@ -1127,6 +1150,9 @@
 {
     double azimuth = 0.0;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         if(m_coordinateSystemType == CCoordinateSystemType::Arbitrary)
@@ -1250,6 +1276,9 @@
     x = 0.0;
     y = 0.0;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         if(m_coordinateSystemType == CCoordinateSystemType::Arbitrary)
@@ -1364,6 +1393,9 @@
     char* proj4 = NULL;
     wchar_t* csProj4 = NULL;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Initialize the catalog cache if it has not been created yet
@@ -1488,7 +1520,7 @@
             message += L" ";
             message += strError;
 
-            delete strError;
+            delete [] strError;
             strError = NULL;
         }
 
@@ -1524,6 +1556,9 @@
     wchar_t* csWkt = NULL;
     char* wkt = NULL;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Initialize the catalog cache if it has not been created yet
@@ -1687,7 +1722,7 @@
             message += L" ";
             message += strError;
 
-            delete strError;
+            delete [] strError;
             strError = NULL;
         }
 
@@ -1965,7 +2000,8 @@
     if(m_catalog == NULL )
     {
         // Lock all threads while we create the catalog
-        CriticalClass.Enter();
+        AutoCriticalClass acc;
+
         // We have to check for NULL again because we might have been locked out by another
         // thread that just finished initializing the catalog.
         if(m_catalog == NULL )
@@ -1973,7 +2009,6 @@
             // Create the catalog. We only want to do this once!
             m_catalog = new CCoordinateSystemCatalog();
         }
-        CriticalClass.Leave();
 
         // Throw exception if we failed to initialize the catalog
         if (m_catalog == NULL)
@@ -1989,12 +2024,10 @@
     if (m_catalog != NULL)
     {
         // Lock all threads while we delete the catalog
-        CriticalClass.Enter();
+        AutoCriticalClass acc;
 
         delete m_catalog;
         m_catalog = NULL;
-
-        CriticalClass.Leave();
     }
 }
 
@@ -2019,6 +2052,9 @@
     OGRErr error = OGRERR_NONE;
     char* epsgWkt = NULL;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Initialize the catalog cache if it has not been created yet
@@ -2093,7 +2129,7 @@
         message += strCode;
         message += L"\" to WKT.";
 
-        delete strCode;
+        delete [] strCode;
         strCode = NULL;
 
         if(error)
@@ -2102,7 +2138,7 @@
             message += L" ";
             message += strError;
 
-            delete strError;
+            delete [] strError;
             strError = NULL;
         }
 
@@ -2117,6 +2153,9 @@
     long code;
     OGRErr error = OGRERR_NONE;
 
+    // Lock all threads
+    AutoCriticalClass acc;
+
     try
     {
         // Initialize the catalog cache if it has not been created yet
@@ -2187,7 +2226,7 @@
         
         STRING message = L"Failed to convert WKT to EPSG code.";
 
-        delete strCode;
+        delete [] strCode;
         strCode = NULL;
 
         if(error)
@@ -2196,7 +2235,7 @@
             message += L" ";
             message += strError;
 
-            delete strError;
+            delete [] strError;
             strError = NULL;
         }
 

Modified: branches/1.1.x/MgDev/Common/CoordinateSystem/CriticalSection.h
===================================================================
--- branches/1.1.x/MgDev/Common/CoordinateSystem/CriticalSection.h	2007-01-12 22:53:47 UTC (rev 1043)
+++ branches/1.1.x/MgDev/Common/CoordinateSystem/CriticalSection.h	2007-01-12 23:10:54 UTC (rev 1044)
@@ -109,4 +109,19 @@
 // This is used to protect library calls
 static CustomCriticalSection CriticalClass;
 
+class AutoCriticalClass
+{
+public:
+
+    AutoCriticalClass()
+    {
+        CriticalClass.Enter();
+    }
+
+    ~AutoCriticalClass()
+    {
+        CriticalClass.Leave();
+    }
+};
+
 #endif



More information about the mapguide-commits mailing list