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:
Russell Bryant
2007-11-30 19:34:47 +00:00
parent 45f98e5419
commit fac7480820
6 changed files with 24 additions and 23 deletions

View 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);