[mapguide-commits] r5295 - in trunk/MgDev/Common: CoordinateSystem Geometry

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Tue Oct 19 12:32:00 EDT 2010


Author: brucedechant
Date: 2010-10-19 09:32:00 -0700 (Tue, 19 Oct 2010)
New Revision: 5295

Added:
   trunk/MgDev/Common/CoordinateSystem/CriticalSection.cpp
   trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.cpp
   trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.h
Modified:
   trunk/MgDev/Common/CoordinateSystem/CriticalSection.h
   trunk/MgDev/Common/Geometry/Geometry.vcproj
   trunk/MgDev/Common/Geometry/Makefile.am
Log:
Fix for trac ticket 1463 - Access to the CsMap coordinate system dictionary files is not correctly protected by the Mg API
http://trac.osgeo.org/mapguide/ticket/1463

Notes:
- Moves the CriticalClass into a separate source file

Submitted on behalf of Andr?\195?\169 Barth


Added: trunk/MgDev/Common/CoordinateSystem/CriticalSection.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CriticalSection.cpp	                        (rev 0)
+++ trunk/MgDev/Common/CoordinateSystem/CriticalSection.cpp	2010-10-19 16:32:00 UTC (rev 5295)
@@ -0,0 +1,83 @@
+#ifdef _WIN32
+#   include <Windows.h>
+#else
+#  include <pthread.h>
+#  ifndef __bsdi__
+#    include <semaphore.h>
+#  endif
+#endif
+
+#include "CriticalSection.h"
+
+#ifdef _WIN32
+    CRITICAL_SECTION CritSect;
+#else //LINUX
+    pthread_mutex_t CritSect;
+    pthread_mutexattr_t CritSectAttributes;
+#endif
+
+//declare the "global" instance of our CustomCriticalSection object we're using throughout the whole process
+CustomCriticalSection CriticalClass;
+
+CustomCriticalSection::CustomCriticalSection()
+{
+    m_bInitialized = false;
+    Initialize();
+}
+
+#ifdef _WIN32
+
+CustomCriticalSection::~CustomCriticalSection()
+{
+    ::DeleteCriticalSection(&CritSect);
+}
+
+void CustomCriticalSection::Initialize()
+{
+    if(!m_bInitialized)
+    {
+        m_bInitialized = true;
+        ::InitializeCriticalSection(&CritSect);
+    }
+}
+
+void CustomCriticalSection::Enter()
+{
+    ::EnterCriticalSection(&CritSect);
+}
+
+void CustomCriticalSection::Leave()
+{
+    ::LeaveCriticalSection(&CritSect);
+}
+
+#else //LINUX
+
+CustomCriticalSection::~CustomCriticalSection()
+{
+    pthread_mutex_destroy(&CritSect);
+}
+
+void CustomCriticalSection::Initialize()
+{
+    if(!m_bInitialized)
+    {
+        m_bInitialized = true;
+        pthread_mutexattr_init(&CritSectAttributes);
+        pthread_mutexattr_settype(&CritSectAttributes, PTHREAD_MUTEX_RECURSIVE);
+        pthread_mutex_init(&CritSect, &CritSectAttributes);
+        pthread_mutexattr_destroy(&CritSectAttributes);
+    }
+}
+
+void CustomCriticalSection::Enter()
+{
+    pthread_mutex_lock(&CritSect);
+}
+
+void CustomCriticalSection::Leave()
+{
+    pthread_mutex_unlock(&CritSect);
+}
+
+#endif //_WIN32


Property changes on: trunk/MgDev/Common/CoordinateSystem/CriticalSection.cpp
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/MgDev/Common/CoordinateSystem/CriticalSection.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/CriticalSection.h	2010-10-19 06:23:47 UTC (rev 5294)
+++ trunk/MgDev/Common/CoordinateSystem/CriticalSection.h	2010-10-19 16:32:00 UTC (rev 5295)
@@ -18,120 +18,24 @@
 #ifndef CRITICALSECTION_H_
 #define CRITICALSECTION_H_
 
