[mapguide-commits] r6321 - in sandbox/adsk/vik/Common:
CoordinateSystem Foundation/System
svn_mapguide at osgeo.org
svn_mapguide at osgeo.org
Thu Dec 8 13:26:31 EST 2011
Author: traianstanev
Date: 2011-12-08 10:26:31 -0800 (Thu, 08 Dec 2011)
New Revision: 6321
Modified:
sandbox/adsk/vik/Common/CoordinateSystem/CoordSysCatalog.cpp
sandbox/adsk/vik/Common/Foundation/System/Disposable.cpp
sandbox/adsk/vik/Common/Foundation/System/Disposable.h
sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.cpp
sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.h
sandbox/adsk/vik/Common/Foundation/System/Ptr.h
Log:
Replaced usage of mutex by usage of atomic operations in MgGuardDisposable. Removed a boolean flag member var that was only used for debugging messages.
Modified: sandbox/adsk/vik/Common/CoordinateSystem/CoordSysCatalog.cpp
===================================================================
--- sandbox/adsk/vik/Common/CoordinateSystem/CoordSysCatalog.cpp 2011-12-08 17:55:54 UTC (rev 6320)
+++ sandbox/adsk/vik/Common/CoordinateSystem/CoordSysCatalog.cpp 2011-12-08 18:26:31 UTC (rev 6321)
@@ -119,17 +119,6 @@
m_pCtDict = NULL;
m_pGpDict = NULL;
m_pGxDict = NULL;
-
- //NOTE: the following behavior happens only in DEBUG if we do not reset the countFlag
- //If an exception is thrown from within the constructor of this MgDisposable derived class
- //is caught and then forwarded by MG_THROW()
- //then MgDisposable::~MgDisposable is called right away.
- //In the process of trying to build CCoordinateSystemCatalog the refcount has been bumped up by the constructors of the dictionary classes
- //catching the exception in turns bumps them down when releasing the objects
- //MgDisposable::m_refCountFlag is now equal to "true" and m_refCount is equal to 1
- //That triggers an ASSERTS in MgDisposable::~MgDisposable if we do not rest the flag to false:
- //ACE_ASSERT(m_refCountFlag ? (m_refCount == 0) : (m_refCount == 1));
- ResetRefCountFlag();
}
MG_THROW()
}
Modified: sandbox/adsk/vik/Common/Foundation/System/Disposable.cpp
===================================================================
--- sandbox/adsk/vik/Common/Foundation/System/Disposable.cpp 2011-12-08 17:55:54 UTC (rev 6320)
+++ sandbox/adsk/vik/Common/Foundation/System/Disposable.cpp 2011-12-08 18:26:31 UTC (rev 6321)
@@ -57,8 +57,6 @@
#endif
#endif
- m_refCountFlag = true;
-
if (0 == m_refCount)
{
#ifdef _DEBUG
@@ -90,8 +88,6 @@
#endif
#endif
- m_refCountFlag = true;
-
if (0 >= m_refCount)
{
#ifdef _DEBUG
@@ -116,23 +112,8 @@
//////////////////////////////////////////////////////////////
-void MgDisposable::SetRefCountFlag()
-{
- m_refCountFlag = true;
-}
-
-
-//////////////////////////////////////////////////////////////
-void MgDisposable::ResetRefCountFlag()
-{
- m_refCountFlag = false;
-}
-
-
-//////////////////////////////////////////////////////////////
MgDisposable::MgDisposable() :
- m_refCount(1),
- m_refCountFlag(false)
+ m_refCount(1)
{
}
@@ -140,16 +121,4 @@
//////////////////////////////////////////////////////////////
MgDisposable::~MgDisposable()
{
-#ifdef _DEBUG
- if ((m_refCountFlag) && (m_refCount != 0))
- {
- ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) ************ Error in MgDisposable::~MgDisposable(). Class Name: %W. Actual Reference Count: %d. Expected Reference Count: 0. This object should have been created on the heap instead of on the stack.\n"), GetClassName().c_str(), m_refCount));
- }
- else if ((!m_refCountFlag) && (m_refCount != 1))
- {
- ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) ************ Error in MgDisposable::~MgDisposable(). Class Name: %W. Actual Reference Count: %d. Expected Reference Count: 1. This object should have been created on the stack instead of on the heap.\n"), GetClassName().c_str(), m_refCount));
- }
-#endif
-
- ACE_ASSERT(m_refCountFlag ? (m_refCount == 0) : (m_refCount == 1));
}
Modified: sandbox/adsk/vik/Common/Foundation/System/Disposable.h
===================================================================
--- sandbox/adsk/vik/Common/Foundation/System/Disposable.h 2011-12-08 17:55:54 UTC (rev 6320)
+++ sandbox/adsk/vik/Common/Foundation/System/Disposable.h 2011-12-08 18:26:31 UTC (rev 6321)
@@ -74,15 +74,6 @@
///
virtual INT32 Release();
- //////////////////////////////////////////////////////////////////
- /// \brief
- /// Sets the ref count flag for this object to true.
- ///
- /// \return
- /// Returns nothing
- ///
- virtual void SetRefCountFlag();
-
protected:
//////////////////////////////////////////////////////////////////
@@ -103,15 +94,7 @@
///
virtual void Dispose() = 0;
- //////////////////////////////////////////////////////////////////
- /// \brief
- /// Resets the ref count flag for this object to false.
- ///
- /// \return
- /// Returns nothing
- ///
- void ResetRefCountFlag();
-
+
private:
// hidden copy constructor and assignment operator
@@ -123,7 +106,6 @@
friend class MgGuardDisposable;
INT32 m_refCount;
- bool m_refCountFlag;
#if WANT_ACE
#ifdef _DEBUG
Modified: sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.cpp
===================================================================
--- sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.cpp 2011-12-08 17:55:54 UTC (rev 6320)
+++ sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.cpp 2011-12-08 18:26:31 UTC (rev 6321)
@@ -22,8 +22,6 @@
//////////////////////////////////////////////////////////////
INT32 MgGuardDisposable::GetRefCount()
{
- MgLock lock(m_mutex);
-
return m_refCount;
}
@@ -31,46 +29,48 @@
//////////////////////////////////////////////////////////////
INT32 MgGuardDisposable::AddRef()
{
- MgLock lock(m_mutex);
-
- m_refCountFlag = true;
-
if (0 == m_refCount)
{
#ifdef _DEBUG
ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) ************ Error in MgGuardDisposable::Addref(). Class Name: %W. Called with Reference Count = 0.\n"), GetClassName().c_str()));
#endif
-
throw new MgException(L"MgGuardDisposable.AddRef", __LINE__, __WFILE__, NULL, L"Logic", NULL);
}
+#if defined (__GNUC__)
+ return __sync_add_and_fetch(&m_refCount,1);
+#elif defined(_WIN32)
+ return InterlockedIncrement((LONG*)&m_refCount);
+#else
return ++m_refCount;
+
+#endif
+
}
//////////////////////////////////////////////////////////////
INT32 MgGuardDisposable::Release()
{
+ if (0 >= m_refCount)
{
- MgLock lock(m_mutex);
-
- m_refCountFlag = true;
-
- if (0 >= m_refCount)
- {
#ifdef _DEBUG
- ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) ************ Error in MgGuardDisposable::Release(). Class Name: %W. Called with Reference Count <= 0.\n"), GetClassName().c_str()));
+ ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%t) ************ Error in MgGuardDisposable::Release(). Class Name: %W. Called with Reference Count <= 0.\n"), GetClassName().c_str()));
#endif
+ throw new MgException(L"MgGuardDisposable.Release", __LINE__, __WFILE__, NULL, L"Logic", NULL);
+ }
- throw new MgException(L"MgGuardDisposable.Release", __LINE__, __WFILE__, NULL, L"Logic", NULL);
- }
-
- --m_refCount;
-
- if (0 != m_refCount)
- {
+ #if defined (__GNUC__)
+ __sync_sub_and_fetch(&m_refCount, 1);
+#elif defined(_WIN32)
+ InterlockedDecrement((LONG*)&m_refCount);
+#else
+ --m_refCount;
+#endif
+
+ if (0 != m_refCount)
+ {
return m_refCount;
- }
}
// if we get here, the reference count must be zero, so dispose of this object
@@ -80,18 +80,11 @@
//////////////////////////////////////////////////////////////
-void MgGuardDisposable::SetRefCountFlag()
+MgGuardDisposable::MgGuardDisposable() : MgDisposable()
{
- MgLock lock(m_mutex);
- m_refCountFlag = true;
}
-//////////////////////////////////////////////////////////////
-MgGuardDisposable::MgGuardDisposable()
-{
-}
-
//////////////////////////////////////////////////////////////
MgGuardDisposable::~MgGuardDisposable()
{
Modified: sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.h
===================================================================
--- sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.h 2011-12-08 17:55:54 UTC (rev 6320)
+++ sandbox/adsk/vik/Common/Foundation/System/GuardDisposable.h 2011-12-08 18:26:31 UTC (rev 6321)
@@ -67,15 +67,13 @@
///
virtual INT32 Release();
- //////////////////////////////////////////////////////////////////
- /// \brief
- /// Sets the refcount flag for this object to true
- ///
- /// \return
- /// Returns nothing
- ///
- void SetRefCountFlag();
+private:
+ // hidden copy constructor and assignment operator
+ MgGuardDisposable(const MgGuardDisposable&);
+ MgGuardDisposable& operator=(const MgGuardDisposable&);
+
+
protected:
//////////////////////////////////////////////////////////////////
@@ -86,10 +84,6 @@
/// Returns nothing
///
MgGuardDisposable();
-
-private:
-
- MgMutex m_mutex;
};
/// \endcond
Modified: sandbox/adsk/vik/Common/Foundation/System/Ptr.h
===================================================================
--- sandbox/adsk/vik/Common/Foundation/System/Ptr.h 2011-12-08 17:55:54 UTC (rev 6320)
+++ sandbox/adsk/vik/Common/Foundation/System/Ptr.h 2011-12-08 18:26:31 UTC (rev 6321)
@@ -70,8 +70,6 @@
Ptr(T* lp) throw()
{
p = lp;
- if (p)
- p->SetRefCountFlag();
}
Ptr(const Ptr<T>& lp) throw()
@@ -136,8 +134,6 @@
SAFE_RELEASE(p);
p = lp;
- if (p)
- p->SetRefCountFlag();
return p;
}
More information about the mapguide-commits
mailing list