[svn-commits] rizzo: branch rizzo/astobj2 r47354 - in /team/rizzo/astobj2: include/asterisk...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Nov 9 02:54:21 MST 2006


Author: rizzo
Date: Thu Nov  9 03:54:19 2006
New Revision: 47354

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47354
Log:
change definitions for OBJ_DATA and OBJ_SINGLE
to OBJ_NODATA and OBJ_MULTIPLE because that's a more
reasonable default (0 means OBJ_DATA | OBJ_SINGLE).

add a bit of debugging


Modified:
    team/rizzo/astobj2/include/asterisk/astobj2.h
    team/rizzo/astobj2/main/astobj2.c

Modified: team/rizzo/astobj2/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/include/asterisk/astobj2.h?view=diff&rev=47354&r1=47353&r2=47354
==============================================================================
--- team/rizzo/astobj2/include/asterisk/astobj2.h (original)
+++ team/rizzo/astobj2/include/asterisk/astobj2.h Thu Nov  9 03:54:19 2006
@@ -262,8 +262,8 @@
  */
 enum search_flags {
 	OBJ_UNLINK	= 0x01,	/* unlink the object found */
-	OBJ_DATA	= 0x02,	/* on match, return the object. */
-	OBJ_SINGLE	= 0x08,	/* stop at the first match */
+	OBJ_NODATA	= 0x02,	/* on match, return the object. */
+	OBJ_MULTIPLE	= 0x08,	/* don't stop at the first match */
 	OBJ_POINTER	= 0x10	/* obj is an astobj object */
 };
 
@@ -398,11 +398,11 @@
  * The use of flags argument is the follow:
  *
  *	OBJ_UNLINK 		unlinks the object found
- *	OBJ_DATA		on match, return an object
- *				Callbacks do not use OBJ_DATA,
+ *	OBJ_NODATA		on match, do return an object
+ *				Callbacks use OBJ_NODATA as a default
  *				functions such as find() do
- *	OBJ_SINGLE		stop at the first match.
- *				Default for _find();
+ *	OBJ_MULTIPLE		return multiple matches
+ *				Default for _find() is no.
  *				to a key (not yet supported)
  *	OBJ_POINTER 		the pointer is an object pointer
  *

Modified: team/rizzo/astobj2/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/main/astobj2.c?view=diff&rev=47354&r1=47353&r2=47354
==============================================================================
--- team/rizzo/astobj2/main/astobj2.c (original)
+++ team/rizzo/astobj2/main/astobj2.c Thu Nov  9 03:54:19 2006
@@ -176,6 +176,7 @@
 	/* allocation */
 	struct astobj2 *obj;
 
+	ast_verbose("ao2_alloc %d\n", data_size);
 	if (data_size < sizeof(void *))
 		data_size = sizeof(void *);
 
@@ -250,16 +251,15 @@
 
 	ao2_container *c = ao2_alloc(container_size, container_destruct);
 
-	if (c == NULL)
-		return NULL;
-
-	/* init */
-	c->elements = 0;
-	c->version = 1;	/* 0 is a reserved value here */
-	c->n_buckets = n_buckets;
-	c->hash_fn = hash_fn ? hash_fn : hash_zero;
-	c->cmp_fn = cmp_fn;
-
+	if (c != NULL) {
+		/* init */
+		c->elements = 0;
+		c->version = 1;	/* 0 is a reserved value here */
+		c->n_buckets = n_buckets;
+		c->hash_fn = hash_fn ? hash_fn : hash_zero;
+		c->cmp_fn = cmp_fn;
+	}
+	ast_verbose("ao2_container_alloc %d returns %p\n", n_buckets, c);
 	return c;
 }
 
@@ -333,10 +333,10 @@
  */
 void *ao2_unlink(ao2_container *c, void *user_data)
 {
-	ast_verbose("unlinking %p from container\n", user_data);
+	// ast_verbose("unlinking %p from container\n", user_data);
 	if (INTERNAL_OBJ(user_data) == NULL)	/* safety check on the argument */
 		return NULL;
-	ao2_callback(c, OBJ_SINGLE | OBJ_UNLINK | OBJ_POINTER, match_by_addr, user_data);
+	ao2_callback(c, OBJ_UNLINK | OBJ_POINTER | OBJ_NODATA, match_by_addr, user_data);
 	return NULL;
 }
 
