projects
/
synfig.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Put mutexes around the reference counts for the shared_object class. Maybe this...
[synfig.git]
/
ETL
/
trunk
/
ETL
/
_handle.h
diff --git
a/ETL/trunk/ETL/_handle.h
b/ETL/trunk/ETL/_handle.h
index
9c0b2ba
..
6a46f85
100644
(file)
--- a/
ETL/trunk/ETL/_handle.h
+++ b/
ETL/trunk/ETL/_handle.h
@@
-1,6
+1,6
@@
/* === E T L =============================================================== */
/*! \file _handle.h
/* === E T L =============================================================== */
/*! \file _handle.h
-** $Id
: _handle.h,v 1.1.1.1 2005/01/04 01:31:47 darco Exp
$
+** $Id$
** \brief Template Object Handle Implementation
** \internal
**
** \brief Template Object Handle Implementation
** \internal
**
@@
-31,7
+31,13
@@
/* === 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
+
#include <cassert>
#include <cassert>
+#ifdef ETL_LOCK_REFCOUNTS
+#include <glibmm/thread.h>
+#endif
/* === M A C R O S ========================================================= */
/* === M A C R O S ========================================================= */
@@
-66,6
+72,9
@@
class shared_object
{
private:
mutable int refcount;
{
private:
mutable int refcount;
+#ifdef ETL_LOCK_REFCOUNTS
+ mutable Glib::Mutex mutex;
+#endif
protected:
shared_object():refcount(0) { }
protected:
shared_object():refcount(0) { }
@@
-78,11
+87,19
@@
protected:
public:
void ref()const
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
{
//! 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--;
assert(refcount>0);
refcount--;
@@
-90,6
+107,9
@@
public:
if(refcount==0) {
#ifdef ETL_SELF_DELETING_SHARED_OBJECT
refcount=-666;
if(refcount==0) {
#ifdef ETL_SELF_DELETING_SHARED_OBJECT
refcount=-666;
+#ifdef ETL_LOCK_REFCOUNTS
+ lock.release();
+#endif
delete this;
#endif
return false;
delete this;
#endif
return false;
@@
-99,7
+119,12
@@
public:
}
int count()const
}
int count()const
- { return refcount; }
+ {
+#ifdef ETL_LOCK_REFCOUNTS
+ Glib::Mutex::Lock lock(mutex);
+#endif
+ return refcount;
+ }
}; // END of class shared_object
// ========================================================================
}; // END of class shared_object
// ========================================================================
@@
-391,7
+416,7
@@
private:
assert(obj);
obj->rref();
assert(obj);
obj->rref();
- // If this is the first revers
a
ble handle
+ // If this is the first revers
i
ble handle
if(!obj->front_)
{
obj->front_=obj->back_=this;
if(!obj->front_)
{
obj->front_=obj->back_=this;
@@
-411,7
+436,7
@@
private:
assert(obj);
obj->runref();
assert(obj);
obj->runref();
- // If this is the last revers
a
ble handle
+ // If this is the last revers
i
ble handle
if(obj->front_==obj->back_)
{
obj->front_=obj->back_=0;
if(obj->front_==obj->back_)
{
obj->front_=obj->back_=0;
@@
-556,7
+581,7
@@
public:
/*! Uses the default constructor */
void spawn() { operator=(handle<value_type>(new T())); }
/*! Uses the default constructor */
void spawn() { operator=(handle<value_type>(new T())); }
- //! Returns number of revers
a
ble instances
+ //! Returns number of revers
i
ble instances
count_type
rcount()const
{
count_type
rcount()const
{