mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 04:11:08 +00:00
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. ........ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@90351 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1165,6 +1165,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 {
|
||||
@@ -1284,7 +1286,6 @@ static struct call_queue *find_queue_by_name_rt(const char *queuename, struct as
|
||||
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 @@ 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"
|
||||
@@ -4590,6 +4593,8 @@ static int reload_queues(int reload)
|
||||
|
||||
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 @@ static int reload_queues(int reload)
|
||||
|
||||
if (new) {
|
||||
ao2_link(queues, q);
|
||||
queue_ref(q);
|
||||
} else
|
||||
ao2_unlock(q);
|
||||
queue_unref(q);
|
||||
|
@@ -3014,7 +3014,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 {
|
||||
@@ -3069,7 +3069,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);
|
||||
}
|
||||
@@ -10695,14 +10695,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);
|
||||
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 @@ 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);
|
||||
user = NULL;
|
||||
user = user_unref(user);
|
||||
}
|
||||
}
|
||||
if (!strcasecmp(utype, "peer") || !strcasecmp(utype, "friend")) {
|
||||
@@ -10748,7 +10748,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);
|
||||
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);
|
||||
|
@@ -119,12 +119,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
|
||||
does not lock the object to be computed, so modifications of
|
||||
@@ -352,18 +346,25 @@ 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 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 @@ void *ao2_link(struct ao2_container *c, void *newobj);
|
||||
* 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);
|
||||
|
||||
|
@@ -363,6 +363,7 @@ void *ao2_link(struct ao2_container *c, void *user_data)
|
||||
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;
|
||||
|
@@ -1431,7 +1431,6 @@ static void set_fn(char *fn, int fn_size, const char *file, const char *configfi
|
||||
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 */
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -3087,8 +3087,6 @@ static void xml_translate(struct ast_str **out, char *in, struct ast_variable *v
|
||||
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);
|
||||
|
Reference in New Issue
Block a user