[svn-commits] russell: trunk r90351 - in /trunk: ./ apps/ channels/ include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Nov 30 13:34:48 CST 2007


Author: russell
Date: Fri Nov 30 13:34:47 2007
New Revision: 90351

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90351
Log:
Merged revisions 90348 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r90348 | russell | 2007-11-30 13:26:04 -0600 (Fri, 30 Nov 2007) | 8 lines

Change the behavior of ao2_link().  Previously, in inherited a reference.
Now, it automatically increases the reference count to reflect the reference
that is now held by the container.

This was done to be more consistent with ao2_unlink(), which automatically
releases the reference held by the container.  It also makes it so it is
no longer possible for a pointer to be invalid after ao2_link() returns.

........

Modified:
    trunk/   (props changed)
    trunk/apps/app_queue.c
    trunk/channels/chan_iax2.c
    trunk/include/asterisk/astobj2.h
    trunk/main/astobj2.c
    trunk/main/config.c
    trunk/main/manager.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?view=diff&rev=90351&r1=90350&r2=90351
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Fri Nov 30 13:34:47 2007
@@ -1165,6 +1165,8 @@
 			m->realtime = 1;
 			add_to_interfaces(interface);
 			ao2_link(q->members, m);
+			ao2_ref(m, -1);
+			m = NULL;
 			q->membercount++;
 		}
 	} else {
@@ -1284,7 +1286,6 @@
 		q->realtime = 1;
 		init_queue(q);		/* Ensure defaults for all parameters not set explicitly. */
 		ao2_link(queues, q);
-		queue_ref(q);
 	}
 
 	memset(tmpbuf, 0, sizeof(tmpbuf));
@@ -3373,6 +3374,8 @@
 		if ((new_member = create_queue_member(interface, membername, penalty, paused))) {
 			new_member->dynamic = 1;
 			ao2_link(q->members, new_member);
+			ao2_ref(new_member, -1);
+			new_member = NULL;
 			q->membercount++;
 			manager_event(EVENT_FLAG_AGENT, "QueueMemberAdded",
 				"Queue: %s\r\n"
@@ -4590,6 +4593,8 @@
 
 						newm = create_queue_member(interface, membername, penalty, cur ? cur->paused : 0);
 						ao2_link(q->members, newm);
+						ao2_ref(newm, -1);
+						newm = NULL;
 
 						if (cur)
 							ao2_ref(cur, -1);
@@ -4619,7 +4624,6 @@
 
 				if (new) {
 					ao2_link(queues, q);
-					queue_ref(q);
 				} else
 					ao2_unlock(q);
 				queue_unref(q);

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=90351&r1=90350&r2=90351
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Fri Nov 30 13:34:47 2007
@@ -3014,7 +3014,7 @@
  			if (peer->expire == -1)
  				peer_unref(peer);
 		}
-		ao2_link(peers, peer_ref(peer));
+		ao2_link(peers, peer);
 		if (ast_test_flag(peer, IAX_DYNAMIC))
 			reg_source_db(peer);
 	} else {
@@ -3069,7 +3069,7 @@
 
 	if (ast_test_flag((&globalflags), IAX_RTCACHEFRIENDS)) {
 		ast_set_flag(user, IAX_RTCACHEFRIENDS);
-		ao2_link(users, user_ref(user));
+		ao2_link(users, user);
 	} else {
 		ast_set_flag(user, IAX_TEMPONLY);	
 	}
@@ -10695,14 +10695,14 @@
 					user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0);
 					if (user) {
 						ao2_link(users, user);
-						user = NULL;
+						user = user_unref(user);
 					}
 					peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0);
 					if (peer) {
 						if (ast_test_flag(peer, IAX_DYNAMIC))
 							reg_source_db(peer);
 						ao2_link(peers, peer);
-						peer = NULL;
+						peer = peer_unref(peer);
 					}
 				}
 				if (ast_true(registeriax) || (!registeriax && genregisteriax)) {
@@ -10739,7 +10739,7 @@
 					user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0);
 					if (user) {
 						ao2_link(users, user);
-						user = NULL;
+						user = user_unref(user);
 					}
 				}
 				if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