-#ifndef _WIN32
-#  include <pthread.h>
-#  ifndef __bsdi__
-#    include <semaphore.h>
-#  endif
-#endif
+#include "SmartCriticalClass.h"
 
-// Critical Section Class
 class CustomCriticalSection
 {
 public:
+    CustomCriticalSection();
+    ~CustomCriticalSection();
 
-    CustomCriticalSection()
-    {
-        m_bInitialized = false;
-        Initialize();
-    }
+    void Initialize();
 
-#ifdef _WIN32
+    void Enter();
+    void Leave();
 
-    ~CustomCriticalSection()
-    {
-        ::DeleteCriticalSection(&m_CritSect);
-    }
-
-    void Initialize()
-    {
-        if(!m_bInitialized)
-        {
-            m_bInitialized = true;
-            ::InitializeCriticalSection(&m_CritSect);
-        }
-    }
-
-    void Enter()
-    {
-        ::EnterCriticalSection(&m_CritSect);
-    }
-
-    void Leave()
-    {
-        ::LeaveCriticalSection(&m_CritSect);
-    }
-
 private:
-    CRITICAL_SECTION m_CritSect;
-
-#else //LINUX
-
-    ~CustomCriticalSection()
-    {
-        pthread_mutex_destroy(&m_CritSect);
-    }
-
-    void Initialize()
-    {
-        if(!m_bInitialized)
-        {
-            m_bInitialized = true;
-            pthread_mutexattr_init(&m_attributes);
-            pthread_mutexattr_settype(&m_attributes, PTHREAD_MUTEX_RECURSIVE);
-            pthread_mutex_init(&m_CritSect, &m_attributes);
-            pthread_mutexattr_destroy(&m_attributes);
-        }
-    }
-
-    void Enter()
-    {
-        pthread_mutex_lock(&m_CritSect);
-    }
-
-    void Leave()
-    {
-        pthread_mutex_unlock(&m_CritSect);
-    }
-
-private:
-    pthread_mutex_t m_CritSect;
-    pthread_mutexattr_t m_attributes;
-
-#endif //_WIN32
-
-private:
     bool m_bInitialized;
 };
 
-// This is used to protect library calls
-static CustomCriticalSection CriticalClass;
+//This is used to protect *all* library calls - make sure, all comilation units refer to the same instance
+extern CustomCriticalSection CriticalClass;
 
-class SmartCriticalClass
-{
-public:
-    SmartCriticalClass(bool bEnter):m_bEntered(bEnter)
-    {
-        if (bEnter)
-        {
-            CriticalClass.Enter();
-        }
-    }
-    void Enter()
-    {
-        m_bEntered=true;
-        CriticalClass.Enter();
-    }
-    ~SmartCriticalClass()
-    {
-        if (m_bEntered)
-        {
-            CriticalClass.Leave();
-        }
-    }
-private:
-    SmartCriticalClass();
-    bool m_bEntered;
-};
-
 #endif //CRITICALSECTION_H_

Added: trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.cpp
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.cpp	                        (rev 0)
+++ trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.cpp	2010-10-19 16:32:00 UTC (rev 5295)
@@ -0,0 +1,26 @@
+#include "CriticalSection.h"
+
+//utility implementation to access the central "CriticalClass critical section"
+//
+SmartCriticalClass::SmartCriticalClass(bool bEnter)
+    :m_bEntered(bEnter)
+{
+    if (bEnter)
+    {
+        CriticalClass.Enter();
+    }
+}
+
+SmartCriticalClass::~SmartCriticalClass()
+{
+    if (m_bEntered)
+    {
+        CriticalClass.Leave();
+    }
+}
+
+void SmartCriticalClass::Enter()
+{
+    m_bEntered = true;
+    CriticalClass.Enter();
+}


Property changes on: trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.cpp
___________________________________________________________________
Added: svn:eol-style
   + native

Added: trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.h
===================================================================
--- trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.h	                        (rev 0)
+++ trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.h	2010-10-19 16:32:00 UTC (rev 5295)
@@ -0,0 +1,33 @@
+//
+//  Copyright (C) 2004-2010 by Autodesk, Inc.
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of version 2.1 of the GNU Lesser
+//  General Public License as published by the Free Software Foundation.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+//
+
+#ifndef SMARTCRITICALCLASS_H_
+#define SMARTCRITICALCLASS_H_
+
+class SmartCriticalClass
+{
+public:
+    SmartCriticalClass(bool bEnter);
+    ~SmartCriticalClass();
+
+    void Enter();
+
+private:
+    bool m_bEntered;
+};
+
+#endif //SMARTCRITICALCLASS_H_


Property changes on: trunk/MgDev/Common/CoordinateSystem/SmartCriticalClass.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/MgDev/Common/Geometry/Geometry.vcproj
===================================================================
--- trunk/MgDev/Common/Geometry/Geometry.vcproj	2010-10-19 06:23:47 UTC (rev 5294)
+++ trunk/MgDev/Common/Geometry/Geometry.vcproj	2010-10-19 16:32:00 UTC (rev 5295)
@@ -3135,6 +3135,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\CoordinateSystem\CriticalSection.cpp"
+				>
+			</File>
+			<File
 				RelativePath="..\CoordinateSystem\CriticalSection.h"
 				>
 			</File>
@@ -3166,6 +3170,14 @@
 				RelativePath="..\CoordinateSystem\namestruct.h"
 				>
 			</File>
+			<File
+				RelativePath="..\CoordinateSystem\SmartCriticalClass.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\CoordinateSystem\SmartCriticalClass.h"
+				>
+			</File>
 		</Filter>
 		<File
 			RelativePath=".\AgfReaderWriter.cpp"

Modified: trunk/MgDev/Common/Geometry/Makefile.am
===================================================================
--- trunk/MgDev/Common/Geometry/Makefile.am	2010-10-19 06:23:47 UTC (rev 5294)
+++ trunk/MgDev/Common/Geometry/Makefile.am	2010-10-19 16:32:00 UTC (rev 5295)
@@ -51,7 +51,9 @@
   ../CoordinateSystem/CoordSysMgrs.cpp \
   ../CoordinateSystem/CoordSysMgrsMajorRegion.cpp \
   ../CoordinateSystem/CoordSysOneGrid.cpp \
-  ../CoordinateSystem/namestruct.cpp
+  ../CoordinateSystem/namestruct.cpp \
+  ../CoordinateSystem/CriticalSection.cpp \
+  ../CoordinateSystem/SmartCriticalClass.cpp
 
 include_SOURCES = \
   AgfReaderWriter.cpp \
@@ -197,7 +199,9 @@
   ../CoordinateSystem/CoordSysMgrsZone.cpp \
   ../CoordinateSystem/CoordSysMgrs.cpp \
   ../CoordinateSystem/CoordSysMgrsMajorRegion.cpp \
-  ../CoordinateSystem/CoordSysOneGrid.cpp
+  ../CoordinateSystem/CoordSysOneGrid.cpp \
+  ../CoordinateSystem/CriticalSection.cpp \
+  ../CoordinateSystem/SmartCriticalClass.cpp
 
 noinst_HEADERS = $(include_SOURCES) \
   AgfReaderWriter.h \
@@ -408,6 +412,7 @@
   ../CoordinateSystem/CoordSysType.h \
   ../CoordinateSystem/CoordSysUtil.h \
   ../CoordinateSystem/CriticalSection.h \
+  ../CoordinateSystem/SmartCriticalClass.h \
   ../CoordinateSystem/CoordSysDictionaryUtility.h \
   ../CoordinateSystem/CoordSysEnumInteger32.h \
   ../CoordinateSystem/CoordSysMathComparator.h \



More information about the mapguide-commits mailing list