<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7902">View Change</a></p><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, 57 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/02/7902/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/stasis.c b/main/stasis.c<br>index 5f080d1..bb1fbcd 100644<br>--- a/main/stasis.c<br>+++ b/main/stasis.c<br>@@ -424,10 +424,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>@@ -435,10 +435,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>@@ -456,7 +456,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>@@ -488,6 +488,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>@@ -502,11 +504,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>@@ -537,18 +540,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>@@ -562,6 +568,8 @@<br> <br> /* Unsubscribing unrefs the subscription */<br> ao2_cleanup(sub);<br>+ ao2_cleanup(topic);<br>+<br> return NULL;<br> }<br> <br>@@ -580,22 +588,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>@@ -623,13 +635,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>@@ -670,8 +684,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>@@ -684,6 +698,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>@@ -691,15 +706,17 @@<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> <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>+ idx = AST_VECTOR_REMOVE_ELEM_UNORDERED(&topic->subscribers, sub,<br> AST_VECTOR_ELEM_CLEANUP_NOOP);<br>+ ao2_unlock(topic);<br>+<br>+ return idx;<br> }<br> <br> /*!<br>@@ -1216,25 +1233,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>@@ -1251,9 +1268,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>@@ -1265,13 +1282,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>@@ -1280,7 +1304,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>@@ -1322,7 +1346,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>@@ -1515,17 +1540,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>@@ -1571,7 +1598,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>@@ -1632,6 +1659,7 @@<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> return -1;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7902">change 7902</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/7902"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: Ib11193531e797bcb16bba560a408eab155f706d1 </div>
<div style="display:none"> Gerrit-Change-Number: 7902 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>