[asterisk-commits] russell: branch 1.4 r90348 - in /branches/1.4: apps/ channels/ include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 30 13:26:04 CST 2007


Author: russell
Date: Fri Nov 30 13:26:04 2007
New Revision: 90348

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90348
Log:
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:
    branches/1.4/apps/app_queue.c
    branches/1.4/channels/chan_iax2.c
    branches/1.4/include/asterisk/astobj2.h
    branches/1.4/main/astobj2.c
    branches/1.4/main/manager.c

Modified: branches/1.4/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/apps/app_queue.c?view=diff&rev=90348&r1=90347&r2=90348
==============================================================================
--- branches/1.4/apps/app_queue.c (original)
+++ branches/1.4/apps/app_queue.c Fri Nov 30 13:26:04 2007
@@ -1069,6 +1069,8 @@
 			m->realtime = 1;
 			add_to_interfaces(interface);
 			ao2_link(q->members, m);
+			ao2_ref(m, -1);
+			m = NULL;
 			q->membercount++;
 		}
 	} else {
@@ -3036,6 +3038,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"
@@ -4021,6 +4025,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);

Modified: branches/1.4/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/channels/chan_iax2.c?view=diff&rev=90348&r1=90347&r2=90348
==============================================================================
--- branches/1.4/channels/chan_iax2.c (original)
+++ branches/1.4/channels/chan_iax2.c Fri Nov 30 13:26:04 2007
@@ -2740,7 +2740,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 {
@@ -2797,7 +2797,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);	
 	}
@@ -9801,14 +9801,14 @@
 					user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0);
 					if (user) {
 						__ao2_link(users, user, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
-						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, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
-						peer = NULL;
+						peer = peer_unref(peer);
 					}
 				}
 				if (ast_true(registeriax) || (!registeriax && genregisteriax)) {
@@ -9845,7 +9845,7 @@
 					user = build_user(cat, ast_variable_browse(cfg, cat), NULL, 0);
 					if (user) {
 						__ao2_link(users, user, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
-						user = NULL;
+						user = user_unref(user);
 					}
 				}
 				if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
@@ -9854,7 +9854,7 @@
 						if (ast_test_flag(peer, IAX_DYNAMIC))
 							reg_source_db(peer);
 						__ao2_link(peers, peer, (MAX_PEER_BUCKETS == 1) ? 1 : 0);
-						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: branches/1.4/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/astobj2.h?view=diff&rev=90348&r1=90347&r2=90348
==============================================================================
--- branches/1.4/include/asterisk/astobj2.h (original)
+++ branches/1.4/include/asterisk/astobj2.h Fri Nov 30 13:26:04 2007
@@ -113,10 +113,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 the object in the container grabs the reference
-to the object (which is now owned by the container) so we do not
-need to drop ours when we are done.
 
 \note While an object o is in a container, we expect that
 my_hash_fn(o) will always return the same value. The function
@@ -348,16 +344,21 @@
  * 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 obj the object to be added.
+ * \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.
+ * 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 to the object that the container now holds.
  *
  * For Asterisk 1.4 only, there is a dirty hack here to ensure that chan_iax2
  * can have objects linked in to the container at the head instead of tail
@@ -367,6 +368,7 @@
  */
 #define ao2_link(c, o) __ao2_link(c, o, 0)
 void *__ao2_link(struct ao2_container *c, void *newobj, int iax2_hack);
+
 /*!
  * \brief Remove an object from the container
  *
@@ -380,9 +382,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: branches/1.4/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/astobj2.c?view=diff&rev=90348&r1=90347&r2=90348
==============================================================================
--- branches/1.4/main/astobj2.c (original)
+++ branches/1.4/main/astobj2.c Fri Nov 30 13:26:04 2007
@@ -365,6 +365,7 @@
 	else
 		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: branches/1.4/main/manager.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/manager.c?view=diff&rev=90348&r1=90347&r2=90348
==============================================================================
--- branches/1.4/main/manager.c (original)
+++ branches/1.4/main/manager.c Fri Nov 30 13:26:04 2007
@@ -394,8 +394,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);
 				}
 




More information about the asterisk-commits mailing list