[asterisk-commits] russell: branch russell/iax_refcount r80332 - /team/russell/iax_refcount/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 22 14:25:34 CDT 2007


Author: russell
Date: Wed Aug 22 14:25:33 2007
New Revision: 80332

URL: http://svn.digium.com/view/asterisk?view=rev&rev=80332
Log:
remove some more commented out debug messages, make various formatting tweaks
in regards to coding standards as i read through the code

Modified:
    team/russell/iax_refcount/main/astobj2.c

Modified: team/russell/iax_refcount/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/team/russell/iax_refcount/main/astobj2.c?view=diff&rev=80332&r1=80331&r2=80332
==============================================================================
--- team/russell/iax_refcount/main/astobj2.c (original)
+++ team/russell/iax_refcount/main/astobj2.c Wed Aug 22 14:25:33 2007
@@ -306,33 +306,31 @@
  */
 void *ao2_link(ao2_container *c, void *user_data)
 {
-	static int prof_id = -1;
 	int i;
 	/* create a new list entry */
 	struct bucket_list *p;
 	struct astobj2 *obj = INTERNAL_OBJ(user_data);
-	if (obj == NULL)
-		return NULL;
+	
+	if (!obj)
+		return NULL;
+
 	if (INTERNAL_OBJ(c) == NULL)
 		return NULL;
-	if (prof_id == -1)
-		prof_id = ast_add_profile("ao2_link", 0);
-	ast_mark(prof_id, 1);
-	p = ast_calloc(1, sizeof(struct bucket_list));
-	if (p == NULL)		/* alloc failure, die */
-		return NULL;
-	/* apply the hash function */
+
+	p = ast_calloc(1, sizeof(*p));
+	if (!p)
+		return NULL;
+
 	i = c->hash_fn(user_data, OBJ_POINTER);
 
 	ao2_lock(c);
 	i %= c->n_buckets;
-
 	p->astobj = obj;
 	p->version = ast_atomic_fetchadd_int(&c->version, 1);
 	AST_LIST_INSERT_HEAD(&c->buckets[i], p, entry);
 	ast_atomic_fetchadd_int(&c->elements, 1);
 	ao2_unlock(c);
-	ast_mark(prof_id, 0);
+	
 	return p;
 }
 
@@ -341,9 +339,7 @@
  */
 static int match_by_addr(void *user_data, void *arg, int flags)
 {
-	int i = (user_data == arg) ? CMP_MATCH | CMP_STOP : 0;
-	// ast_verbose("match_by_addr u %p arg %p ret %d\n", user_data, arg, i);
-	return i;
+	return (user_data == arg) ? (CMP_MATCH | CMP_STOP) : 0;
 }
 
 /*! 
@@ -352,10 +348,11 @@
  */
 void *ao2_unlink(ao2_container *c, void *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_UNLINK | OBJ_POINTER | OBJ_NODATA, match_by_addr, user_data);
+
 	return NULL;
 }
 
@@ -379,6 +376,7 @@
 
 	if (INTERNAL_OBJ(c) == NULL)	/* safety check on the argument */
 		return NULL;
+
 	if ((flags & (OBJ_MULTIPLE | OBJ_NODATA)) == OBJ_MULTIPLE) {
 		ast_log(LOG_WARNING, "multiple data return not implemented yet (flags %x)\n", flags);
 		return NULL;
@@ -412,7 +410,7 @@
 		i = 0;
 		last = c->n_buckets;
 	} else {
-		last = i+1;
+		last = i + 1;
 	}
 
 	ao2_lock(c);	/* avoid modifications to the content */
@@ -501,8 +499,10 @@
 
 	if (INTERNAL_OBJ(a->c) == NULL)
 		return NULL;
+
 	if (!(a->flags & F_AO2I_DONTLOCK))
 		ao2_lock(a->c);
+
 	/* optimization. If the container is unchanged and
 	 * we have a pointer, try follow it
 	 */
@@ -530,6 +530,7 @@
 				goto found;
 		}
 	}
+
 found:
 	if (p) {
 		a->version = p->version;
@@ -538,8 +539,10 @@
 		/* inc refcount of returned object */
 		ao2_ref(EXTERNAL_OBJ(p->astobj), 1);
 	}
+
 	if (!(a->flags & F_AO2I_DONTLOCK))
 		ao2_unlock(a->c);
+
 	return p ? EXTERNAL_OBJ(p->astobj) : NULL;
 }
 




More information about the asterisk-commits mailing list