<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7905">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stasis: Remove silly usage of RAII_VAR.<br><br>Change-Id: Ib11193531e797bcb16bba560a408eab155f706d1<br>---<br>M main/stasis.c<br>1 file changed, 63 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/stasis.c b/main/stasis.c<br>index 38accb5..190ab14 100644<br>--- a/main/stasis.c<br>+++ b/main/stasis.c<br>@@ -422,10 +422,10 @@<br> {<br>        /* Notify that the final message has been received */<br>         if (stasis_subscription_final_message(sub, message)) {<br>-               SCOPED_AO2LOCK(lock, sub);<br>-<br>+                ao2_lock(sub);<br>                sub->final_message_rxed = 1;<br>               ast_cond_signal(&sub->join_cond);<br>+             ao2_unlock(sub);<br>      }<br> <br>  /* Since sub is mostly immutable, no need to lock sub */<br>@@ -433,10 +433,10 @@<br> <br>    /* Notify that the final message has been processed */<br>        if (stasis_subscription_final_message(sub, message)) {<br>-               SCOPED_AO2LOCK(lock, sub);<br>-<br>+                ao2_lock(sub);<br>                sub->final_message_processed = 1;<br>          ast_cond_signal(&sub->join_cond);<br>+             ao2_unlock(sub);<br>      }<br> }<br> <br>@@ -454,7 +454,7 @@<br>         int needs_mailbox,<br>    int use_thread_pool)<br> {<br>-     RAII_VAR(struct stasis_subscription *, sub, NULL, ao2_cleanup);<br>+      struct stasis_subscription *sub;<br> <br>   if (!topic) {<br>                 return NULL;<br>@@ -486,6 +486,8 @@<br>                     sub->mailbox = ast_taskprocessor_get(tps_name, TPS_REF_DEFAULT);<br>           }<br>             if (!sub->mailbox) {<br>+                      ao2_ref(sub, -1);<br>+<br>                  return NULL;<br>          }<br>             ast_taskprocessor_set_local(sub->mailbox, sub);<br>@@ -500,11 +502,12 @@<br>     ast_cond_init(&sub->join_cond, NULL);<br> <br>       if (topic_add_subscription(topic, sub) != 0) {<br>+               ao2_ref(sub, -1);<br>+<br>          return NULL;<br>  }<br>     send_subscription_subscribe(topic, sub);<br> <br>-  ao2_ref(sub, +1);<br>     return sub;<br> }<br> <br>@@ -535,18 +538,21 @@<br> {<br>         /* The subscription may be the last ref to this topic. Hold<br>    * the topic ref open until after the unlock. */<br>-     RAII_VAR(struct stasis_topic *, topic,<br>-               ao2_bump(sub ? sub->topic : NULL), ao2_cleanup);<br>+  struct stasis_topic *topic;<br> <br>        if (!sub) {<br>           return NULL;<br>  }<br>+<br>+ topic = ao2_bump(sub->topic);<br> <br>   /* We have to remove the subscription first, to ensure the unsubscribe<br>         * is the final message */<br>    if (topic_remove_subscription(sub->topic, sub) != 0) {<br>             ast_log(LOG_ERROR,<br>                    "Internal error: subscription has invalid topic\n");<br>+               ao2_cleanup(topic);<br>+<br>                return NULL;<br>  }<br> <br>@@ -560,6 +566,8 @@<br> <br>  /* Unsubscribing unrefs the subscription */<br>   ao2_cleanup(sub);<br>+    ao2_cleanup(topic);<br>+<br>        return NULL;<br> }<br> <br>@@ -578,22 +586,26 @@<br> void stasis_subscription_join(struct stasis_subscription *subscription)<br> {<br>      if (subscription) {<br>-          SCOPED_AO2LOCK(lock, subscription);<br>-<br>+               ao2_lock(subscription);<br>               /* Wait until the processed flag has been set */<br>              while (!subscription->final_message_processed) {<br>                   ast_cond_wait(&subscription->join_cond,<br>                                ao2_object_get_lockaddr(subscription));<br>               }<br>+            ao2_unlock(subscription);<br>     }<br> }<br> <br> int stasis_subscription_is_done(struct stasis_subscription *subscription)<br> {<br>      if (subscription) {<br>-          SCOPED_AO2LOCK(lock, subscription);<br>+          int ret;<br> <br>-          return subscription->final_message_rxed;<br>+          ao2_lock(subscription);<br>+              ret = subscription->final_message_rxed;<br>+           ao2_unlock(subscription);<br>+<br>+         return ret;<br>   }<br> <br>  /* Null subscription is about as done as you can get */<br>@@ -621,13 +633,15 @@<br>        if (sub) {<br>            size_t i;<br>             struct stasis_topic *topic = sub->topic;<br>-          SCOPED_AO2LOCK(lock_topic, topic);<br> <br>+                ao2_lock(topic);<br>              for (i = 0; i < AST_VECTOR_SIZE(&topic->subscribers); ++i) {<br>                        if (AST_VECTOR_GET(&topic->subscribers, i) == sub) {<br>+                          ao2_unlock(topic);<br>                            return 1;<br>                     }<br>             }<br>+            ao2_unlock(topic);<br>    }<br> <br>  return 0;<br>@@ -668,8 +682,8 @@<br> static int topic_add_subscription(struct stasis_topic *topic, struct stasis_subscription *sub)<br> {<br>   size_t idx;<br>-  SCOPED_AO2LOCK(lock, topic);<br> <br>+      ao2_lock(topic);<br>      /* The reference from the topic to the subscription is shared with<br>     * the owner of the subscription, which will explicitly unsubscribe<br>    * to release it.<br>@@ -682,6 +696,7 @@<br>                topic_add_subscription(<br>                       AST_VECTOR_GET(&topic->upstream_topics, idx), sub);<br>    }<br>+    ao2_unlock(topic);<br> <br>         return 0;<br> }<br>@@ -689,15 +704,18 @@<br> static int topic_remove_subscription(struct stasis_topic *topic, struct stasis_subscription *sub)<br> {<br>  size_t idx;<br>-  SCOPED_AO2LOCK(lock_topic, topic);<br>+   int res;<br> <br>+  ao2_lock(topic);<br>      for (idx = 0; idx < AST_VECTOR_SIZE(&topic->upstream_topics); ++idx) {<br>              topic_remove_subscription(<br>                    AST_VECTOR_GET(&topic->upstream_topics, idx), sub);<br>    }<br>-<br>- return AST_VECTOR_REMOVE_ELEM_UNORDERED(&topic->subscribers, sub,<br>+     res = AST_VECTOR_REMOVE_ELEM_UNORDERED(&topic->subscribers, sub,<br>               AST_VECTOR_ELEM_CLEANUP_NOOP);<br>+       ao2_unlock(topic);<br>+<br>+        return res;<br> }<br> <br> /*!<br>@@ -1214,25 +1232,25 @@<br> struct ast_multi_object_blob *ast_multi_object_blob_create(struct ast_json *blob)<br> {<br>     int type;<br>-    RAII_VAR(struct ast_multi_object_blob *, multi,<br>-                      ao2_alloc(sizeof(*multi), multi_object_blob_dtor),<br>-                   ao2_cleanup);<br>+        struct ast_multi_object_blob *multi;<br> <br>       ast_assert(blob != NULL);<br> <br>+ multi = ao2_alloc(sizeof(*multi), multi_object_blob_dtor);<br>    if (!multi) {<br>                 return NULL;<br>  }<br> <br>  for (type = 0; type < STASIS_UMOS_MAX; ++type) {<br>           if (AST_VECTOR_INIT(&multi->snapshots[type], 0)) {<br>+                    ao2_ref(multi, -1);<br>+<br>                        return NULL;<br>          }<br>     }<br> <br>  multi->blob = ast_json_ref(blob);<br> <br>-      ao2_ref(multi, +1);<br>   return multi;<br> }<br> <br>@@ -1249,9 +1267,9 @@<br> void ast_multi_object_blob_single_channel_publish(struct ast_channel *chan,<br>     struct stasis_message_type *type, struct ast_json *blob)<br> {<br>- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);<br>-       RAII_VAR(struct ast_channel_snapshot *, channel_snapshot, NULL, ao2_cleanup);<br>-        RAII_VAR(struct ast_multi_object_blob *, multi, NULL, ao2_cleanup);<br>+  struct stasis_message *message;<br>+      struct ast_channel_snapshot *channel_snapshot;<br>+       struct ast_multi_object_blob *multi;<br> <br>       if (!type) {<br>          return;<br>@@ -1263,13 +1281,20 @@<br>      }<br> <br>  channel_snapshot = ast_channel_snapshot_create(chan);<br>-        ao2_ref(channel_snapshot, +1);<br>+       if (!channel_snapshot) {<br>+             ao2_ref(multi, -1);<br>+          return;<br>+      }<br>+<br>+ /* this call steals the channel_snapshot reference */<br>         ast_multi_object_blob_add(multi, STASIS_UMOS_CHANNEL, channel_snapshot);<br> <br>   message = stasis_message_create(type, multi);<br>+        ao2_ref(multi, -1);<br>   if (message) {<br>                /* app_userevent still publishes to channel */<br>                stasis_publish(ast_channel_topic(chan), message);<br>+            ao2_ref(message, -1);<br>         }<br> }<br> <br>@@ -1278,7 +1303,7 @@<br>       struct stasis_message *message,<br>       const struct stasis_message_sanitizer *sanitize)<br> {<br>- RAII_VAR(struct ast_json *, out, NULL, ast_json_unref);<br>+      struct ast_json *out;<br>         struct ast_multi_object_blob *multi = stasis_message_data(message);<br>   struct ast_json *blob = multi->blob;<br>       const struct timeval *tv = stasis_message_timestamp(message);<br>@@ -1320,7 +1345,8 @@<br>                  }<br>             }<br>     }<br>-    return ast_json_ref(out);<br>+<br>+ return out;<br> }<br> <br> /*! \internal \brief convert multi object blob to ami string */<br>@@ -1513,17 +1539,19 @@<br> <br> int stasis_message_type_declined(const char *name)<br> {<br>-    RAII_VAR(struct stasis_config *, cfg, ao2_global_obj_ref(globals), ao2_cleanup);<br>+     struct stasis_config *cfg = ao2_global_obj_ref(globals);<br>      char *name_in_declined;<br>       int res;<br> <br>   if (!cfg || !cfg->declined_message_types) {<br>+               ao2_cleanup(cfg);<br>             return 0;<br>     }<br> <br>  name_in_declined = ao2_find(cfg->declined_message_types->declined, name, OBJ_SEARCH_KEY);<br>       res = name_in_declined ? 1 : 0;<br>       ao2_cleanup(name_in_declined);<br>+       ao2_ref(cfg, -1);<br>     if (res) {<br>            ast_log(LOG_NOTICE, "Declining to allocate Stasis message type '%s' due to configuration\n", name);<br>         }<br>@@ -1569,7 +1597,7 @@<br> <br> int stasis_init(void)<br> {<br>-      RAII_VAR(struct stasis_config *, cfg, NULL, ao2_cleanup);<br>+    struct stasis_config *cfg;<br>    int cache_init;<br>       struct ast_threadpool_options threadpool_opts = { 0, };<br> <br>@@ -1605,11 +1633,14 @@<br>           if (aco_set_defaults(&threadpool_option, "threadpool", default_cfg->threadpool_options)) {<br>                   ast_log(LOG_ERROR, "Failed to initialize defaults on Stasis configuration object\n");<br>                       ao2_ref(default_cfg, -1);<br>+<br>                  return -1;<br>            }<br> <br>          if (aco_set_defaults(&declined_option, "declined_message_types", default_cfg->declined_message_types)) {<br>                     ast_log(LOG_ERROR, "Failed to load stasis.conf and failed to initialize defaults.\n");<br>+                     ao2_ref(default_cfg, -1);<br>+<br>                  return -1;<br>            }<br> <br>@@ -1620,6 +1651,7 @@<br>           cfg = ao2_global_obj_ref(globals);<br>            if (!cfg) {<br>                   ast_log(LOG_ERROR, "Failed to obtain Stasis configuration object\n");<br>+<br>                    return -1;<br>            }<br>     }<br>@@ -1630,8 +1662,10 @@<br>     threadpool_opts.max_size = cfg->threadpool_options->max_size;<br>   threadpool_opts.idle_timeout = cfg->threadpool_options->idle_timeout_sec;<br>       pool = ast_threadpool_create("stasis-core", NULL, &threadpool_opts);<br>+   ao2_ref(cfg, -1);<br>     if (!pool) {<br>          ast_log(LOG_ERROR, "Failed to create 'stasis-core' threadpool\n");<br>+<br>               return -1;<br>    }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7905">change 7905</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/7905"/><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: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ib11193531e797bcb16bba560a408eab155f706d1 </div>
<div style="display:none"> Gerrit-Change-Number: 7905 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>