X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_handle.h;h=393894cc0baf1e40ccf936d5857fac31146dbe20;hb=9459638ad6797b8139f1e9f0715c96076dbf0890;hp=32a37ad98bccf6d722a9e957a0e8ca9de64f682e;hpb=428daa8dd2b5593d6b61894df9a170bb8002bb8f;p=synfig.git diff --git a/ETL/trunk/ETL/_handle.h b/ETL/trunk/ETL/_handle.h index 32a37ad..393894c 100644 --- a/ETL/trunk/ETL/_handle.h +++ b/ETL/trunk/ETL/_handle.h @@ -6,6 +6,7 @@ ** ** \legal ** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** Copyright (c) 2007, 2008 Chris Moore ** ** This package is free software; you can redistribute it and/or ** modify it under the terms of the GNU General Public License as @@ -66,6 +67,9 @@ class shared_object { private: mutable int refcount; +#ifdef ETL_LOCK_REFCOUNTS + mutable etl::mutex mtx; +#endif protected: shared_object():refcount(0) { } @@ -78,28 +82,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 // ======================================================================== @@ -205,7 +224,7 @@ public: swap(handle &x) { pointer ptr=x.obj; - x.obj=x.get(); + x.obj=obj; obj=ptr; return *this; } @@ -361,8 +380,8 @@ public: using handle::unique; using handle::operator bool; using handle::get; - using handle::operator *; - using handle::operator ->; + using handle::operator*; + using handle::operator->; /* operator const handle&()const @@ -606,7 +625,7 @@ public: { assert(0); pointer ptr=x.obj; - x.obj=x.get(); + x.obj=obj; obj=ptr; return *this; } @@ -688,7 +707,7 @@ public: swap(loose_handle &x) { pointer ptr=x.obj; - x.obj=x.get(); + x.obj=obj; obj=ptr; return *this; }