aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-30 19:26:04 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2007-11-30 19:26:04 +0000
commit213a686818ae3b52921ac398852d0ffdff4f5f73 (patch)
tree9cb3c976f72d1999221cfb9a689ea8d7929fa8ad
parent64fb113167810bc0f1d1310f205d23b687ef8f18 (diff)
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. git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@90348 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--apps/app_queue.c6
-rw-r--r--channels/chan_iax2.c12
-rw-r--r--include/asterisk/astobj2.h20
-rw-r--r--main/astobj2.c1
-rw-r--r--main/manager.c2
5 files changed, 23 insertions, 18 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c
index da99ab0a3..bee1997ac 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -1069,6 +1069,8 @@ static void rt_handle_member_record(struct call_queue *q, char *interface, const
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 @@ static int add_to_queue(const char *queuename, const char *interface, const char
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 @@ static int reload_queues(void)
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);
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 004e1de62..de8493ea3 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -2740,7 +2740,7 @@ static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in
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 @@ static struct iax2_user *realtime_user(const char *username)
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 @@ static int set_config(char *config_file, int reload)
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 @@ static int set_config(char *config_file, int reload)
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 @@ static int set_config(char *config_file, int reload)
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);
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h
index 219d947d8..bcb8addda 100644
--- a/include/asterisk/astobj2.h
+++ b/include/asterisk/astobj2.h
@@ -114,10 +114,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
does not lock the object to be computed, so modifications of
@@ -348,17 +344,22 @@ int ao2_container_count(struct ao2_container *c);
* 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
* when it is just a linked list. This is to maintain some existing behavior
@@ -367,6 +368,7 @@ int ao2_container_count(struct ao2_container *c);
*/
#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 @@ void *__ao2_link(struct ao2_container *c, void *newobj, int iax2_hack);
* 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);
diff --git a/main/astobj2.c b/main/astobj2.c
index 4b82eaf92..7cbf70cce 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -365,6 +365,7 @@ void *__ao2_link(struct ao2_container *c, void *user_data, int iax2_hack)
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;
diff --git a/main/manager.c b/main/manager.c
index cecb2ca89..830634792 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -394,8 +394,6 @@ static char *xml_translate(char *in, struct ast_variable *vars)
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);
}