From 5f8bb1a790e48650f65f34523efc133a140b6609 Mon Sep 17 00:00:00 2001 From: dooglus Date: Sun, 14 Oct 2007 23:28:40 +0000 Subject: [PATCH] Put mutexes around the reference counts for the shared_object class. Maybe this will help prevent crashes. git-svn-id: http://svn.voria.com/code@931 1f10aa63-cdf2-0310-b900-c93c546f37ac --- ETL/trunk/ETL/_handle.h | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ETL/trunk/ETL/_handle.h b/ETL/trunk/ETL/_handle.h index 83a9ab5..6a46f85 100644 --- a/ETL/trunk/ETL/_handle.h +++ b/ETL/trunk/ETL/_handle.h @@ -31,7 +31,13 @@ /* === H E A D E R S ======================================================= */ +// include the next line in an attempt to increase stability +#define ETL_LOCK_REFCOUNTS + #include +#ifdef ETL_LOCK_REFCOUNTS +#include +#endif /* === M A C R O S ========================================================= */ @@ -66,6 +72,9 @@ class shared_object { private: mutable int refcount; +#ifdef ETL_LOCK_REFCOUNTS + mutable Glib::Mutex mutex; +#endif protected: shared_object():refcount(0) { } @@ -78,11 +87,19 @@ protected: public: void ref()const - { assert(refcount>=0); refcount++; } + { +#ifdef ETL_LOCK_REFCOUNTS + Glib::Mutex::Lock lock(mutex); +#endif + assert(refcount>=0); refcount++; + } //! Returns \c false if object needs to be deleted bool unref()const { +#ifdef ETL_LOCK_REFCOUNTS + Glib::Mutex::Lock lock(mutex); +#endif assert(refcount>0); refcount--; @@ -90,6 +107,9 @@ public: if(refcount==0) { #ifdef ETL_SELF_DELETING_SHARED_OBJECT refcount=-666; +#ifdef ETL_LOCK_REFCOUNTS + lock.release(); +#endif delete this; #endif return false; @@ -99,7 +119,12 @@ public: } int count()const - { return refcount; } + { +#ifdef ETL_LOCK_REFCOUNTS + Glib::Mutex::Lock lock(mutex); +#endif + return refcount; + } }; // END of class shared_object // ======================================================================== -- 2.7.4