[Asterisk-cvs] asterisk/include/asterisk astobj.h,1.8,1.9

markster at lists.digium.com markster at lists.digium.com
Sun Jan 9 23:42:07 CST 2005


Update of /usr/cvsroot/asterisk/include/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv29158/include/asterisk

Modified Files:
	astobj.h 
Log Message:
Improve object destruction (bug #3286)


Index: astobj.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/astobj.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- astobj.h	7 Jan 2005 06:14:50 -0000	1.8
+++ astobj.h	10 Jan 2005 05:46:25 -0000	1.9
@@ -32,8 +32,7 @@
 #define ASTOBJ_DEFAULT_BUCKETS	256
 #define ASTOBJ_DEFAULT_HASH		ast_strhash
 
-#define ASTOBJ_FLAG_DELME 	(1 << 0)		/* Object has been deleted, remove on last unref */
-#define ASTOBJ_FLAG_MARKED	(1 << 1)		/* Object has been marked for possible deletion */
+#define ASTOBJ_FLAG_MARKED	(1 << 0)		/* Object has been marked for future operation */
 
 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96)
 #define __builtin_expect(exp, c) (exp)
@@ -81,13 +80,17 @@
 	
 #define ASTOBJ_UNREF(object,destructor) \
 	do { \
+		int newcount = 0; \
 		ASTOBJ_WRLOCK(object); \
 		if (__builtin_expect((object)->refcount, 1)) \
-			(object)->refcount--; \
+			newcount = --((object)->refcount); \
 		else \
 			ast_log(LOG_WARNING, "Unreferencing unreferenced (object)!\n"); \
 		ASTOBJ_UNLOCK(object); \
-		ASTOBJ_DESTROY(object,destructor); \
+		if (newcount == 0) { \
+			ast_mutex_destroy(&(object)->_lock); \
+			destructor((object)); \
+		} \
 		(object) = NULL; \
 	} while(0)
 
@@ -105,18 +108,6 @@
 		ASTOBJ_UNLOCK(object); \
 	} while(0)
 
-#define ASTOBJ_DESTROY(object,destructor) \
-	do { \
-		if (__builtin_expect((object)->refcount, 1)) { \
-			ASTOBJ_WRLOCK(object); \
-			(object)->objflags |= ASTOBJ_FLAG_DELME; \
-			ASTOBJ_UNLOCK(object); \
-		} else { \
-			ast_mutex_destroy(&(object)->_lock); \
-			destructor((object)); \
-		} \
-	} while(0)
-	
 #define ASTOBJ_INIT(object) \
 	do { \
 		ast_mutex_init(&(object)->_lock); \
@@ -190,7 +181,6 @@
 		ASTOBJ_CONTAINER_WRLOCK(container); \
 		while((iterator = (container)->head)) { \
 			(container)->head = (iterator)->next[0]; \
-			ASTOBJ_DESTROY(iterator,destructor); \
 			ASTOBJ_UNREF(iterator,destructor); \
 		} \
 		ASTOBJ_CONTAINER_UNLOCK(container); \
@@ -203,6 +193,7 @@
 		ASTOBJ_CONTAINER_TRAVERSE(container, !found, do { \
 			if (!(strcasecmp(iterator->name, (namestr)))) { \
 				found = iterator; \
+				found->next[0] = NULL; \
 				ASTOBJ_CONTAINER_WRLOCK(container); \
 				if (prev) \
 					prev->next[0] = next; \
@@ -223,6 +214,7 @@
 			ASTOBJ_RDLOCK(iterator); \
 			if (!(comparefunc(iterator->field, (data)))) { \
 				found = iterator; \
+				found->next[0] = NULL; \
 				ASTOBJ_CONTAINER_WRLOCK(container); \
 				if (prev) \
 					prev->next[0] = next; \
@@ -249,7 +241,7 @@
 					(container)->head = next; \
 				ASTOBJ_CONTAINER_UNLOCK(container); \
 				ASTOBJ_UNLOCK(iterator); \
-				ASTOBJ_DESTROY(iterator,destructor); \
+				ASTOBJ_UNREF(iterator,destructor); \
 				continue; \
 			} \
 			ASTOBJ_UNLOCK(iterator); \




More information about the svn-commits mailing list