@@ -10748,7 +10748,7 @@
 						if (ast_test_flag(peer, IAX_DYNAMIC))
 							reg_source_db(peer);
 						ao2_link(peers, peer);
-						peer = NULL;
+						peer = peer_unref(peer);
 					}
 				} else if (strcasecmp(utype, "user")) {
 					ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config_file);

Modified: trunk/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/astobj2.h?view=diff&rev=90351&r1=90350&r2=90351
==============================================================================
--- trunk/include/asterisk/astobj2.h (original)
+++ trunk/include/asterisk/astobj2.h Fri Nov 30 13:34:47 2007
@@ -118,12 +118,6 @@
 The function returns NULL in case of errors (and the object
 is not inserted in the container). Other values mean success
 (we are not supposed to use the value as a pointer to anything).
-
-\note inserting an object in a container grabs the reference
-to the object (which is now owned by the container), so we do not
-need to drop our reference - in fact, we don't own it anymore,
-so we are not even supposed to access the object as someone might
-delete it.
 
 \note While an object o is in a container, we expect that
 my_hash_fn(o) will always return the same value. The function
@@ -352,18 +346,25 @@
  * We can use the functions below on any kind of 
  * object defined by the user.
  */
-/*!
- * Add an object to a container.
+
+/*!
+ * \brief Add an object to a container.
  *
  * \param c the container to operate on.
  * \param newobj the object to be added.
- * \return NULL on errors, other values on success.
- *
- * This function insert an object in a container according its key.
+ *
+ * \retval NULL on errors
+ * \retval newobj on success.
+ *
+ * This function inserts an object in a container according its key.
  *
  * \note Remember to set the key before calling this function.
+ *
+ * \note This function automatically increases the reference count to account
+ *       for the reference that the container now holds to the object.
  */
 void *ao2_link(struct ao2_container *c, void *newobj);
+
 /*!
  * \brief Remove an object from the container
  *
@@ -377,9 +378,7 @@
  *       be called.
  *
  * \note If the object gets unlinked from the container, the container's
- *       reference to the object will be automatically released.  This is
- *       slightly different than ao2_link(), which inherits a reference instead
- *       of automatically increasing the reference count.
+ *       reference to the object will be automatically released.  
  */
 void *ao2_unlink(struct ao2_container *c, void *obj);
 

Modified: trunk/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/trunk/main/astobj2.c?view=diff&rev=90351&r1=90350&r2=90351
==============================================================================
--- trunk/main/astobj2.c (original)
+++ trunk/main/astobj2.c Fri Nov 30 13:34:47 2007
@@ -363,6 +363,7 @@
 	p->version = ast_atomic_fetchadd_int(&c->version, 1);
 	AST_LIST_INSERT_TAIL(&c->buckets[i], p, entry);
 	ast_atomic_fetchadd_int(&c->elements, 1);
+	ao2_ref(user_data, +1);
 	ao2_unlock(c);
 	
 	return p;

Modified: trunk/main/config.c
URL: http://svn.digium.com/view/asterisk/trunk/main/config.c?view=diff&rev=90351&r1=90350&r2=90351
==============================================================================
--- trunk/main/config.c (original)
+++ trunk/main/config.c Fri Nov 30 13:34:47 2007
@@ -1431,7 +1431,6 @@
 		fx->lineno = 1;
 		*fi = fx;
 		ao2_link(fileset, fx);
-		ao2_ref(fx,1); /* bump the ref count, so it looks like we just got the ref from find */
 	}
 }
 

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=90351&r1=90350&r2=90351
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Fri Nov 30 13:34:47 2007
@@ -3087,8 +3087,6 @@
 				vc = ao2_alloc(sizeof(*vc), NULL);
 				vc->varname = var;
 				vc->count = 1;
-				/* Increment refcount, because we're going to deref once later */
-				ao2_ref(vc, 1);
 				ao2_link(vco, vc);
 			}
 			xml_copy_escape(out, var, xml ? 1 | 2 : 0);




More information about the svn-commits mailing list