@@ -358,10 +358,11 @@
 	int i, last;	/* search boundaries */
 	void *ret = NULL;
 
+	// ast_verbose("ao2_callback %p\n", c);
 	if (INTERNAL_OBJ(c) == NULL)	/* safety check on the argument */
 		return NULL;
-	if ( (flags & (OBJ_SINGLE | OBJ_DATA)) == OBJ_DATA) {
-		ast_log(LOG_WARNING, "multiple data return not implemented yet");
+	if ( (flags & (OBJ_MULTIPLE | OBJ_NODATA)) == OBJ_MULTIPLE) {
+		ast_log(LOG_WARNING, "multiple data return not implemented yet (flags %x)\n", flags);
 		return NULL;
 	}
 
@@ -410,7 +411,7 @@
 				break;
 			}
 			/* we have a match (CMP_MATCH) here */
-			if (flags & OBJ_DATA) {	/* if must return the object, record the value */
+			if (!(flags & OBJ_NODATA)) {	/* if must return the object, record the value */
 				/* it is important to handle this case before the unlink */
 				ret = EXTERNAL_OBJ(cur->astobj);
 				ao2_ref(ret, 1);
@@ -420,13 +421,13 @@
 				struct bucket_list *x = cur;
 
 				// ast_verbose("++ unlink u %p at %p\n", EXTERNAL_OBJ(cur->astobj), cur);
+				ao2_ref(EXTERNAL_OBJ(cur->astobj), -1);
 				if (prev == NULL)	/* gone from head */
 					c->buckets[i].head  = cur->next;
 				else			/* gone from the middle */
 					prev->next = cur->next;
 				if (c->buckets[i].tail == cur) /* update tail if needed */
 					c->buckets[i].tail = prev;
-				ao2_ref(EXTERNAL_OBJ(cur->astobj), -1);
 				cur = cur->next ;	/* prepare for next cycle */
 				free(x);	/* free the link record */
 				/* update number of elements and version */
@@ -437,12 +438,12 @@
 				cur = cur->next;
 			}
 
-			if ((match & CMP_STOP) || (flags & OBJ_SINGLE)) {
+			if ((match & CMP_STOP) || (flags & OBJ_MULTIPLE) == 0) {
 				/* We found the only match we need */
 				i = last;	/* force exit from outer loop */
 				break;
 			}
-			if (flags & OBJ_DATA) {
+			if (!(flags & OBJ_NODATA)) {
 #if 0	/* XXX to be completed */
 				/*
 				 * This is the multiple-return case. We need to link
@@ -461,8 +462,6 @@
  */
 void *ao2_find(ao2_container *c, void *arg, enum search_flags flags)
 {
-	if (flags == 0)
-		flags = OBJ_SINGLE | OBJ_DATA;	/* reasonable default */
 	ast_log(LOG_NOTICE, "ao2_find\n");
 	return ao2_callback(c, flags, c->cmp_fn, arg);
 }
@@ -490,6 +489,7 @@
 	int lim;
 	struct bucket_list *p = NULL;
 
+	// ast_verbose("ao2_iterator a %p a->c %p\n", a, a->c);
 	if (INTERNAL_OBJ(a->c) == NULL)
 		return NULL;
 	if (!(a->flags & F_AO2I_DONTLOCK))
@@ -498,8 +498,7 @@
 	 * we have a pointer, try follow it
 	 */
 	if (a->c->version == a->c_version && (p = a->obj) ) {
-		ast_verbose("optimized lookup for %u\n",
-			a->version);
+		// ast_verbose("optimized lookup for %u\n", a->version);
 		if ( (p = p->next) )
 			goto found;
 		/* nope, start from the next bucket */
@@ -627,9 +626,9 @@
 	ast_cli(fd, "testing callbacks again\n");
 	ao2_callback(c1, 0, print_cb, (void*)fd);
 
-	{ int a;
-		ao2_ref(&a, -1);
-	}
+	ast_verbose("now you should see an error message:\n");
+	ao2_ref(&i, -1);	/* i is not a valid object so we print an error here */
+
 	ast_cli(fd, "destroy container\n");
 	ao2_ref(c1, -1);	/* destroy container */
 	ast_verbose("at the end have %d objects\n",



More information about the svn-commits mailing list