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.
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@90351
65c4cc65-6c06-0410-ace0-
fbb531ad65f3
m->realtime = 1;
add_to_interfaces(interface);
ao2_link(q->members, m);
+ ao2_ref(m, -1);
+ m = NULL;
q->membercount++;
}
} else {
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));
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"
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);
if (new) {
ao2_link(queues, q);
- queue_ref(q);
} else
ao2_unlock(q);
queue_unref(q);
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 {
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);
}
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)) {
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")) {
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);
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
does not lock the object to be computed, so modifications of
* 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
*
* 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);
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;
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 */
}
}
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);