diff --git a/channels/chan_sip.c b/channels/chan_sip.c index b90eb4ca25fe5111e9179886bb2ffabb99389cfe..ff4c5609eed3032f1dc8f532536617a62da3edd3 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -35347,12 +35347,18 @@ static int load_module(void) /* the fact that ao2_containers can't resize automatically is a major worry! */ /* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */ - peers = ao2_t_container_alloc(HASH_PEER_SIZE, peer_hash_cb, peer_cmp_cb, "allocate peers"); - peers_by_ip = ao2_t_container_alloc(HASH_PEER_SIZE, peer_iphash_cb, NULL, "allocate peers_by_ip"); - dialogs = ao2_t_container_alloc(HASH_DIALOG_SIZE, dialog_hash_cb, dialog_cmp_cb, "allocate dialogs"); - dialogs_needdestroy = ao2_t_container_alloc(1, NULL, NULL, "allocate dialogs_needdestroy"); - dialogs_rtpcheck = ao2_t_container_alloc(HASH_DIALOG_SIZE, dialog_hash_cb, dialog_cmp_cb, "allocate dialogs for rtpchecks"); - threadt = ao2_t_container_alloc(HASH_DIALOG_SIZE, threadt_hash_cb, threadt_cmp_cb, "allocate threadt table"); + peers = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, HASH_PEER_SIZE, + peer_hash_cb, NULL, peer_cmp_cb, "allocate peers"); + peers_by_ip = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, HASH_PEER_SIZE, + peer_iphash_cb, NULL, NULL, "allocate peers_by_ip"); + dialogs = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, HASH_DIALOG_SIZE, + dialog_hash_cb, NULL, dialog_cmp_cb, "allocate dialogs"); + dialogs_needdestroy = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 1, + NULL, NULL, NULL, "allocate dialogs_needdestroy"); + dialogs_rtpcheck = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, HASH_DIALOG_SIZE, + dialog_hash_cb, NULL, dialog_cmp_cb, "allocate dialogs for rtpchecks"); + threadt = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, HASH_DIALOG_SIZE, + threadt_hash_cb, NULL, threadt_cmp_cb, "allocate threadt table"); if (!peers || !peers_by_ip || !dialogs || !dialogs_needdestroy || !dialogs_rtpcheck || !threadt) { ast_log(LOG_ERROR, "Unable to create primary SIP container(s)\n"); @@ -35366,7 +35372,8 @@ static int load_module(void) } ast_format_cap_append_by_type(sip_tech.capabilities, AST_MEDIA_TYPE_AUDIO); - registry_list = ao2_t_container_alloc(HASH_REGISTRY_SIZE, registry_hash_cb, registry_cmp_cb, "allocate registry_list"); + registry_list = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, HASH_REGISTRY_SIZE, + registry_hash_cb, NULL, registry_cmp_cb, "allocate registry_list"); subscription_mwi_list = ao2_t_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, AO2_CONTAINER_ALLOC_OPT_INSERT_BEGIN, NULL, NULL, "allocate subscription_mwi_list"); diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index 03752015c3f2fa16e53674add55783c3fea3bd79..0e32e893c9353c04bef99f4ecf0bdbfbcfff3bb3 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -1218,6 +1218,7 @@ typedef int (ao2_sort_fn)(const void *obj_left, const void *obj_right, int flags struct ao2_container; /*! + * \deprecated * \brief Allocate and initialize a hash container with the desired number of buckets. * * \details @@ -1235,16 +1236,20 @@ struct ao2_container; * \note Destructor is set implicitly. * \note This is legacy container creation that is mapped to the new method. */ +#define ao2_container_alloc(n_buckets, hash_fn, cmp_fn) \ + ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, (n_buckets), (hash_fn), NULL, (cmp_fn)) +#ifndef AST_IN_CORE +/* These macros are removed from Asterisk 17. They are still available to modules + * but should only be used by third party modules that have not been updated. */ #define ao2_t_container_alloc_options(options, n_buckets, hash_fn, cmp_fn, tag) \ ao2_t_container_alloc_hash((options), 0, (n_buckets), (hash_fn), NULL, (cmp_fn), (tag)) #define ao2_container_alloc_options(options, n_buckets, hash_fn, cmp_fn) \ ao2_container_alloc_hash((options), 0, (n_buckets), (hash_fn), NULL, (cmp_fn)) #define ao2_t_container_alloc(n_buckets, hash_fn, cmp_fn, tag) \ - ao2_t_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn), (tag)) -#define ao2_container_alloc(n_buckets, hash_fn, cmp_fn) \ - ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_MUTEX, (n_buckets), (hash_fn), (cmp_fn)) + ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, (n_buckets), (hash_fn), NULL, (cmp_fn), (tag)) +#endif /*! * \brief Allocate and initialize a hash container with the desired number of buckets. diff --git a/main/bridge.c b/main/bridge.c index 0f3cfb1bb9be3618ef7a5a5aed40d074d9ea41cb..17e25b6996e253b7893500139138fadb954b8046 100644 --- a/main/bridge.c +++ b/main/bridge.c @@ -3985,8 +3985,8 @@ struct ao2_container *ast_bridge_peers_nolock(struct ast_bridge *bridge) struct ao2_container *channels; struct ast_bridge_channel *iter; - channels = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, - 13, channel_hash, channel_cmp); + channels = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, + 13, channel_hash, NULL, channel_cmp); if (!channels) { return NULL; } diff --git a/main/bucket.c b/main/bucket.c index 084d25368d88e940be7c216836affd9647872f5e..6246a94962ee19d053e9dff2dcf98fd0c795afd0 100644 --- a/main/bucket.c +++ b/main/bucket.c @@ -592,8 +592,8 @@ static void *bucket_file_alloc(const char *name) return NULL; } - file->metadata = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, METADATA_BUCKETS, - ast_bucket_metadata_hash_fn, ast_bucket_metadata_cmp_fn); + file->metadata = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, METADATA_BUCKETS, + ast_bucket_metadata_hash_fn, NULL, ast_bucket_metadata_cmp_fn); if (!file->metadata) { return NULL; } @@ -864,8 +864,8 @@ int ast_bucket_init(void) { ast_register_cleanup(&bucket_cleanup); - schemes = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, SCHEME_BUCKETS, - ast_bucket_scheme_hash_fn, ast_bucket_scheme_cmp_fn); + schemes = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, SCHEME_BUCKETS, + ast_bucket_scheme_hash_fn, NULL, ast_bucket_scheme_cmp_fn); if (!schemes) { ast_log(LOG_ERROR, "Failed to create container for Bucket schemes\n"); return -1; diff --git a/main/ccss.c b/main/ccss.c index 67c6faed95e065d659934fafc06f62735d7aa786..7ff77fdab255b3f8d051e474b835f42aaf046d32 100644 --- a/main/ccss.c +++ b/main/ccss.c @@ -4653,14 +4653,19 @@ int ast_cc_init(void) { int res; - if (!(cc_core_instances = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS, - cc_core_instance_hash_fn, cc_core_instance_cmp_fn, - "Create core instance container"))) { + cc_core_instances = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, + CC_CORE_INSTANCES_BUCKETS, + cc_core_instance_hash_fn, NULL, cc_core_instance_cmp_fn, + "Create core instance container"); + if (!cc_core_instances) { return -1; } - if (!(generic_monitors = ao2_t_container_alloc(CC_CORE_INSTANCES_BUCKETS, - generic_monitor_instance_list_hash_fn, generic_monitor_instance_list_cmp_fn, - "Create generic monitor container"))) { + + generic_monitors = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, + CC_CORE_INSTANCES_BUCKETS, + generic_monitor_instance_list_hash_fn, NULL, generic_monitor_instance_list_cmp_fn, + "Create generic monitor container"); + if (!generic_monitors) { return -1; } if (!(cc_core_taskprocessor = ast_taskprocessor_get("CCSS_core", TPS_REF_DEFAULT))) { diff --git a/main/channel.c b/main/channel.c index d13d3f5f8e7ab6ca1f08031df11c7e11e7091461..e5bd8794d6bbe16ffd3602056163e594a35de685 100644 --- a/main/channel.c +++ b/main/channel.c @@ -7632,8 +7632,8 @@ struct ast_namedgroups *ast_get_namedgroups(const char *s) return NULL; } - namedgroups = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 19, - namedgroup_hash_cb, namedgroup_cmp_cb); + namedgroups = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, 19, + namedgroup_hash_cb, NULL, namedgroup_cmp_cb); if (!namedgroups) { return NULL; } diff --git a/main/codec.c b/main/codec.c index 05cee4ab648faafec2547a9c62754199aee800b6..3d48c7e43ec3141ef1720bae23d987ae1574d18d 100644 --- a/main/codec.c +++ b/main/codec.c @@ -250,8 +250,8 @@ static void codec_shutdown(void) int ast_codec_init(void) { - codecs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CODEC_BUCKETS, - ast_codec_hash_fn, codec_cmp); + codecs = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, CODEC_BUCKETS, + ast_codec_hash_fn, NULL, codec_cmp); if (!codecs) { return -1; } diff --git a/main/features_config.c b/main/features_config.c index 3dac8272e05a52a0bd00760a38bffaf8f22f4e21..de81b7029e1e2d9edee6e0fe7de44905f9e7ebbb 100644 --- a/main/features_config.c +++ b/main/features_config.c @@ -757,8 +757,8 @@ static struct features_config *__features_config_alloc(int allocate_applicationm return NULL; } - cfg->featuregroups = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 11, featuregroup_hash, - featuregroup_cmp); + cfg->featuregroups = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, 11, + featuregroup_hash, NULL, featuregroup_cmp); if (!cfg->featuregroups) { return NULL; } diff --git a/main/format.c b/main/format.c index b81a1f1d4ca0c2acba1fca105ee6ab0ee711d21d..0534acdc9eddffdd67519e80b73b834cf1d6eaab 100644 --- a/main/format.c +++ b/main/format.c @@ -76,8 +76,8 @@ static void format_shutdown(void) int ast_format_init(void) { - interfaces = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, FORMAT_INTERFACE_BUCKETS, - format_interface_hash_fn, format_interface_cmp_fn); + interfaces = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, + FORMAT_INTERFACE_BUCKETS, format_interface_hash_fn, NULL, format_interface_cmp_fn); if (!interfaces) { return -1; } diff --git a/main/format_cache.c b/main/format_cache.c index 3de1951a302a491dfd4d9b3dc96a2a1ad8a59f9c..e6277ee11ef6994c84e0316df0f0909f5e464e35 100644 --- a/main/format_cache.c +++ b/main/format_cache.c @@ -353,8 +353,8 @@ static void format_cache_shutdown(void) int ast_format_cache_init(void) { - formats = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, CACHE_BUCKETS, - format_hash_cb, format_cmp_cb); + formats = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, CACHE_BUCKETS, + format_hash_cb, NULL, format_cmp_cb); if (!formats) { return -1; } diff --git a/main/pbx.c b/main/pbx.c index bcfd42d9eaebfa984c64402ccac46acbb33eb991..c87496b7307b761590085c65054edac4419f7f1c 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -3014,7 +3014,7 @@ static void device_state_info_dt(void *obj) static struct ao2_container *alloc_device_state_info(void) { - return ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL); + return ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL); } static int ast_extension_state3(struct ast_str *hint_app, struct ao2_container *device_state_info) diff --git a/main/pickup.c b/main/pickup.c index 6f1e0f12f6eee70f62be8db0ccd12b321ce8ea5e..dc695c7322c8162e200c5c4827f8dbe9bacfbbfb 100644 --- a/main/pickup.c +++ b/main/pickup.c @@ -137,7 +137,7 @@ struct ast_channel *ast_pickup_find_by_group(struct ast_channel *chan) struct ao2_container *candidates;/*!< Candidate channels found to pickup. */ struct ast_channel *target;/*!< Potential pickup target */ - candidates = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL); + candidates = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL); if (!candidates) { return NULL; } diff --git a/main/sorcery.c b/main/sorcery.c index 2418ce3eed7e025b2ff40def4187b351e5850001..7b01374593851e3568ae695d0a86b0af0f4b47e9 100644 --- a/main/sorcery.c +++ b/main/sorcery.c @@ -611,8 +611,8 @@ struct ast_sorcery *__ast_sorcery_open(const char *module_name) goto done; } - 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); + sorcery->types = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, TYPE_BUCKETS, + ast_sorcery_object_type_hash_fn, NULL, ast_sorcery_object_type_cmp_fn); if (!sorcery->types) { ao2_ref(sorcery, -1); sorcery = NULL; @@ -1761,7 +1761,8 @@ void *ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const ch /* If returning multiple objects create a container to store them in */ if ((flags & AST_RETRIEVE_FLAG_MULTIPLE)) { - if (!(object = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL))) { + object = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL); + if (!object) { return NULL; } } @@ -1805,7 +1806,12 @@ struct ao2_container *ast_sorcery_retrieve_by_regex(const struct ast_sorcery *so struct ao2_container *objects; int i; - if (!object_type || !(objects = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL))) { + if (!object_type) { + return NULL; + } + + objects = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL); + if (!objects) { return NULL; } @@ -1835,7 +1841,12 @@ struct ao2_container *ast_sorcery_retrieve_by_prefix(const struct ast_sorcery *s struct ao2_container *objects; int i; - if (!object_type || !(objects = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL))) { + if (!object_type) { + return NULL; + } + + objects = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, NULL, NULL); + if (!objects) { return NULL; } diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index 9bb9a8dbd54a806d62009428202b631cfb6e1340..85eb576f9b1e66fcd7a4a6c77830a5f22df93981 100644 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -1993,7 +1993,9 @@ static int load_module(void) { int res; - if (!(mohclasses = ao2_t_container_alloc(53, moh_class_hash, moh_class_cmp, "Moh class container"))) { + mohclasses = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 53, + moh_class_hash, NULL, moh_class_cmp, "Moh class container"); + if (!mohclasses) { return AST_MODULE_LOAD_DECLINE; } diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c index 20f5e392cede88b5e5ce1b6790a9973494225a6b..9f3e658a94df9a3da4750f1a465a94559017e50b 100644 --- a/res/res_pjsip_notify.c +++ b/res/res_pjsip_notify.c @@ -226,9 +226,9 @@ static void *notify_cfg_alloc(void) return NULL; } - if (!(cfg->notify_options = ao2_container_alloc_options( - AO2_ALLOC_OPT_LOCK_NOLOCK, 20, notify_option_hash, - notify_option_cmp))) { + cfg->notify_options = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_NOLOCK, 0, + 20, notify_option_hash, NULL, notify_option_cmp); + if (!cfg->notify_options) { ao2_cleanup(cfg); return NULL; } diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c index 560177c0640c6cabf7dfaf0d0ddb4c8ec763493c..2d49cd896c869504591219ef5f7d0e297a820db3 100644 --- a/res/res_pjsip_outbound_publish.c +++ b/res/res_pjsip_outbound_publish.c @@ -1200,9 +1200,9 @@ static int sip_outbound_publish_apply(const struct ast_sorcery *sorcery, void *o * object if created/updated, or keep the old object if an error occurs. */ if (!new_states) { - new_states = ao2_container_alloc_options( - AO2_ALLOC_OPT_LOCK_NOLOCK, DEFAULT_STATE_BUCKETS, - outbound_publish_state_hash, outbound_publish_state_cmp); + new_states = ao2_container_alloc_hash( + AO2_ALLOC_OPT_LOCK_NOLOCK, 0, DEFAULT_STATE_BUCKETS, + outbound_publish_state_hash, NULL, outbound_publish_state_cmp); if (!new_states) { ast_log(LOG_ERROR, "Unable to allocate new states container\n"); diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c index 30e6ef04b9ef497eff85c38c9e86ad94ca49e2c7..9a1ade09f3904a8b115e63fbd4e2b637ec04c141 100644 --- a/res/res_sorcery_memory_cache.c +++ b/res/res_sorcery_memory_cache.c @@ -1556,9 +1556,9 @@ static void *sorcery_memory_cache_open(const char *data) } } - cache->objects = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_RWLOCK, + cache->objects = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_RWLOCK, 0, cache->maximum_objects ? cache->maximum_objects : CACHE_CONTAINER_BUCKET_SIZE, - sorcery_memory_cached_object_hash, sorcery_memory_cached_object_cmp); + sorcery_memory_cached_object_hash, NULL, sorcery_memory_cached_object_cmp); if (!cache->objects) { ast_log(LOG_ERROR, "Could not create a container to hold cached objects for memory cache\n"); return NULL; diff --git a/res/res_srtp.c b/res/res_srtp.c index d2d2457ae8121d6a7241f0b332afa0568fe5b103..8e8e1850c9756c41a14ae1acd334e02449a6e67c 100644 --- a/res/res_srtp.c +++ b/res/res_srtp.c @@ -192,7 +192,9 @@ static struct ast_srtp *res_srtp_new(void) return NULL; } - if (!(srtp->policies = ao2_t_container_alloc(5, policy_hash_fn, policy_cmp_fn, "SRTP policy container"))) { + srtp->policies = ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 5, + policy_hash_fn, NULL, policy_cmp_fn, "SRTP policy container"); + if (!srtp->policies) { ast_free(srtp); return NULL; } diff --git a/tests/test_astobj2.c b/tests/test_astobj2.c index 6da22b7d1e30da9988044f449a26e06e023bb187..68f48ed3cce899de443326bf7b5d66d35bc46768 100644 --- a/tests/test_astobj2.c +++ b/tests/test_astobj2.c @@ -458,7 +458,7 @@ static int astobj2_test_1_helper(int tst_num, enum test_container_type type, int test_sort_cb, test_cmp_cb, "test"); break; } - c2 = ao2_t_container_alloc(1, NULL, NULL, "test"); + c2 = ao2_t_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL, "test"); if (!c1 || !c2) { ast_test_status_update(test, "ao2_container_alloc failed.\n");