From 364488f724c536c824a0451af19a06d223d88e01 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Thu, 13 Sep 2018 22:04:55 -0400 Subject: [PATCH] RFC: ao2 reference storage location logging part 3 Change-Id: I60f587ad9f2a790f56a04684a0624fbf3959e005 --- main/astobj2_container.c | 6 +-- main/config_options.c | 6 +-- main/sorcery.c | 46 ++++++++++-------- main/stasis.c | 23 +++++---- main/stasis_cache.c | 21 ++++----- main/taskprocessor.c | 15 +++--- main/threadpool.c | 9 +++- res/res_pjsip/config_global.c | 64 +++++++------------------- res/res_pjsip/pjsip_cli.c | 4 +- res/res_pjsip/pjsip_options.c | 22 ++++----- res/res_pjsip/pjsip_transport_events.c | 12 ++--- res/res_pjsip_mwi.c | 4 +- 12 files changed, 102 insertions(+), 130 deletions(-) diff --git a/main/astobj2_container.c b/main/astobj2_container.c index b740184934..1691bc3620 100644 --- a/main/astobj2_container.c +++ b/main/astobj2_container.c @@ -458,18 +458,18 @@ void *__ao2_weakproxy_find(struct ao2_container *c, const void *arg, enum search ao2_rdlock(c); } - while ((proxy = ao2_find(c, arg, flags | OBJ_NOLOCK))) { + while ((proxy = ao2_find_full(c, arg, flags | OBJ_NOLOCK, "", &proxy))) { obj = __ao2_weakproxy_get_object(proxy, 0, tag ?: __PRETTY_FUNCTION__, file, line, func); if (obj) { - ao2_ref(proxy, -1); + ao2_s_cleanup(&proxy); break; } /* Upgrade to a write lock */ __adjust_lock(c, AO2_LOCK_REQ_WRLOCK, 1); ao2_unlink_flags(c, proxy, OBJ_NOLOCK); - ao2_ref(proxy, -1); + ao2_s_cleanup(&proxy); } if (flags & OBJ_NOLOCK) { diff --git a/main/config_options.c b/main/config_options.c index 41c8b222c9..ac53d091df 100644 --- a/main/config_options.c +++ b/main/config_options.c @@ -926,7 +926,7 @@ int aco_set_defaults(struct aco_type *type, const char *category, void *obj) return -1; } - iter = ao2_iterator_init(type->internal->opts, 0); + ao2_s_iterator_init(&iter, type->internal->opts, 0); while ((opt = ao2_iterator_next(&iter))) { RAII_VAR(struct ast_variable *, var, NULL, ast_variables_destroy); @@ -964,7 +964,7 @@ static char *complete_config_module(const char *word) struct ao2_iterator i; struct ast_xml_doc_item *cur; - i = ao2_iterator_init(xmldocs, 0); + ao2_s_iterator_init(&i, xmldocs, 0); while ((cur = ao2_iterator_next(&i))) { if (!strncasecmp(word, cur->name, wordlen)) { if (ast_cli_completion_add(ast_strdup(cur->name))) { @@ -1167,7 +1167,7 @@ static void cli_show_modules(struct ast_cli_args *a) return; } - it_items = ao2_iterator_init(xmldocs, 0); + ao2_s_iterator_init(&it_items, xmldocs, 0); ast_cli(a->fd, "The following modules have configuration information:\n"); while ((item = ao2_iterator_next(&it_items))) { ast_cli(a->fd, "\t%s\n", item->name); diff --git a/main/sorcery.c b/main/sorcery.c index 5f382a4b08..1e10bfdb79 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -60,8 +60,9 @@ #define OBJECT_FIELD_BUCKETS 29 #define NOTIFY_GENERIC_OBSERVERS(container, type, callback, ...) ({ \ - struct ao2_iterator i = ao2_iterator_init(container, 0); \ + struct ao2_iterator i; \ struct type *observer; \ + ao2_s_iterator_init(&i, container, 0); \ ao2_rdlock(container); \ while ((observer = ao2_iterator_next(&i))) { \ if (observer->callbacks->callback) { \ @@ -570,8 +571,8 @@ static void sorcery_destructor(void *obj) if (sorcery->observers) { NOTIFY_GLOBAL_OBSERVERS(observers, instance_destroying, sorcery->module_name, sorcery); } - ao2_cleanup(sorcery->observers); - ao2_cleanup(sorcery->types); + ao2_s_cleanup(&sorcery->observers); + ao2_s_cleanup(&sorcery->types); } /*! \brief Hashing function for sorcery types */ @@ -621,13 +622,14 @@ struct ast_sorcery *__ast_sorcery_open(const char *module_name, const char *file goto failure_cleanup; } - sorcery->types = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, TYPE_BUCKETS, - ast_sorcery_object_type_hash_fn, ast_sorcery_object_type_cmp_fn); + ao2_s_container_alloc_hash(&sorcery->types, AO2_ALLOC_OPT_LOCK_RWLOCK, 0, TYPE_BUCKETS, + ast_sorcery_object_type_hash_fn, NULL, ast_sorcery_object_type_cmp_fn, ""); if (!sorcery->types) { goto failure_cleanup; } - if (!(sorcery->observers = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, NULL, NULL))) { + ao2_s_container_alloc_list(&sorcery->observers, AO2_ALLOC_OPT_LOCK_RWLOCK, 0, NULL, NULL, ""); + if (!sorcery->observers) { goto failure_cleanup; } @@ -665,11 +667,11 @@ static void sorcery_object_type_destructor(void *obj) struct ast_sorcery_object_type *object_type = obj; AST_VECTOR_RW_WRLOCK(&object_type->wizards); - AST_VECTOR_CALLBACK_VOID(&object_type->wizards, ao2_cleanup); + AST_VECTOR_CALLBACK_VOID(&object_type->wizards, ao2_ref_full, -1, "", &object_type->wizards); AST_VECTOR_RW_UNLOCK(&object_type->wizards); AST_VECTOR_RW_FREE(&object_type->wizards); - ao2_cleanup(object_type->fields); - ao2_cleanup(object_type->observers); + ao2_s_cleanup(&object_type->fields); + ao2_s_cleanup(&object_type->observers); if (object_type->info) { aco_info_destroy(object_type->info); @@ -698,15 +700,15 @@ static struct ast_sorcery_object_type *sorcery_object_type_alloc(const char *typ return NULL; } - object_type->fields = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, - OBJECT_FIELD_BUCKETS, ast_sorcery_object_field_hash_fn, NULL, ast_sorcery_object_field_cmp_fn); + ao2_s_container_alloc_hash(&object_type->fields, AO2_ALLOC_OPT_LOCK_NOLOCK, 0, + OBJECT_FIELD_BUCKETS, ast_sorcery_object_field_hash_fn, NULL, ast_sorcery_object_field_cmp_fn, ""); if (!object_type->fields) { ao2_ref(object_type, -1); return NULL; } - object_type->observers = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, - NULL, NULL); + ao2_s_container_alloc_list(&object_type->observers, AO2_ALLOC_OPT_LOCK_RWLOCK, 0, + NULL, NULL, ""); if (!object_type->observers) { ao2_ref(object_type, -1); return NULL; @@ -756,7 +758,7 @@ static void sorcery_object_wizard_destructor(void *obj) ast_module_unref(object_wizard->wizard->callbacks.module); } - ao2_cleanup(object_wizard->wizard); + ao2_s_cleanup(&object_wizard->wizard); } /*! \brief Return the number of wizards mapped to an object type */ @@ -815,8 +817,10 @@ int __ast_sorcery_remove_wizard_mapping(struct ast_sorcery *sorcery, AST_VECTOR_RW_WRLOCK(&object_type->wizards); #define WIZARD_NAME_COMPARE(a, b) (strcmp((a)->wizard->callbacks.name, (b)) == 0) - res = AST_VECTOR_REMOVE_CMP_ORDERED(&object_type->wizards, name, WIZARD_NAME_COMPARE, ao2_cleanup); +#define WIZARD_NAME_CLEANUP(item) ao2_ref_full(item, -1, "", &object_type->wizards) + res = AST_VECTOR_REMOVE_CMP_ORDERED(&object_type->wizards, name, WIZARD_NAME_COMPARE, WIZARD_NAME_CLEANUP); #undef WIZARD_NAME_COMPARE +#undef WIZARD_NAME_CLEANUP AST_VECTOR_RW_UNLOCK(&object_type->wizards); return res; @@ -829,9 +833,11 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor { RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup); RAII_VAR(struct ast_sorcery_internal_wizard *, wizard, ao2_find(wizards, name, OBJ_KEY), ao2_cleanup); - RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, ao2_alloc(sizeof(*object_wizard), sorcery_object_wizard_destructor), ao2_cleanup); + RAII_AO2_S(struct ast_sorcery_object_wizard *, object_wizard, NULL); int created = 0; + ao2_s_alloc(&object_wizard, sizeof(*object_wizard), sorcery_object_wizard_destructor, + AO2_ALLOC_OPT_LOCK_MUTEX, ""); if (!object_wizard) { return AST_SORCERY_APPLY_FAIL; } @@ -876,7 +882,7 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor return AST_SORCERY_APPLY_FAIL; } - object_wizard->wizard = ao2_bump(wizard); + ao2_s_set(&object_wizard->wizard, wizard); object_wizard->caching = caching; if (position == AST_SORCERY_WIZARD_POSITION_LAST) { @@ -888,7 +894,7 @@ enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sor return AST_SORCERY_APPLY_FAIL; } AST_VECTOR_RW_UNLOCK(&object_type->wizards); - ao2_bump(object_wizard); + ao2_ref_full(object_wizard, +1, "", &object_type->wizards); if (created) { ao2_link(sorcery->types, object_type); @@ -1407,7 +1413,7 @@ struct ast_variable *ast_sorcery_objectset_create2(const struct ast_sorcery *sor return NULL; } - i = ao2_iterator_init(object_type->fields, 0); + ao2_s_iterator_init(&i, object_type->fields, 0); for (; (object_field = ao2_iterator_next(&i)); ao2_ref(object_field, -1)) { struct ast_variable *tmp; @@ -1461,7 +1467,7 @@ struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sor return NULL; } - i = ao2_iterator_init(object_type->fields, 0); + ao2_s_iterator_init(&i, object_type->fields, 0); for (; !res && (object_field = ao2_iterator_next(&i)); ao2_ref(object_field, -1)) { if (object_field->multiple_handler) { diff --git a/main/stasis.c b/main/stasis.c index 1616debf3e..531faf55e5 100644 --- a/main/stasis.c +++ b/main/stasis.c @@ -841,7 +841,7 @@ static void publish_msg(struct stasis_topic *topic, * The topic may be unref'ed by the subscription invocation. * Make sure we hold onto a reference while dispatching. */ - ao2_ref(topic, +1); + ao2_s_init(&topic); ao2_lock(topic); for (i = 0; i < AST_VECTOR_SIZE(&topic->subscribers); ++i) { struct stasis_subscription *sub = AST_VECTOR_GET(&topic->subscribers, i); @@ -851,7 +851,7 @@ static void publish_msg(struct stasis_topic *topic, dispatch_message(sub, message, (sub == sync_sub)); } ao2_unlock(topic); - ao2_ref(topic, -1); + ao2_s_cleanup(&topic); } void stasis_publish(struct stasis_topic *topic, struct stasis_message *message) @@ -885,9 +885,9 @@ static void forward_dtor(void *obj) { struct stasis_forward *forward = obj; - ao2_cleanup(forward->from_topic); + ao2_s_cleanup(&forward->from_topic); forward->from_topic = NULL; - ao2_cleanup(forward->to_topic); + ao2_s_cleanup(&forward->to_topic); forward->to_topic = NULL; } @@ -942,8 +942,8 @@ struct stasis_forward *stasis_forward_all(struct stasis_topic *from_topic, return forward; } - forward->from_topic = ao2_bump(from_topic); - forward->to_topic = ao2_bump(to_topic); + ao2_s_set(&forward->from_topic, from_topic); + ao2_s_set(&forward->to_topic, to_topic); topic_lock_both(to_topic, from_topic); res = AST_VECTOR_APPEND(&to_topic->upstream_topics, from_topic); @@ -1079,9 +1079,9 @@ static void topic_pool_dtor(void *obj) { struct stasis_topic_pool *pool = obj; - ao2_cleanup(pool->pool_container); + ao2_s_cleanup(&pool->pool_container); pool->pool_container = NULL; - ao2_cleanup(pool->pool_topic); + ao2_s_cleanup(&pool->pool_topic); pool->pool_topic = NULL; } @@ -1152,14 +1152,13 @@ struct stasis_topic_pool *stasis_topic_pool_create(struct stasis_topic *pooled_t return NULL; } - pool->pool_container = ao2_container_alloc(TOPIC_POOL_BUCKETS, - topic_pool_entry_hash, topic_pool_entry_cmp); + ao2_s_container_alloc_hash(&pool->pool_container, AO2_ALLOC_OPT_LOCK_MUTEX, 0, TOPIC_POOL_BUCKETS, + topic_pool_entry_hash, NULL, topic_pool_entry_cmp, ""); if (!pool->pool_container) { ao2_cleanup(pool); return NULL; } - ao2_ref(pooled_topic, +1); - pool->pool_topic = pooled_topic; + ao2_s_set(&pool->pool_topic, pooled_topic); return pool; } diff --git a/main/stasis_cache.c b/main/stasis_cache.c index 9907c6c226..c89e3e8adb 100644 --- a/main/stasis_cache.c +++ b/main/stasis_cache.c @@ -74,11 +74,11 @@ static void stasis_caching_topic_dtor(void *obj) ao2_cleanup(caching_topic->sub); caching_topic->sub = NULL; - ao2_cleanup(caching_topic->cache); + ao2_s_cleanup(&caching_topic->cache); caching_topic->cache = NULL; ao2_cleanup(caching_topic->topic); caching_topic->topic = NULL; - ao2_cleanup(caching_topic->original_topic); + ao2_s_cleanup(&caching_topic->original_topic); caching_topic->original_topic = NULL; } @@ -747,9 +747,9 @@ static void stasis_cache_update_dtor(void *obj) { struct stasis_cache_update *update = obj; - ao2_cleanup(update->old_snapshot); + ao2_s_cleanup(&update->old_snapshot); update->old_snapshot = NULL; - ao2_cleanup(update->new_snapshot); + ao2_s_cleanup(&update->new_snapshot); update->new_snapshot = NULL; ao2_cleanup(update->type); update->type = NULL; @@ -773,16 +773,14 @@ static struct stasis_message *update_create(struct stasis_message *old_snapshot, } if (old_snapshot) { - ao2_ref(old_snapshot, +1); - update->old_snapshot = old_snapshot; + ao2_s_set(&update->old_snapshot, old_snapshot); if (!new_snapshot) { ao2_ref(stasis_message_type(old_snapshot), +1); update->type = stasis_message_type(old_snapshot); } } if (new_snapshot) { - ao2_ref(new_snapshot, +1); - update->new_snapshot = new_snapshot; + ao2_s_set(&update->new_snapshot, new_snapshot); ao2_ref(stasis_message_type(new_snapshot), +1); update->type = stasis_message_type(new_snapshot); } @@ -931,8 +929,8 @@ struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *or return NULL; } - ao2_ref(cache, +1); - caching_topic->cache = cache; + ao2_s_set(&caching_topic->cache, cache); + if (!cache->registered) { if (ao2_container_register(new_name, cache->entries, print_cache_entry)) { ast_log(LOG_ERROR, "Stasis cache container '%p' for '%s' did not register\n", @@ -950,8 +948,7 @@ struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *or return NULL; } - ao2_ref(original_topic, +1); - caching_topic->original_topic = original_topic; + ao2_s_set(&caching_topic->original_topic, original_topic); /* The subscription holds the reference, so no additional ref bump. */ return caching_topic; diff --git a/main/taskprocessor.c b/main/taskprocessor.c index 91eb7d9930..2aed0334f0 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -645,8 +645,7 @@ static void tps_taskprocessor_dtor(void *tps) t->stats = NULL; ast_free((char *) t->name); t->name = NULL; - ao2_cleanup(t->listener); - t->listener = NULL; + ao2_s_replace(&t->listener, NULL); } /* pop the front task and return it */ @@ -682,7 +681,7 @@ const char *ast_taskprocessor_name(struct ast_taskprocessor *tps) static void listener_shutdown(struct ast_taskprocessor_listener *listener) { listener->callbacks->shutdown(listener); - ao2_ref(listener->tps, -1); + ao2_s_cleanup(&listener->tps); } static void taskprocessor_listener_dtor(void *obj) @@ -757,18 +756,16 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru return NULL; } - ao2_ref(listener, +1); - p->listener = listener; + ao2_s_set(&p->listener, listener); p->thread = AST_PTHREADT_NULL; - ao2_ref(p, +1); - listener->tps = p; + ao2_s_set(&listener->tps, p); if (!(ao2_link(tps_singletons, p))) { ast_log(LOG_ERROR, "Failed to add taskprocessor '%s' to container\n", p->name); - listener->tps = NULL; - ao2_ref(p, -2); + ao2_s_replace(&listener->tps, NULL); + ao2_ref(p, -1); return NULL; } diff --git a/main/threadpool.c b/main/threadpool.c index be7e23d8f1..de040215b5 100644 --- a/main/threadpool.c +++ b/main/threadpool.c @@ -1349,7 +1349,7 @@ static void serializer_shutdown(struct ast_taskprocessor_listener *listener) if (ser->shutdown_group) { serializer_shutdown_group_dec(ser->shutdown_group); } - ao2_cleanup(ser); + ao2_ref_full(ser, -1, "", listener); } static struct ast_taskprocessor_listener_callbacks serializer_tps_listener_callbacks = { @@ -1381,10 +1381,15 @@ struct ast_taskprocessor *ast_threadpool_serializer_group(const char *name, return NULL; } + if (ast_opt_ref_debug) { + ao2_ref_full(ser, +1, "", listener); + ao2_ref(ser, -1); + } + tps = ast_taskprocessor_create_with_listener(name, listener); if (!tps) { /* ser ref transferred to listener but not cleaned without tps */ - ao2_ref(ser, -1); + ao2_ref_full(ser, -1, "", listener); } else if (shutdown_group) { serializer_shutdown_group_inc(shutdown_group); } diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c index b3d6fa28b8..c19309fafb 100644 --- a/res/res_pjsip/config_global.c +++ b/res/res_pjsip/config_global.c @@ -160,45 +160,39 @@ static struct global_config *get_global_cfg(void) char *ast_sip_global_default_outbound_endpoint(void) { char *str; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return ast_strdup(DEFAULT_OUTBOUND_ENDPOINT); } str = ast_strdup(cfg->default_outbound_endpoint); - ao2_ref(cfg, -1); return str; } char *ast_sip_get_debug(void) { char *res; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return ast_strdup(DEFAULT_DEBUG); } res = ast_strdup(cfg->debug); - ao2_ref(cfg, -1); return res; } char *ast_sip_get_regcontext(void) { char *res; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return ast_strdup(DEFAULT_REGCONTEXT); } res = ast_strdup(cfg->regcontext); - ao2_ref(cfg, -1); return res; } @@ -206,15 +200,13 @@ char *ast_sip_get_regcontext(void) char *ast_sip_get_default_voicemail_extension(void) { char *res; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return ast_strdup(DEFAULT_VOICEMAIL_EXTENSION); } res = ast_strdup(cfg->default_voicemail_extension); - ao2_ref(cfg, -1); return res; } @@ -222,84 +214,73 @@ char *ast_sip_get_default_voicemail_extension(void) char *ast_sip_get_endpoint_identifier_order(void) { char *res; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return ast_strdup(DEFAULT_ENDPOINT_IDENTIFIER_ORDER); } res = ast_strdup(cfg->endpoint_identifier_order); - ao2_ref(cfg, -1); return res; } unsigned int ast_sip_get_keep_alive_interval(void) { unsigned int interval; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_KEEPALIVE_INTERVAL; } interval = cfg->keep_alive_interval; - ao2_ref(cfg, -1); return interval; } unsigned int ast_sip_get_contact_expiration_check_interval(void) { unsigned int interval; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_CONTACT_EXPIRATION_CHECK_INTERVAL; } interval = cfg->contact_expiration_check_interval; - ao2_ref(cfg, -1); return interval; } unsigned int ast_sip_get_disable_multi_domain(void) { unsigned int disable_multi_domain; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_DISABLE_MULTI_DOMAIN; } disable_multi_domain = cfg->disable_multi_domain; - ao2_ref(cfg, -1); return disable_multi_domain; } unsigned int ast_sip_get_max_initial_qualify_time(void) { unsigned int time; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_MAX_INITIAL_QUALIFY_TIME; } time = cfg->max_initial_qualify_time; - ao2_ref(cfg, -1); return time; } void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned int *period, unsigned int *prune_interval) { - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { *count = DEFAULT_UNIDENTIFIED_REQUEST_COUNT; *period = DEFAULT_UNIDENTIFIED_REQUEST_PERIOD; @@ -311,33 +292,28 @@ void ast_sip_get_unidentified_request_thresholds(unsigned int *count, unsigned i *period = cfg->unidentified_request_period; *prune_interval = cfg->unidentified_request_prune_interval; - ao2_ref(cfg, -1); return; } void ast_sip_get_default_realm(char *realm, size_t size) { - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { ast_copy_string(realm, DEFAULT_REALM, size); } else { ast_copy_string(realm, cfg->default_realm, size); - ao2_ref(cfg, -1); } } void ast_sip_get_default_from_user(char *from_user, size_t size) { - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { ast_copy_string(from_user, DEFAULT_FROM_USER, size); } else { ast_copy_string(from_user, cfg->default_from_user, size); - ao2_ref(cfg, -1); } } @@ -345,60 +321,52 @@ void ast_sip_get_default_from_user(char *from_user, size_t size) unsigned int ast_sip_get_mwi_tps_queue_high(void) { unsigned int tps_queue_high; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_MWI_TPS_QUEUE_HIGH; } tps_queue_high = cfg->mwi.tps_queue_high; - ao2_ref(cfg, -1); return tps_queue_high; } int ast_sip_get_mwi_tps_queue_low(void) { int tps_queue_low; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_MWI_TPS_QUEUE_LOW; } tps_queue_low = cfg->mwi.tps_queue_low; - ao2_ref(cfg, -1); return tps_queue_low; } unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void) { unsigned int disable_initial_unsolicited; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED; } disable_initial_unsolicited = cfg->mwi.disable_initial_unsolicited; - ao2_ref(cfg, -1); return disable_initial_unsolicited; } unsigned int ast_sip_get_ignore_uri_user_options(void) { unsigned int ignore_uri_user_options; - struct global_config *cfg; + RAII_AO2_S_GLOBAL(struct global_config *, cfg, global_cfg); - cfg = get_global_cfg(); if (!cfg) { return DEFAULT_IGNORE_URI_USER_OPTIONS; } ignore_uri_user_options = cfg->ignore_uri_user_options; - ao2_ref(cfg, -1); return ignore_uri_user_options; } diff --git a/res/res_pjsip/pjsip_cli.c b/res/res_pjsip/pjsip_cli.c index 4544a1717d..e4a44426dd 100644 --- a/res/res_pjsip/pjsip_cli.c +++ b/res/res_pjsip/pjsip_cli.c @@ -319,6 +319,8 @@ int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter ast_assert(formatter->retrieve_by_id != NULL); ao2_link(formatter_registry, formatter); + /* Drop allocation ref now. */ + ao2_ref(formatter, -1); return 0; } @@ -327,7 +329,7 @@ int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatt { if (formatter) { ao2_wrlock(formatter_registry); - if (ao2_ref(formatter, -1) == 2) { + if (ao2_ref(formatter, 0) == 1) { ao2_unlink_flags(formatter_registry, formatter, OBJ_NOLOCK); } ao2_unlock(formatter_registry); diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c index f2439c4e80..ddf2245299 100644 --- a/res/res_pjsip/pjsip_options.c +++ b/res/res_pjsip/pjsip_options.c @@ -561,7 +561,7 @@ static enum ast_endpoint_state sip_options_get_endpoint_state_compositor_state( struct sip_options_endpoint_aor_status *aor_status; enum ast_endpoint_state state = AST_ENDPOINT_OFFLINE; - it_aor_statuses = ao2_iterator_init(endpoint_state_compositor->aor_statuses, 0); + ao2_s_iterator_init(&it_aor_statuses, endpoint_state_compositor->aor_statuses, 0); for (; (aor_status = ao2_iterator_next(&it_aor_statuses)); ao2_ref(aor_status, -1)) { if (aor_status->available) { state = AST_ENDPOINT_ONLINE; @@ -949,9 +949,9 @@ static void sip_options_aor_dtor(void *obj) if (aor_options->contacts) { ao2_callback(aor_options->contacts, OBJ_NODATA | OBJ_UNLINK, sip_options_remove_contact, aor_options); - ao2_ref(aor_options->contacts, -1); + ao2_s_cleanup(&aor_options->contacts); } - ao2_cleanup(aor_options->dynamic_contacts); + ao2_s_cleanup(&aor_options->dynamic_contacts); ast_taskprocessor_unreference(aor_options->serializer); @@ -987,17 +987,17 @@ static struct sip_options_aor *sip_options_aor_alloc(struct ast_sip_aor *aor) return NULL; } - aor_options->contacts = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, + ao2_s_container_alloc_hash(&aor_options->contacts, AO2_ALLOC_OPT_LOCK_NOLOCK, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, CONTACT_BUCKETS, ast_sorcery_object_id_hash, - ast_sorcery_object_id_sort, ast_sorcery_object_id_compare); + ast_sorcery_object_id_sort, ast_sorcery_object_id_compare, ""); if (!aor_options->contacts) { ao2_ref(aor_options, -1); return NULL; } - aor_options->dynamic_contacts = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, + ao2_s_container_alloc_hash(&aor_options->dynamic_contacts, AO2_ALLOC_OPT_LOCK_NOLOCK, AO2_CONTAINER_ALLOC_OPT_DUPS_REJECT, CONTACT_BUCKETS, ast_sorcery_object_id_hash, - ast_sorcery_object_id_sort, ast_sorcery_object_id_compare); + ast_sorcery_object_id_sort, ast_sorcery_object_id_compare, ""); if (!aor_options->dynamic_contacts) { ao2_ref(aor_options, -1); return NULL; @@ -1266,7 +1266,7 @@ static void sip_options_apply_aor_configuration(struct sip_options_aor *aor_opti /* Process permanent contacts */ if (aor->permanent_contacts) { - iter = ao2_iterator_init(aor->permanent_contacts, 0); + ao2_s_iterator_init(&iter, aor->permanent_contacts, 0); for (; (contact = ao2_iterator_next(&iter)); ao2_ref(contact, -1)) { ao2_find(existing_contacts, ast_sorcery_object_get_id(contact), OBJ_NODATA | OBJ_UNLINK | OBJ_SEARCH_KEY); @@ -1296,7 +1296,7 @@ static void sip_options_apply_aor_configuration(struct sip_options_aor *aor_opti } /* Process dynamic contacts */ - iter = ao2_iterator_init(aor_options->dynamic_contacts, 0); + ao2_s_iterator_init(&iter, aor_options->dynamic_contacts, 0); for (; (contact = ao2_iterator_next(&iter)); ao2_ref(contact, -1)) { ao2_find(existing_contacts, ast_sorcery_object_get_id(contact), OBJ_NODATA | OBJ_UNLINK | OBJ_SEARCH_KEY); @@ -1826,7 +1826,7 @@ static void sip_options_endpoint_unlink_aor_feeders(struct ast_sip_endpoint *end endpoint_state_compositor->active = 0; /* Unlink AOR feeders pointing to endpoint */ - it_aor_statuses = ao2_iterator_init(endpoint_state_compositor->aor_statuses, 0); + ao2_s_iterator_init(&it_aor_statuses, endpoint_state_compositor->aor_statuses, 0); for (; (aor_status = ao2_iterator_next(&it_aor_statuses)); ao2_ref(aor_status, -1)) { task_data.aor_options = ao2_find(sip_options_aors, aor_status->name, OBJ_SEARCH_KEY); @@ -2765,7 +2765,7 @@ static int sip_options_cleanup_task(void *obj) return 0; } - it_aor = ao2_iterator_init(sip_options_aors, AO2_ITERATOR_UNLINK); + ao2_s_iterator_init(&it_aor, sip_options_aors, AO2_ITERATOR_UNLINK); for (; (aor_options = ao2_iterator_next(&it_aor)); ao2_ref(aor_options, -1)) { ast_sip_push_task_wait_serializer(aor_options->serializer, sip_options_cleanup_aor_task, aor_options); diff --git a/res/res_pjsip/pjsip_transport_events.c b/res/res_pjsip/pjsip_transport_events.c index cc7b7c077a..3d5dfb448f 100644 --- a/res/res_pjsip/pjsip_transport_events.c +++ b/res/res_pjsip/pjsip_transport_events.c @@ -257,7 +257,7 @@ static int ptr_matcher(void *a, void *b) void ast_sip_transport_monitor_unregister_all(ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches) { - struct ao2_container *transports; + RAII_AO2_S_GLOBAL(struct ao2_container *, transports, active_transports); struct callback_data cb_data = { .cb = cb, .data = data, @@ -266,18 +266,16 @@ void ast_sip_transport_monitor_unregister_all(ast_transport_monitor_shutdown_cb ast_assert(cb != NULL); - transports = ao2_global_obj_ref(active_transports); if (!transports) { return; } ao2_callback(transports, OBJ_MULTIPLE | OBJ_NODATA, transport_monitor_unregister_cb, &cb_data); - ao2_ref(transports, -1); } void ast_sip_transport_monitor_unregister(pjsip_transport *transport, ast_transport_monitor_shutdown_cb cb, void *data, ast_transport_monitor_data_matcher matches) { - struct ao2_container *transports; + RAII_AO2_S_GLOBAL(struct ao2_container *, transports, active_transports); struct transport_monitor *monitored; ast_assert(transport != NULL && cb != NULL); @@ -388,14 +386,14 @@ int ast_sip_initialize_transport_events(void) return -1; } - transports = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, + ao2_s_container_alloc_hash(&transports, AO2_ALLOC_OPT_LOCK_MUTEX, 0, ACTIVE_TRANSPORTS_BUCKETS, transport_monitor_hash_fn, NULL, - transport_monitor_cmp_fn); + transport_monitor_cmp_fn, ""); if (!transports) { return -1; } ao2_global_obj_replace_unref(active_transports, transports); - ao2_ref(transports, -1); + ao2_s_cleanup(&transports); tpmgr_state_callback = pjsip_tpmgr_get_state_cb(tpmgr); pjsip_tpmgr_set_state_cb(tpmgr, &transport_state_callback); diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c index 4cd892c05b..a0c8d251f4 100644 --- a/res/res_pjsip_mwi.c +++ b/res/res_pjsip_mwi.c @@ -327,7 +327,7 @@ static void mwi_subscription_destructor(void *obj) if (sub->is_solicited) { ast_sip_subscription_destroy(sub->sip_sub); } - ao2_cleanup(sub->stasis_subs); + ao2_s_cleanup(&sub->stasis_subs); ast_free(sub->aors); } @@ -358,7 +358,7 @@ static struct mwi_subscription *mwi_subscription_alloc(struct ast_sip_endpoint * sub->sip_sub = sip_sub; } - sub->stasis_subs = ao2_container_alloc(STASIS_BUCKETS, stasis_sub_hash, stasis_sub_cmp); + ao2_s_container_alloc_hash(&sub->stasis_subs, AO2_ALLOC_OPT_LOCK_MUTEX, 0, STASIS_BUCKETS, stasis_sub_hash, NULL, stasis_sub_cmp, ""); if (!sub->stasis_subs) { ao2_cleanup(sub); return NULL; -- 2.17.1