diff options
author | Russell Bryant <russell@russellbryant.com> | 2011-07-29 19:34:36 +0000 |
---|---|---|
committer | Russell Bryant <russell@russellbryant.com> | 2011-07-29 19:34:36 +0000 |
commit | 6a15e95a324bfd4ab6824f4cf9e047d7db684c52 (patch) | |
tree | ca7f78316d950a6b7a8d5f75e46581ef828e111e /include/asterisk/astobj2.h | |
parent | d2ed4ed5f70b7d670623ad1d7dee8e9268ff175a (diff) |
astobj2: Avoid using temporary objects + ao2_find() with OBJ_POINTER.
There is a fairly common pattern making its way through the code base where we
put a temporary object on the stack so we can call ao2_find() with OBJ_POINTER.
The purpose is so that it can be passed into the object hash function.
However, this really seems like a hack and potentially error prone. This patch
is a first stab at approach to avoid having to do that.
It adds a new flag, OBJ_KEY, which can be used instead of OBJ_POINTER in these
situations. Then, the hash function can know whether it was given an object or
some custom data to hash.
The patch also changes some uses of ao2_find() for iax2_user and iax2_peer
objects to reflect how OBJ_KEY would be used.
So long, and thanks for all the fish.
Review: https://reviewboard.asterisk.org/r/1184/
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@330273 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/astobj2.h')
-rw-r--r-- | include/asterisk/astobj2.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index bf8dd42ba..4b15b8c42 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -680,6 +680,16 @@ enum search_flags { * by another mechanism other that the internal ao2_lock. */ OBJ_NOLOCK = (1 << 5), + /*! + * \brief The data is hashable, but is not an object. + * + * This can be used when you want to be able to pass custom data + * to a hash function that is not a full object, but perhaps just + * a string. + * + * \note OBJ_KEY and OBJ_POINTER are mutually exclusive options. + */ + OBJ_KEY = (1 << 6), }; /*! @@ -964,9 +974,9 @@ void *__ao2_callback_data(struct ao2_container *c, enum search_flags flags, #endif -void *__ao2_find_debug(struct ao2_container *c, void *arg, enum search_flags flags, char *tag, +void *__ao2_find_debug(struct ao2_container *c, const void *arg, enum search_flags flags, char *tag, char *file, int line, const char *funcname); -void *__ao2_find(struct ao2_container *c, void *arg, enum search_flags flags); +void *__ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags); /*! \brief * |