/* === H E A D E R S ======================================================= */
+// include the next line in an attempt to increase stability
+#define ETL_LOCK_REFCOUNTS
+
#include <cassert>
+#ifdef ETL_LOCK_REFCOUNTS
+#include <glibmm/thread.h>
+#endif
/* === M A C R O S ========================================================= */
{
private:
mutable int refcount;
+#ifdef ETL_LOCK_REFCOUNTS
+ mutable Glib::Mutex mutex;
+#endif
protected:
shared_object():refcount(0) { }
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--;
if(refcount==0) {
#ifdef ETL_SELF_DELETING_SHARED_OBJECT
refcount=-666;
+#ifdef ETL_LOCK_REFCOUNTS
+ lock.release();
+#endif
delete this;
#endif
return false;
}
int count()const
- { return refcount; }
+ {
+#ifdef ETL_LOCK_REFCOUNTS
+ Glib::Mutex::Lock lock(mutex);
+#endif
+ return refcount;
+ }
}; // END of class shared_object
// ========================================================================