**
** \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
{
private:
mutable int refcount;
+#ifdef ETL_LOCK_REFCOUNTS
+ mutable etl::mutex mtx;
+#endif
protected:
shared_object():refcount(0) { }
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
// ========================================================================
typedef int size_type;
protected:
+#ifdef _DEBUG
+public:
+#endif
value_type *obj; //!< Pointer to object
public:
using handle<value_type>::unique;
using handle<value_type>::operator bool;
using handle<value_type>::get;
- using handle<value_type>::operator *;
- using handle<value_type>::operator ->;
+ using handle<value_type>::operator*;
+ using handle<value_type>::operator->;
/*
operator const handle<value_type>&()const
typedef int size_type;
protected:
+#ifdef _DEBUG
+public:
+#endif
value_type *obj; //!< Pointer to object
public: