X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_handle.h;h=862c9146462a8565ca2649a4c600eddf1c6c9379;hb=9fc439081f4226774682129daa12d25f5ae3dfcb;hp=3f0750381096b766c0fd9f5708d491b66ab98308;hpb=c627dcb7bcb9957fb3d7dd5c879ea5c70b5c9d02;p=synfig.git diff --git a/ETL/trunk/ETL/_handle.h b/ETL/trunk/ETL/_handle.h index 3f07503..862c914 100644 --- a/ETL/trunk/ETL/_handle.h +++ b/ETL/trunk/ETL/_handle.h @@ -32,8 +32,15 @@ /* === 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 "_mutex_simple.h" +#endif + /* === M A C R O S ========================================================= */ /* === T Y P E D E F S ===================================================== */ @@ -67,6 +74,9 @@ class shared_object { private: mutable int refcount; +#ifdef ETL_LOCK_REFCOUNTS + mutable etl::mutex mtx; +#endif protected: shared_object():refcount(0) { } @@ -79,28 +89,43 @@ protected: public: void ref()const - { assert(refcount>=0); refcount++; } + { +#ifdef ETL_LOCK_REFCOUNTS + etl::mutex::lock lock(mtx); +#endif + assert(refcount>=0); + refcount++; + } //! Returns \c false if object needs to be deleted bool unref()const { - assert(refcount>0); + bool ret = true; + { +#ifdef ETL_LOCK_REFCOUNTS + etl::mutex::lock lock(mtx); +#endif + assert(refcount>0); - refcount--; + refcount--; - if(refcount==0) { + if(refcount==0) { + ret = false; #ifdef ETL_SELF_DELETING_SHARED_OBJECT - refcount=-666; - delete this; + refcount=-666; #endif - return false; + } } - return true; +#ifdef ETL_SELF_DELETING_SHARED_OBJECT + if (!ret) + delete this; +#endif + return ret; } - int count()const - { return refcount; } + int count()const { return refcount; } + }; // END of class shared_object // ========================================================================