summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
c627dcb)
/* === H E A D E R S ======================================================= */
/* === H E A D E R S ======================================================= */
+// include the next line in an attempt to increase stability
+#define ETL_LOCK_REFCOUNTS
+
+#ifdef ETL_LOCK_REFCOUNTS
+# include "_mutex_simple.h"
+#endif
+
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
/* === M A C R O S ========================================================= */
/* === T Y P E D E F S ===================================================== */
{
private:
mutable int refcount;
{
private:
mutable int refcount;
+#ifdef ETL_LOCK_REFCOUNTS
+ mutable etl::mutex mtx;
+#endif
protected:
shared_object():refcount(0) { }
protected:
shared_object():refcount(0) { }
- { 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
{
//! Returns \c false if object needs to be deleted
bool unref()const
{
+ bool ret = true;
+ {
+#ifdef ETL_LOCK_REFCOUNTS
+ etl::mutex::lock lock(mtx);
+#endif
+ assert(refcount>0);
+ if(refcount==0) {
+ ret = false;
#ifdef ETL_SELF_DELETING_SHARED_OBJECT
#ifdef ETL_SELF_DELETING_SHARED_OBJECT
- refcount=-666;
- delete this;
+#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
// ========================================================================
}; // END of class shared_object
// ========================================================================