cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
* [Cluster-devel] conga/ricci/include counting_auto_ptr.cpp coun ...
@ 2007-09-04 21:28 rmccabe
  0 siblings, 0 replies; 2+ messages in thread
From: rmccabe @ 2007-09-04 21:28 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-09-04 21:28:05

Modified files:
	ricci/include  : counting_auto_ptr.cpp counting_auto_ptr.h 

Log message:
	More debugging, make the refcounter an int * again

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/counting_auto_ptr.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/counting_auto_ptr.h.diff?cvsroot=cluster&r1=1.3&r2=1.4

--- conga/ricci/include/counting_auto_ptr.cpp	2007/09/04 18:43:26	1.4
+++ conga/ricci/include/counting_auto_ptr.cpp	2007/09/04 21:28:05	1.5
@@ -28,12 +28,18 @@
 counting_auto_ptr<X>::counting_auto_ptr(X* ptr) :
 	_ptr(ptr)
 {
-	_counter = 1;
+	try {
+		_counter = new int(1);
+	} catch ( ... ) {
+		delete _ptr;
+		throw;
+	}
 
 	try {
 		_mutex = new Mutex();
 	} catch ( ... ) {
 		delete _ptr;
+		delete _counter;
 		throw;
 	}
 };
@@ -45,7 +51,7 @@
 	_ptr = o._ptr;
 	_mutex = o._mutex;
 	_counter = o._counter;
-	_counter++;
+	(*_counter)++;
 };
 
 template<class X>
@@ -58,7 +64,7 @@
 		_ptr = o._ptr;
 		_mutex = o._mutex;
 		_counter = o._counter;
-		_counter++;
+		(*_counter)++;
 	}
 	return *this;
 };
@@ -76,10 +82,14 @@
 	bool last = false;
 	{
 		MutexLocker l(*_mutex);
-		last = (--_counter == 0);
+		last = (--(*_counter) == 0);
+		if (*_counter < 0)
+			throw int();
 	}
 
 	if (last) {
+		delete _counter;
+		_counter = NULL;
 		delete _ptr;
 		_ptr = NULL;
 		delete _mutex;
@@ -102,6 +112,9 @@
 X*
 counting_auto_ptr<X>::operator->() const
 {
+#ifdef DEBUG
+	assert(_ptr != NULL);
+#endif
 	return _ptr;
 };
 
--- conga/ricci/include/counting_auto_ptr.h	2007/09/04 18:30:46	1.3
+++ conga/ricci/include/counting_auto_ptr.h	2007/09/04 21:28:05	1.4
@@ -47,7 +47,7 @@
 	private:
 		X* _ptr;
 		Mutex* _mutex;
-		int _counter;
+		int *_counter;
 		void decrease_counter();
 };
 



^ permalink raw reply	[flat|nested] 2+ messages in thread
* [Cluster-devel] conga/ricci/include counting_auto_ptr.cpp coun ...
@ 2007-09-04 18:30 rmccabe
  0 siblings, 0 replies; 2+ messages in thread
From: rmccabe @ 2007-09-04 18:30 UTC (permalink / raw)
  To: cluster-devel.redhat.com

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	rmccabe at sourceware.org	2007-09-04 18:30:46

Modified files:
	ricci/include  : counting_auto_ptr.cpp counting_auto_ptr.h 

Log message:
	don't dynamically allocate the reference counter int on the heap

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/counting_auto_ptr.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/counting_auto_ptr.h.diff?cvsroot=cluster&r1=1.2&r2=1.3

--- conga/ricci/include/counting_auto_ptr.cpp	2007/08/31 13:32:36	1.2
+++ conga/ricci/include/counting_auto_ptr.cpp	2007/09/04 18:30:46	1.3
@@ -29,7 +29,7 @@
 	_ptr(ptr)
 {
 	try {
-		_counter = new int(1);
+		_counter = 1;
 	} catch ( ... ) {
 		delete _ptr;
 		throw;
@@ -39,7 +39,6 @@
 		_mutex = new Mutex();
 	} catch ( ... ) {
 		delete _ptr;
-		delete _counter;
 		throw;
 	}
 };
@@ -51,7 +50,7 @@
 	_ptr = o._ptr;
 	_mutex = o._mutex;
 	_counter = o._counter;
-	(*_counter)++;
+	_counter++;
 };
 
 template<class X>
@@ -64,7 +63,7 @@
 		_ptr = o._ptr;
 		_mutex = o._mutex;
 		_counter = o._counter;
-		(*_counter)++;
+		_counter++;
 	}
 	return *this;
 };
@@ -82,11 +81,10 @@
 	bool last = false;
 	{
 		MutexLocker l(*_mutex);
-		last = (--(*_counter) == 0);
+		last = (--_counter == 0);
 	}
 
 	if (last) {
-		delete _counter;
 		delete _ptr;
 		delete _mutex;
 	}
--- conga/ricci/include/counting_auto_ptr.h	2007/08/31 13:32:36	1.2
+++ conga/ricci/include/counting_auto_ptr.h	2007/09/04 18:30:46	1.3
@@ -47,7 +47,7 @@
 	private:
 		X* _ptr;
 		Mutex* _mutex;
-		int* _counter;
+		int _counter;
 		void decrease_counter();
 };
 



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-09-04 21:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-04 21:28 [Cluster-devel] conga/ricci/include counting_auto_ptr.cpp coun rmccabe
  -- strict thread matches above, loose matches on Subject: below --
2007-09-04 18:30 rmccabe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).