<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/6736">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">astobj2: Add ao2_weakproxy_find function.<br><br>This function finds a weak proxy in an ao2_container and returns the<br>real object associated with it.<br><br>Change-Id: I9da822049747275f5961b5c0a7f14e87157d65d8<br>---<br>M include/asterisk/astobj2.h<br>M main/astobj2_container.c<br>2 files changed, 53 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/36/6736/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h<br>index 9b5ec12..a18f099 100644<br>--- a/include/asterisk/astobj2.h<br>+++ b/include/asterisk/astobj2.h<br>@@ -1775,6 +1775,17 @@<br> void *__ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags,<br> const char *tag, const char *file, int line, const char *func);<br> <br>+/*!<br>+ * \brief Perform an ao2_find on a container with ao2_weakproxy objects, returning the real object.<br>+ *<br>+ * \note Only OBJ_SEARCH_* and OBJ_NOLOCK flags are supported by this function.<br>+ * \see ao2_callback for description of arguments.<br>+ */<br>+#define ao2_weakproxy_find(c, arg, flags, tag) \<br>+ __ao2_weakproxy_find(c, arg, flags, tag, __FILE__, __LINE__, __PRETTY_FUNCTION__)<br>+void *__ao2_weakproxy_find(struct ao2_container *c, const void *arg, enum search_flags flags,<br>+ const char *tag, const char *file, int line, const char *func);<br>+<br> /*! \brief<br> *<br> *<br>diff --git a/main/astobj2_container.c b/main/astobj2_container.c<br>index a978db3..c75dff9 100644<br>--- a/main/astobj2_container.c<br>+++ b/main/astobj2_container.c<br>@@ -437,6 +437,48 @@<br> return __ao2_callback(c, flags, c->cmp_fn, arged, tag, file, line, func);<br> }<br> <br>+void *__ao2_weakproxy_find(struct ao2_container *c, const void *arg, enum search_flags flags,<br>+ const char *tag, const char *file, int line, const char *func)<br>+{<br>+ void *proxy;<br>+ void *obj = NULL;<br>+ enum ao2_lock_req orig_lock;<br>+<br>+ ast_assert(!!c);<br>+ ast_assert(flags & OBJ_SEARCH_MASK);<br>+ ast_assert(!(flags & ~(OBJ_SEARCH_MASK | OBJ_NOLOCK)));<br>+<br>+ if (flags & OBJ_NOLOCK) {<br>+ orig_lock = __adjust_lock(c, AO2_LOCK_REQ_RDLOCK, 1);<br>+ } else {<br>+ orig_lock = AO2_LOCK_REQ_RDLOCK;<br>+ ao2_rdlock(c);<br>+ }<br>+<br>+ while ((proxy = ao2_find(c, arg, flags | OBJ_NOLOCK))) {<br>+ obj = __ao2_weakproxy_get_object(proxy, 0, tag ?: __PRETTY_FUNCTION__, file, line, func);<br>+<br>+ if (obj) {<br>+ ao2_ref(proxy, -1);<br>+ break;<br>+ }<br>+<br>+ /* Upgrade to a write lock */<br>+ __adjust_lock(c, AO2_LOCK_REQ_WRLOCK, 1);<br>+ ao2_unlink_flags(c, proxy, OBJ_NOLOCK);<br>+ ao2_ref(proxy, -1);<br>+ }<br>+<br>+ if (flags & OBJ_NOLOCK) {<br>+ /* We'll keep any upgraded lock */<br>+ __adjust_lock(c, orig_lock, 1);<br>+ } else {<br>+ ao2_unlock(c);<br>+ }<br>+<br>+ return obj;<br>+}<br>+<br> /*!<br> * initialize an iterator so we start from the first object<br> */<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/6736">change 6736</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/6736"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I9da822049747275f5961b5c0a7f14e87157d65d8 </div>
<div style="display:none"> Gerrit-Change-Number: 6736 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>