[Asterisk-code-review] astobj2: Eliminate usage of legacy ao2 container alloc routine. (asterisk[13])

Corey Farrell asteriskteam at digium.com
Mon Nov 19 15:43:35 CST 2018


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/10698


Change subject: astobj2: Eliminate usage of legacy ao2_container_alloc routine.
......................................................................

astobj2: Eliminate usage of legacy ao2_container_alloc routine.

Replace usage of ao2_container_alloc with ao2_container_alloc_hash or
ao2_container_alloc_list.

ao2_container_alloc is now restricted to modules only and is being
removed from Asterisk 17.

Change-Id: I0907d78bc66efc775672df37c8faad00f2f6c088
---
M apps/app_confbridge.c
M apps/app_meetme.c
M apps/app_queue.c
M apps/app_skel.c
M apps/app_voicemail.c
M apps/confbridge/conf_config_parser.c
M channels/chan_console.c
M channels/chan_iax2.c
M channels/chan_motif.c
M channels/chan_sip.c
M channels/chan_unistim.c
M channels/sig_pri.c
M funcs/func_dialgroup.c
M funcs/func_lock.c
M funcs/func_odbc.c
M include/asterisk/astobj2.h
M main/cel.c
M main/channel.c
M main/channel_internal_api.c
M main/config.c
M main/config_options.c
M main/data.c
M main/endpoints.c
M main/indications.c
M main/manager.c
M main/media_index.c
M main/message.c
M main/named_acl.c
M main/pbx.c
M main/stasis.c
M main/stasis_channels.c
M main/taskprocessor.c
M main/threadpool.c
M main/xmldoc.c
M pbx/pbx_realtime.c
M res/res_calendar.c
M res/res_clialiases.c
M res/res_config_sqlite3.c
M res/res_corosync.c
M res/res_fax.c
M res/res_http_websocket.c
M res/res_odbc.c
M res/res_parking.c
M res/res_phoneprov.c
M res/res_pjsip/config_transport.c
M res/res_pjsip/pjsip_transport_management.c
M res/res_pjsip_mwi.c
M res/res_pjsip_outbound_publish.c
M res/res_pjsip_outbound_registration.c
M res/res_pjsip_pubsub.c
M res/res_pjsip_session.c
M res/res_rtp_asterisk.c
M res/res_sorcery_memory.c
M res/res_sorcery_memory_cache.c
M res/res_stasis.c
M res/res_stasis_device_state.c
M res/res_stasis_playback.c
M res/res_stasis_recording.c
M res/res_timing_pthread.c
M res/res_xmpp.c
M tests/test_astobj2.c
M tests/test_astobj2_thrash.c
M tests/test_cel.c
M tests/test_config.c
M tests/test_scoped_lock.c
65 files changed, 330 insertions(+), 224 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/98/10698/1

diff --git a/apps/app_confbridge.c b/apps/app_confbridge.c
index 9c6b690..d07c156 100644
--- a/apps/app_confbridge.c
+++ b/apps/app_confbridge.c
@@ -4093,8 +4093,9 @@
 	}
 
 	/* Create a container to hold the conference bridges */
-	conference_bridges = ao2_container_alloc(CONFERENCE_BRIDGE_BUCKETS,
-		conference_bridge_hash_cb, conference_bridge_cmp_cb);
+	conference_bridges = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		CONFERENCE_BRIDGE_BUCKETS,
+		conference_bridge_hash_cb, NULL, conference_bridge_cmp_cb);
 	if (!conference_bridges) {
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 9ef4621..d8493d0 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -1627,8 +1627,14 @@
 
 	ast_format_cap_append(cap_slin, ast_format_slin, 0);
 	/* Make a new one */
-	if (!(cnf = ast_calloc(1, sizeof(*cnf))) ||
-		!(cnf->usercontainer = ao2_container_alloc(1, NULL, user_no_cmp))) {
+	cnf = ast_calloc(1, sizeof(*cnf));
+	if (!cnf) {
+		goto cnfout;
+	}
+
+	cnf->usercontainer = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NULL, user_no_cmp);
+	if (!cnf->usercontainer) {
 		goto cnfout;
 	}
 
@@ -7398,13 +7404,6 @@
 	ast_string_field_free_memory(station);
 }
 
-static int sla_trunk_hash(const void *obj, const int flags)
-{
-	const struct sla_trunk *trunk = obj;
-
-	return ast_str_case_hash(trunk->name);
-}
-
 static int sla_trunk_cmp(void *obj, void *arg, int flags)
 {
 	struct sla_trunk *trunk = obj, *trunk2 = arg;
@@ -7412,13 +7411,6 @@
 	return !strcasecmp(trunk->name, trunk2->name) ? CMP_MATCH | CMP_STOP : 0;
 }
 
-static int sla_station_hash(const void *obj, const int flags)
-{
-	const struct sla_station *station = obj;
-
-	return ast_str_case_hash(station->name);
-}
-
 static int sla_station_cmp(void *obj, void *arg, int flags)
 {
 	struct sla_station *station = obj, *station2 = arg;
@@ -7872,8 +7864,10 @@
 	if (!reload) {
 		ast_mutex_init(&sla.lock);
 		ast_cond_init(&sla.cond, NULL);
-		sla_trunks = ao2_container_alloc(1, sla_trunk_hash, sla_trunk_cmp);
-		sla_stations = ao2_container_alloc(1, sla_station_hash, sla_station_cmp);
+		sla_trunks = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+			NULL, sla_trunk_cmp);
+		sla_stations = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+			NULL, sla_station_cmp);
 	}
 
 	if (!(cfg = ast_config_load(SLA_CONFIG_FILE, config_flags))) {
diff --git a/apps/app_queue.c b/apps/app_queue.c
index ce00b5e..b6b9255 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -2700,9 +2700,10 @@
 	if (!q->members) {
 		if (q->strategy == QUEUE_STRATEGY_LINEAR || q->strategy == QUEUE_STRATEGY_RRORDERED) {
 			/* linear strategy depends on order, so we have to place all members in a single bucket */
-			q->members = ao2_container_alloc(1, member_hash_fn, member_cmp_fn);
+			q->members = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, member_cmp_fn);
 		} else {
-			q->members = ao2_container_alloc(37, member_hash_fn, member_cmp_fn);
+			q->members = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+				member_hash_fn, NULL, member_cmp_fn);
 		}
 	}
 	q->found = 1;
@@ -10925,13 +10926,14 @@
 	struct stasis_topic *queue_topic;
 	struct stasis_topic *manager_topic;
 
-	queues = ao2_container_alloc(MAX_QUEUE_BUCKETS, queue_hash_cb, queue_cmp_cb);
+	queues = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_QUEUE_BUCKETS,
+		queue_hash_cb, NULL, queue_cmp_cb);
 	if (!queues) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	pending_members = ao2_container_alloc(
-		MAX_CALL_ATTEMPT_BUCKETS, pending_members_hash, pending_members_cmp);
+	pending_members = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		MAX_CALL_ATTEMPT_BUCKETS, pending_members_hash, NULL, pending_members_cmp);
 	if (!pending_members) {
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/apps/app_skel.c b/apps/app_skel.c
index ae50bb5..f15c344 100644
--- a/apps/app_skel.c
+++ b/apps/app_skel.c
@@ -582,7 +582,9 @@
 		goto error;
 	}
 
-	if (!(cfg->levels = ao2_container_alloc(LEVEL_BUCKETS, skel_level_hash, skel_level_cmp))) {
+	cfg->levels = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, LEVEL_BUCKETS,
+		skel_level_hash, NULL, skel_level_cmp);
+	if (!cfg->levels) {
 		goto error;
 	}
 
@@ -727,7 +729,9 @@
 	if (aco_info_init(&cfg_info)) {
 		goto error;
 	}
-	if (!(games = ao2_container_alloc(1, NULL, NULL))) {
+
+	games = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
+	if (!games) {
 		goto error;
 	}
 
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index aa114a8..f45c596 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -15018,11 +15018,14 @@
 	my_umask = umask(0);
 	umask(my_umask);
 
-	if (!(inprocess_container = ao2_container_alloc(573, inprocess_hash_fn, inprocess_cmp_fn))) {
+	inprocess_container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 573,
+		inprocess_hash_fn, NULL, inprocess_cmp_fn);
+	if (!inprocess_container) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	poll_list = ao2_container_alloc(POLL_LIST_BUCKETS, poll_state_hash_fn, poll_state_cmp_fn);
+	poll_list = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, POLL_LIST_BUCKETS,
+		poll_state_hash_fn, NULL, poll_state_cmp_fn);
 	if (!poll_list) {
 		ast_log(LOG_ERROR, "Unable to create poll_list container\n");
 		ao2_cleanup(inprocess_container);
diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c
index d1406c1..9486260 100644
--- a/apps/confbridge/conf_config_parser.c
+++ b/apps/confbridge/conf_config_parser.c
@@ -1822,15 +1822,21 @@
 		return NULL;
 	}
 
-	if (!(cfg->user_profiles = ao2_container_alloc(283, user_hash_cb, user_cmp_cb))) {
+	cfg->user_profiles = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 283,
+		user_hash_cb, NULL, user_cmp_cb);
+	if (!cfg->user_profiles) {
 		goto error;
 	}
 
-	if (!(cfg->bridge_profiles = ao2_container_alloc(283, bridge_hash_cb, bridge_cmp_cb))) {
+	cfg->bridge_profiles = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 283,
+		bridge_hash_cb, NULL, bridge_cmp_cb);
+	if (!cfg->bridge_profiles) {
 		goto error;
 	}
 
-	if (!(cfg->menus = ao2_container_alloc(283, menu_hash_cb, menu_cmp_cb))) {
+	cfg->menus = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 283,
+		menu_hash_cb, NULL, menu_cmp_cb);
+	if (!cfg->menus) {
 		goto error;
 	}
 
diff --git a/channels/chan_console.c b/channels/chan_console.c
index f09694b..cdd7a25 100644
--- a/channels/chan_console.c
+++ b/channels/chan_console.c
@@ -1536,7 +1536,9 @@
 
 	init_pvt(&globals, NULL);
 
-	if (!(pvts = ao2_container_alloc(NUM_PVT_BUCKETS, pvt_hash_cb, pvt_cmp_cb)))
+	pvts = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NUM_PVT_BUCKETS,
+		pvt_hash_cb, NULL, pvt_cmp_cb);
+	if (!pvts)
 		goto return_error;
 
 	if (load_config(0))
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index d534c00..b485fd1 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -14858,23 +14858,54 @@
 	peers = users = iax_peercallno_pvts = iax_transfercallno_pvts = NULL;
 	peercnts = callno_limits = calltoken_ignores = NULL;
 
-	if (!(peers = ao2_container_alloc(MAX_PEER_BUCKETS, peer_hash_cb, peer_cmp_cb))) {
+	peers = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_PEER_BUCKETS,
+		peer_hash_cb, NULL, peer_cmp_cb);
+	if (!peers) {
 		goto container_fail;
-	} else if (!(users = ao2_container_alloc(MAX_USER_BUCKETS, user_hash_cb, user_cmp_cb))) {
+	}
+
+	users = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_USER_BUCKETS,
+		user_hash_cb, NULL, user_cmp_cb);
+	if (!users) {
 		goto container_fail;
-	} else if (!(iax_peercallno_pvts = ao2_container_alloc(IAX_MAX_CALLS, pvt_hash_cb, pvt_cmp_cb))) {
+	}
+
+	iax_peercallno_pvts = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		IAX_MAX_CALLS, pvt_hash_cb, NULL, pvt_cmp_cb);
+	if (!iax_peercallno_pvts) {
 		goto container_fail;
-	} else if (!(iax_transfercallno_pvts = ao2_container_alloc(IAX_MAX_CALLS, transfercallno_pvt_hash_cb, transfercallno_pvt_cmp_cb))) {
+	}
+
+	iax_transfercallno_pvts = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		IAX_MAX_CALLS, transfercallno_pvt_hash_cb, NULL, transfercallno_pvt_cmp_cb);
+	if (!iax_transfercallno_pvts) {
 		goto container_fail;
-	} else if (!(peercnts = ao2_container_alloc(MAX_PEER_BUCKETS, peercnt_hash_cb, peercnt_cmp_cb))) {
+	}
+
+	peercnts = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_PEER_BUCKETS,
+		peercnt_hash_cb, NULL, peercnt_cmp_cb);
+	if (!peercnts) {
 		goto container_fail;
-	} else if (!(callno_limits = ao2_container_alloc(MAX_PEER_BUCKETS, addr_range_hash_cb, addr_range_cmp_cb))) {
+	}
+
+	callno_limits = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		MAX_PEER_BUCKETS, addr_range_hash_cb, NULL, addr_range_cmp_cb);
+	if (!callno_limits) {
 		goto container_fail;
-	} else if (!(calltoken_ignores = ao2_container_alloc(MAX_PEER_BUCKETS, addr_range_hash_cb, addr_range_cmp_cb))) {
+	}
+
+	calltoken_ignores = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		MAX_PEER_BUCKETS, addr_range_hash_cb, NULL, addr_range_cmp_cb);
+	if (!calltoken_ignores) {
 		goto container_fail;
-	} else if (create_callno_pools()) {
+	}
+
+	if (create_callno_pools()) {
 		goto container_fail;
-	} else if  (!(transmit_processor = ast_taskprocessor_get("iax2_transmit", TPS_REF_DEFAULT))) {
+	}
+
+	transmit_processor = ast_taskprocessor_get("iax2_transmit", TPS_REF_DEFAULT);
+	if (!transmit_processor) {
 		goto container_fail;
 	}
 
diff --git a/channels/chan_motif.c b/channels/chan_motif.c
index a80f8be..97a56d5 100644
--- a/channels/chan_motif.c
+++ b/channels/chan_motif.c
@@ -473,7 +473,9 @@
 		return NULL;
 	}
 
-	if (!(state->sessions = ao2_container_alloc(SESSION_BUCKETS, jingle_session_hash, jingle_session_cmp))) {
+	state->sessions = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		SESSION_BUCKETS, jingle_session_hash, NULL, jingle_session_cmp);
+	if (!state->sessions) {
 		ao2_ref(state, -1);
 		return NULL;
 	}
@@ -607,7 +609,9 @@
 		return NULL;
 	}
 
-	if (!(cfg->endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, jingle_endpoint_hash, jingle_endpoint_cmp))) {
+	cfg->endpoints = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		ENDPOINT_BUCKETS, jingle_endpoint_hash, NULL, jingle_endpoint_cmp);
+	if (!cfg->endpoints) {
 		ao2_ref(cfg, -1);
 		return NULL;
 	}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 49d5f64..d90c1c7 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1768,8 +1768,9 @@
 {
 	int i, res = 0;
 	for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) {
-		if (!((event_state_compositors[i].compositor) =
-					ao2_container_alloc(ESC_MAX_BUCKETS, esc_hash_fn, esc_cmp_fn))) {
+		event_state_compositors[i].compositor = ao2_container_alloc_hash(
+			AO2_ALLOC_OPT_LOCK_MUTEX, 0, ESC_MAX_BUCKETS, esc_hash_fn, NULL, esc_cmp_fn);
+		if (!event_state_compositors[i].compositor) {
 			res = -1;
 		}
 	}
@@ -35507,7 +35508,9 @@
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	if (!(sip_monitor_instances = ao2_container_alloc(37, sip_monitor_instance_hash_fn, sip_monitor_instance_cmp_fn))) {
+	sip_monitor_instances = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+		sip_monitor_instance_hash_fn, NULL, sip_monitor_instance_cmp_fn);
+	if (!sip_monitor_instances) {
 		unload_module();
 		return AST_MODULE_LOAD_DECLINE;
 	}
diff --git a/channels/chan_unistim.c b/channels/chan_unistim.c
index 5d8e47c..1809c8a 100644
--- a/channels/chan_unistim.c
+++ b/channels/chan_unistim.c
@@ -815,7 +815,9 @@
 		char tmp[1024], *p, *p_orig = NULL, *p_trans = NULL;
 		FILE *f;
 
-		if (!(lang->trans = ao2_container_alloc(8, lang_hash_fn, lang_cmp_fn))) {
+		lang->trans = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 8,
+			lang_hash_fn, NULL, lang_cmp_fn);
+		if (!lang->trans) {
 			ast_log(LOG_ERROR, "Unable to allocate container for translation!\n");
 			return str;
 		}
diff --git a/channels/sig_pri.c b/channels/sig_pri.c
index 682abf3..69fe346 100644
--- a/channels/sig_pri.c
+++ b/channels/sig_pri.c
@@ -10146,8 +10146,8 @@
 
 #if defined(HAVE_PRI_CCSS)
 	sig_pri_cc_type_name = cc_type_name;
-	sig_pri_cc_monitors = ao2_container_alloc(37, sig_pri_cc_monitor_instance_hash_fn,
-		sig_pri_cc_monitor_instance_cmp_fn);
+	sig_pri_cc_monitors = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+		sig_pri_cc_monitor_instance_hash_fn, NULL, sig_pri_cc_monitor_instance_cmp_fn);
 	if (!sig_pri_cc_monitors) {
 		return -1;
 	}
diff --git a/funcs/func_dialgroup.c b/funcs/func_dialgroup.c
index 37aba6a..01348b0 100644
--- a/funcs/func_dialgroup.c
+++ b/funcs/func_dialgroup.c
@@ -223,7 +223,8 @@
 		grhead = ao2_alloc(sizeof(*grhead), group_destroy);
 		if (!grhead)
 			return -1;
-		grhead->entries = ao2_container_alloc(37, entry_hash_fn, entry_cmp_fn);
+		grhead->entries = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+			entry_hash_fn, NULL, entry_cmp_fn);
 		if (!grhead->entries) {
 			ao2_ref(grhead, -1);
 			return -1;
@@ -238,7 +239,9 @@
 
 		/* Remove all existing */
 		ao2_ref(grhead->entries, -1);
-		if (!(grhead->entries = ao2_container_alloc(37, entry_hash_fn, entry_cmp_fn))) {
+		grhead->entries = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+			entry_hash_fn, NULL, entry_cmp_fn);
+		if (!grhead->entries) {
 			ao2_unlink(group_container, grhead);
 			ao2_ref(grhead, -1);
 			return -1;
@@ -299,7 +302,9 @@
 	struct ast_db_entry *dbtree, *tmp;
 	char groupname[AST_MAX_EXTENSION], *ptr;
 
-	if ((group_container = ao2_container_alloc(37, group_hash_fn, group_cmp_fn))) {
+	group_container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+		group_hash_fn, NULL, group_cmp_fn);
+	if (group_container) {
 		/* Refresh groups from astdb */
 		if ((dbtree = ast_db_gettree("dialgroup", NULL))) {
 			for (tmp = dbtree; tmp; tmp = tmp->next) {
diff --git a/funcs/func_lock.c b/funcs/func_lock.c
index e56d56d..a006a57 100644
--- a/funcs/func_lock.c
+++ b/funcs/func_lock.c
@@ -217,12 +217,6 @@
 	return NULL;
 }
 
-static int ast_channel_hash_cb(const void *obj, const int flags)
-{
-	const struct ast_channel *chan = obj;
-	return ast_str_case_hash(ast_channel_name(chan));
-}
-
 static int ast_channel_cmp_cb(void *obj, void *arg, int flags)
 {
 	struct ast_channel *chan = obj, *cmp_args = arg;
@@ -298,7 +292,9 @@
 			AST_LIST_UNLOCK(&locklist);
 			return -1;
 		}
-		if (!(current->requesters = ao2_container_alloc(1, ast_channel_hash_cb, ast_channel_cmp_cb))) {
+		current->requesters = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+			NULL, ast_channel_cmp_cb);
+		if (!current->requesters) {
 			ast_mutex_destroy(&current->mutex);
 			ast_cond_destroy(&current->cond);
 			ast_free(current);
diff --git a/funcs/func_odbc.c b/funcs/func_odbc.c
index f4821c0..70f02b8 100644
--- a/funcs/func_odbc.c
+++ b/funcs/func_odbc.c
@@ -1795,7 +1795,8 @@
 	dsns = NULL;
 
 	if (single_db_connection) {
-		dsns = ao2_container_alloc(DSN_BUCKETS, dsn_hash, dsn_cmp);
+		dsns = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, DSN_BUCKETS,
+			dsn_hash, NULL, dsn_cmp);
 		if (!dsns) {
 			ast_log(LOG_ERROR, "Could not initialize DSN container\n");
 			ast_rwlock_unlock(&single_db_connection_lock);
@@ -1893,7 +1894,8 @@
 	}
 
 	if (single_db_connection) {
-		dsns = ao2_container_alloc(DSN_BUCKETS, dsn_hash, dsn_cmp);
+		dsns = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, DSN_BUCKETS,
+			dsn_hash, NULL, dsn_cmp);
 		if (!dsns) {
 			ast_log(LOG_ERROR, "Could not initialize DSN container\n");
 			ast_rwlock_unlock(&single_db_connection_lock);
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h
index 0e32e89..4765fdc 100644
--- a/include/asterisk/astobj2.h
+++ b/include/asterisk/astobj2.h
@@ -92,7 +92,8 @@
 
     struct ao2_container *c;
 
-    c = ao2_container_alloc(MAX_BUCKETS, my_hash_fn, my_cmp_fn);
+    c = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_BUCKETS,
+        my_hash_fn, NULL, my_cmp_fn);
     \endcode
 
 where
@@ -108,7 +109,7 @@
 other than the fact that they have been created by ao2_alloc().
 All knowledge of the (user-defined) internals of the objects
 is left to the (user-supplied) functions passed as arguments
-to ao2_container_alloc().
+to ao2_container_alloc_hash().
 
 If we want to insert an object in a container, we should
 initialize its fields -- especially, those used by my_hash_fn() --
@@ -856,20 +857,8 @@
 Internally, objects are stored in lists, hash tables or other
 data structures depending on the needs.
 
-\note NOTA BENE: at the moment the only container we support is the
-    hash table and its degenerate form, the list.
-
 Operations on container include:
 
-  -  c = \b ao2_container_alloc(size, hash_fn, cmp_fn)
-    allocate a container with desired size and default compare
-    and hash function
-         -The compare function returns an int, which
-         can be 0 for not found, CMP_STOP to stop end a traversal,
-         or CMP_MATCH if they are equal
-         -The hash function returns an int. The hash function
-         takes two argument, the object pointer and a flags field,
-
   -  \b ao2_find(c, arg, flags)
     returns zero or more elements matching a given criteria
     (specified as arg). 'c' is the container pointer. Flags
@@ -1217,6 +1206,10 @@
 /*@{ */
 struct ao2_container;
 
+#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. */
+
 /*!
  * \deprecated
  * \brief Allocate and initialize a hash container with the desired number of buckets.
@@ -1236,17 +1229,13 @@
  * \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_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))
 #define ao2_t_container_alloc(n_buckets, hash_fn, cmp_fn, tag) \
 	ao2_t_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, (n_buckets), (hash_fn), NULL, (cmp_fn), (tag))
 #endif
diff --git a/main/cel.c b/main/cel.c
index 45726e0..4e67581 100644
--- a/main/cel.c
+++ b/main/cel.c
@@ -1561,15 +1561,16 @@
 {
 	struct ao2_container *container;
 
-	container = ao2_container_alloc(NUM_APP_BUCKETS, cel_linkedid_hash_fn, cel_linkedid_cmp_fn);
+	container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NUM_APP_BUCKETS,
+		cel_linkedid_hash_fn, NULL, cel_linkedid_cmp_fn);
 	ao2_global_obj_replace_unref(cel_linkedids, container);
 	ao2_cleanup(container);
 	if (!container) {
 		return -1;
 	}
 
-	container = ao2_container_alloc(NUM_DIALSTATUS_BUCKETS,
-		cel_dialstatus_hash_fn, cel_dialstatus_cmp_fn);
+	container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_DIALSTATUS_BUCKETS, cel_dialstatus_hash_fn, NULL, cel_dialstatus_cmp_fn);
 	ao2_global_obj_replace_unref(cel_dialstatus_store, container);
 	ao2_cleanup(container);
 	if (!container) {
@@ -1584,7 +1585,8 @@
 		return -1;
 	}
 
-	container = ao2_container_alloc(BACKEND_BUCKETS, cel_backend_hash_fn, cel_backend_cmp_fn);
+	container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, BACKEND_BUCKETS,
+		cel_backend_hash_fn, NULL, cel_backend_cmp_fn);
 	ao2_global_obj_replace_unref(cel_backends, container);
 	ao2_cleanup(container);
 	if (!container) {
diff --git a/main/channel.c b/main/channel.c
index e5bd879..c1eecdb 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -8056,8 +8056,8 @@
 
 int ast_channels_init(void)
 {
-	channels = ao2_container_alloc(NUM_CHANNEL_BUCKETS,
-			ast_channel_hash_cb, ast_channel_cmp_cb);
+	channels = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NUM_CHANNEL_BUCKETS,
+		ast_channel_hash_cb, NULL, ast_channel_cmp_cb);
 	if (!channels) {
 		return -1;
 	}
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index 6e429b3..72ca1a9 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -1462,7 +1462,9 @@
 		return ast_channel_unref(tmp);
 	}
 
-	if (!(tmp->dialed_causes = ao2_container_alloc(DIALED_CAUSES_BUCKETS, pvt_cause_hash_fn, pvt_cause_cmp_fn))) {
+	tmp->dialed_causes = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DIALED_CAUSES_BUCKETS, pvt_cause_hash_fn, NULL, pvt_cause_cmp_fn);
+	if (!tmp->dialed_causes) {
 		return ast_channel_unref(tmp);
 	}
 
diff --git a/main/config.c b/main/config.c
index a8fae05..d864af2 100644
--- a/main/config.c
+++ b/main/config.c
@@ -2545,7 +2545,8 @@
 	struct ao2_container *fileset;
 	struct inclfile *fi;
 
-	fileset = ao2_container_alloc(1023, hash_string, hashtab_compare_strings);
+	fileset = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 1023,
+		hash_string, NULL, hashtab_compare_strings);
 	if (!fileset) {
 		/* Container creation failed. */
 		return -1;
@@ -4112,8 +4113,12 @@
 		config_hook_cb hook_cb)
 {
 	struct cfg_hook *hook;
-	if (!cfg_hooks && !(cfg_hooks = ao2_container_alloc(17, hook_hash, hook_cmp))) {
-		return -1;
+	if (!cfg_hooks) {
+		cfg_hooks = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 17,
+			hook_hash, NULL, hook_cmp);
+		if (!cfg_hooks) {
+			return -1;
+		}
 	}
 
 	if (!(hook = ao2_alloc(sizeof(*hook), hook_destroy))) {
diff --git a/main/config_options.c b/main/config_options.c
index f8b2be8..75d5ad1 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -407,7 +407,8 @@
 
 struct ao2_container *aco_option_container_alloc(void)
 {
-	return ao2_container_alloc(CONFIG_OPT_BUCKETS, config_opt_hash, config_opt_cmp);
+	return ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, CONFIG_OPT_BUCKETS,
+		config_opt_hash, NULL, config_opt_cmp);
 }
 
 static int internal_aco_type_category_check(struct aco_type *match, const char *category)
diff --git a/main/data.c b/main/data.c
index 5972949..b703b56 100644
--- a/main/data.c
+++ b/main/data.c
@@ -323,8 +323,9 @@
 	strcpy(node->name, name);
 
 	/* initialize the childrens container. */
-	if (!(node->children = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
-			data_provider_hash, data_provider_cmp))) {
+	node->children = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_DATA_NODE_BUCKETS, data_provider_hash, NULL, data_provider_cmp);
+	if (!node->children) {
 		ao2_ref(node, -1);
 		return NULL;
 	}
@@ -698,8 +699,8 @@
 		return NULL;
 	}
 
-	res->children = ao2_container_alloc(NUM_DATA_SEARCH_BUCKETS, data_search_hash,
-		data_search_cmp);
+	res->children = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_DATA_SEARCH_BUCKETS, data_search_hash, NULL, data_search_cmp);
 
 	if (!res->children) {
 		ao2_ref(res, -1);
@@ -1418,8 +1419,8 @@
 	strcpy(res->name, namelen ? name : "");
 
 	/* initialize the children container */
-	res->children = ao2_container_alloc(NUM_DATA_RESULT_BUCKETS, data_result_hash,
-		data_result_cmp);
+	res->children = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_DATA_RESULT_BUCKETS, data_result_hash, NULL, data_result_cmp);
 	if (!res->children) {
 		ao2_ref(res, -1);
 		return NULL;
@@ -1656,8 +1657,8 @@
 		return NULL;
 	}
 
-	res->children = ao2_container_alloc(NUM_DATA_FILTER_BUCKETS, data_filter_hash,
-		data_filter_cmp);
+	res->children = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_DATA_FILTER_BUCKETS, data_filter_hash, NULL, data_filter_cmp);
 
 	if (!res->children) {
 		ao2_ref(res, -1);
@@ -3335,8 +3336,9 @@
 
 	ast_rwlock_init(&root_data.lock);
 
-	if (!(root_data.container = ao2_container_alloc(NUM_DATA_NODE_BUCKETS,
-		data_provider_hash, data_provider_cmp))) {
+	root_data.container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_DATA_NODE_BUCKETS, data_provider_hash, NULL, data_provider_cmp);
+	if (!root_data.container) {
 		return -1;
 	}
 
diff --git a/main/endpoints.c b/main/endpoints.c
index 69d022f..b68f207 100644
--- a/main/endpoints.c
+++ b/main/endpoints.c
@@ -484,14 +484,14 @@
 {
 	ast_register_cleanup(endpoint_cleanup);
 
-	endpoints = ao2_container_alloc(ENDPOINT_BUCKETS, ast_endpoint_hash_fn,
-		ast_endpoint_cmp_fn);
+	endpoints = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, ENDPOINT_BUCKETS,
+		ast_endpoint_hash_fn, NULL, ast_endpoint_cmp_fn);
 	if (!endpoints) {
 		return -1;
 	}
 
-	tech_endpoints = ao2_container_alloc(TECH_ENDPOINT_BUCKETS, ast_endpoint_hash_fn,
-		ast_endpoint_cmp_fn);
+	tech_endpoints = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		TECH_ENDPOINT_BUCKETS, ast_endpoint_hash_fn, NULL, ast_endpoint_cmp_fn);
 	if (!tech_endpoints) {
 		return -1;
 	}
diff --git a/main/indications.c b/main/indications.c
index e0ba59b..f193792 100644
--- a/main/indications.c
+++ b/main/indications.c
@@ -1174,8 +1174,8 @@
 /*! \brief Load indications module */
 int ast_indications_init(void)
 {
-	ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,
-			ast_tone_zone_hash, ast_tone_zone_cmp);
+	ast_tone_zones = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_TONE_ZONE_BUCKETS, ast_tone_zone_hash, NULL, ast_tone_zone_cmp);
 	if (!ast_tone_zones) {
 		return -1;
 	}
diff --git a/main/manager.c b/main/manager.c
index 5b4cc3a..47b31bb 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -2224,8 +2224,8 @@
 		return NULL;
 	}
 
-	newsession->whitefilters = ao2_container_alloc(1, NULL, NULL);
-	newsession->blackfilters = ao2_container_alloc(1, NULL, NULL);
+	newsession->whitefilters = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
+	newsession->blackfilters = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
 	if (!newsession->whitefilters || !newsession->blackfilters) {
 		ao2_ref(newsession, -1);
 		return NULL;
@@ -7612,7 +7612,8 @@
 			if (xml) {
 				ast_str_append(out, 0, "<response type='object' id='%s'><%s", dest, objtype);
 			}
-			vco = ao2_container_alloc(37, variable_count_hash_fn, variable_count_cmp_fn);
+			vco = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+				variable_count_hash_fn, NULL, variable_count_cmp_fn);
 			inobj = 1;
 		}
 
@@ -9052,7 +9053,7 @@
 #endif
 
 		/* If you have a NULL hash fn, you only need a single bucket */
-		sessions = ao2_container_alloc(1, NULL, mansession_cmp_fn);
+		sessions = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, mansession_cmp_fn);
 		if (!sessions) {
 			return -1;
 		}
@@ -9308,8 +9309,8 @@
 			/* Default allowmultiplelogin from [general] */
 			user->allowmultiplelogin = allowmultiplelogin;
 			user->writetimeout = 100;
-			user->whitefilters = ao2_container_alloc(1, NULL, NULL);
-			user->blackfilters = ao2_container_alloc(1, NULL, NULL);
+			user->whitefilters = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
+			user->blackfilters = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
 			if (!user->whitefilters || !user->blackfilters) {
 				manager_free_user(user);
 				break;
diff --git a/main/media_index.c b/main/media_index.c
index bfaa580..2d1bc6b 100644
--- a/main/media_index.c
+++ b/main/media_index.c
@@ -121,7 +121,8 @@
 
 	memcpy(info->name, name, name_sz);
 
-	info->variants = ao2_container_alloc(VARIANT_BUCKETS, media_variant_hash, media_variant_cmp);
+	info->variants = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		VARIANT_BUCKETS, media_variant_hash, NULL, media_variant_cmp);
 	if (!info->variants) {
 		ao2_ref(info, -1);
 
@@ -169,7 +170,8 @@
 
 	memcpy(index->base_dir, base_dir, base_dir_sz);
 
-	index->index = ao2_container_alloc(INDEX_BUCKETS, media_info_hash, media_info_cmp);
+	index->index = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, INDEX_BUCKETS,
+		media_info_hash, NULL, media_info_cmp);
 	if (!index->index) {
 		ao2_ref(index, -1);
 
diff --git a/main/message.c b/main/message.c
index 7ba2e26..0543bf4 100644
--- a/main/message.c
+++ b/main/message.c
@@ -369,12 +369,6 @@
 	ao2_ref(msg, -1);
 }
 
-static int msg_data_hash_fn(const void *obj, const int flags)
-{
-	const struct msg_data *data = obj;
-	return ast_str_case_hash(data->name);
-}
-
 static int msg_data_cmp_fn(void *obj, void *arg, int flags)
 {
 	const struct msg_data *one = obj, *two = arg;
@@ -408,7 +402,9 @@
 		return NULL;
 	}
 
-	if (!(msg->vars = ao2_container_alloc(1, msg_data_hash_fn, msg_data_cmp_fn))) {
+	msg->vars = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NULL, msg_data_cmp_fn);
+	if (!msg->vars) {
 		ao2_ref(msg, -1);
 		return NULL;
 	}
diff --git a/main/named_acl.c b/main/named_acl.c
index 826313d..e61bcba 100644
--- a/main/named_acl.c
+++ b/main/named_acl.c
@@ -128,7 +128,9 @@
 		return NULL;
 	}
 
-	if (!(cfg->named_acl_list = ao2_container_alloc(37, named_acl_hash_fn, named_acl_cmp_fn))) {
+	cfg->named_acl_list = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+		named_acl_hash_fn, NULL, named_acl_cmp_fn);
+	if (!cfg->named_acl_list) {
 		goto error;
 	}
 
diff --git a/main/pbx.c b/main/pbx.c
index 434173d..93bd9e6 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -3907,7 +3907,7 @@
 	AST_VECTOR_INIT(&hint_new->devices, 8);
 
 	/* Initialize new hint. */
-	hint_new->callbacks = ao2_container_alloc(1, NULL, hint_id_cmp);
+	hint_new->callbacks = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, hint_id_cmp);
 	if (!hint_new->callbacks) {
 		ao2_ref(hint_new, -1);
 		return -1;
@@ -8753,15 +8753,17 @@
 
 int ast_pbx_init(void)
 {
-	hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp);
+	hints = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		HASH_EXTENHINT_SIZE, hint_hash, NULL, hint_cmp);
 	if (hints) {
 		ao2_container_register("hints", hints, print_hints_key);
 	}
-	hintdevices = ao2_container_alloc(HASH_EXTENHINT_SIZE, hintdevice_hash_cb, hintdevice_cmp_multiple);
+	hintdevices = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		HASH_EXTENHINT_SIZE, hintdevice_hash_cb, NULL, hintdevice_cmp_multiple);
 	if (hintdevices) {
 		ao2_container_register("hintdevices", hintdevices, print_hintdevices_key);
 	}
-	statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);
+	statecbs = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, statecbs_cmp);
 	if (statecbs) {
 		ao2_container_register("statecbs", statecbs, print_statecbs_key);
 	}
diff --git a/main/stasis.c b/main/stasis.c
index d054897..b30bee0 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1285,8 +1285,8 @@
 		return NULL;
 	}
 
-	pool->pool_container = ao2_container_alloc(TOPIC_POOL_BUCKETS,
-		topic_pool_entry_hash, topic_pool_entry_cmp);
+	pool->pool_container = ao2_container_alloc_hash(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;
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index ed460cc..8c7a85f 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -613,8 +613,8 @@
 		return NULL;
 	}
 
-	obj->channel_snapshots = ao2_container_alloc(NUM_MULTI_CHANNEL_BLOB_BUCKETS,
-		channel_role_hash_cb, channel_role_cmp_cb);
+	obj->channel_snapshots = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_MULTI_CHANNEL_BLOB_BUCKETS, channel_role_hash_cb, NULL, channel_role_cmp_cb);
 	if (!obj->channel_snapshots) {
 		ao2_ref(obj, -1);
 		return NULL;
@@ -717,8 +717,9 @@
 		return NULL;
 	}
 
-	ret_container = ao2_container_alloc(NUM_MULTI_CHANNEL_BLOB_BUCKETS,
-		channel_snapshot_hash_cb, channel_snapshot_cmp_cb);
+	ret_container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NUM_MULTI_CHANNEL_BLOB_BUCKETS,
+		channel_snapshot_hash_cb, NULL, channel_snapshot_cmp_cb);
 	if (!ret_container) {
 		return NULL;
 	}
diff --git a/main/taskprocessor.c b/main/taskprocessor.c
index d475650..84c4d2b 100644
--- a/main/taskprocessor.c
+++ b/main/taskprocessor.c
@@ -280,7 +280,9 @@
 /* initialize the taskprocessor container and register CLI operations */
 int ast_tps_init(void)
 {
-	if (!(tps_singletons = ao2_container_alloc(TPS_MAX_BUCKETS, tps_hash_cb, tps_cmp_cb))) {
+	tps_singletons = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		TPS_MAX_BUCKETS, tps_hash_cb, NULL, tps_cmp_cb);
+	if (!tps_singletons) {
 		ast_log(LOG_ERROR, "taskprocessor container failed to initialize!\n");
 		return -1;
 	}
diff --git a/main/threadpool.c b/main/threadpool.c
index 7729930..2ab0936 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -420,15 +420,18 @@
 	if (!pool->control_tps) {
 		return NULL;
 	}
-	pool->active_threads = ao2_container_alloc(THREAD_BUCKETS, worker_thread_hash, worker_thread_cmp);
+	pool->active_threads = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		THREAD_BUCKETS, worker_thread_hash, NULL, worker_thread_cmp);
 	if (!pool->active_threads) {
 		return NULL;
 	}
-	pool->idle_threads = ao2_container_alloc(THREAD_BUCKETS, worker_thread_hash, worker_thread_cmp);
+	pool->idle_threads = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		THREAD_BUCKETS, worker_thread_hash, NULL, worker_thread_cmp);
 	if (!pool->idle_threads) {
 		return NULL;
 	}
-	pool->zombie_threads = ao2_container_alloc(THREAD_BUCKETS, worker_thread_hash, worker_thread_cmp);
+	pool->zombie_threads = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		THREAD_BUCKETS, worker_thread_hash, NULL, worker_thread_cmp);
 	if (!pool->zombie_threads) {
 		return NULL;
 	}
diff --git a/main/xmldoc.c b/main/xmldoc.c
index 37b2861..27bf76b 100644
--- a/main/xmldoc.c
+++ b/main/xmldoc.c
@@ -2659,7 +2659,9 @@
 	struct documentation_tree *doctree;
 	const char *name;
 
-	if (!(docs = ao2_container_alloc(127, ast_xml_doc_item_hash, ast_xml_doc_item_cmp))) {
+	docs = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 127,
+		ast_xml_doc_item_hash, NULL, ast_xml_doc_item_cmp);
+	if (!docs) {
 		ast_log(AST_LOG_ERROR, "Failed to create container for xml document item instances\n");
 		return NULL;
 	}
diff --git a/pbx/pbx_realtime.c b/pbx/pbx_realtime.c
index 9778984..e331781 100644
--- a/pbx/pbx_realtime.c
+++ b/pbx/pbx_realtime.c
@@ -403,7 +403,9 @@
 
 static int load_module(void)
 {
-	if (!(cache = ao2_container_alloc(573, cache_hash, cache_cmp))) {
+	cache = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 573,
+		cache_hash, NULL, cache_cmp);
+	if (!cache) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
diff --git a/res/res_calendar.c b/res/res_calendar.c
index e8ad499..8962f47 100644
--- a/res/res_calendar.c
+++ b/res/res_calendar.c
@@ -409,7 +409,8 @@
 		return NULL;
 	}
 
-	if (!(cal->events = ao2_container_alloc(CALENDAR_BUCKETS, event_hash_fn, event_cmp_fn))) {
+	cal->events = ast_calendar_event_container_alloc();
+	if (!cal->events) {
 		ast_log(LOG_ERROR, "Could not allocate events container for %s\n", cat);
 		cal = unref_calendar(cal);
 		return NULL;
@@ -672,7 +673,8 @@
 
 struct ao2_container *ast_calendar_event_container_alloc(void)
 {
-	return ao2_container_alloc(CALENDAR_BUCKETS, event_hash_fn, event_cmp_fn);
+	return ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, CALENDAR_BUCKETS,
+		event_hash_fn, NULL, event_cmp_fn);
 }
 
 static void event_notification_destroy(void *data)
@@ -1865,7 +1867,9 @@
  */
 static int load_module(void)
 {
-	if (!(calendars = ao2_container_alloc(CALENDAR_BUCKETS, calendar_hash_fn, calendar_cmp_fn))) {
+	calendars = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, CALENDAR_BUCKETS,
+		calendar_hash_fn, NULL, calendar_cmp_fn);
+	if (!calendars) {
 		ast_log(LOG_ERROR, "Unable to allocate calendars container!\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
diff --git a/res/res_clialiases.c b/res/res_clialiases.c
index 355d437..7032214 100644
--- a/res/res_clialiases.c
+++ b/res/res_clialiases.c
@@ -284,7 +284,9 @@
  */
 static int load_module(void)
 {
-	if (!(cli_aliases = ao2_container_alloc(MAX_ALIAS_BUCKETS, alias_hash_cb, alias_cmp_cb))) {
+	cli_aliases = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		MAX_ALIAS_BUCKETS, alias_hash_cb, NULL, alias_cmp_cb);
+	if (!cli_aliases) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
diff --git a/res/res_config_sqlite3.c b/res/res_config_sqlite3.c
index a033970..6148d5d 100644
--- a/res/res_config_sqlite3.c
+++ b/res/res_config_sqlite3.c
@@ -1185,7 +1185,9 @@
 		return -1;
 	}
 
-	if (!(columns = ao2_container_alloc(31, str_hash_fn, str_cmp_fn))) {
+	columns = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 31,
+		str_hash_fn, NULL, str_cmp_fn);
+	if (!columns) {
 		unref_db(&db);
 	   return -1;
 	}
@@ -1360,7 +1362,9 @@
 {
 	discover_sqlite3_caps();
 
-	if (!((databases = ao2_container_alloc(DB_BUCKETS, db_hash_fn, db_cmp_fn)))) {
+	databases = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, DB_BUCKETS,
+		db_hash_fn, NULL, db_cmp_fn);
+	if (!databases) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
diff --git a/res/res_corosync.c b/res/res_corosync.c
index af8afdb..b1518c5 100644
--- a/res/res_corosync.c
+++ b/res/res_corosync.c
@@ -1127,7 +1127,8 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	nodes = ao2_container_alloc(23, corosync_node_hash_fn, corosync_node_cmp_fn);
+	nodes = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 23,
+		corosync_node_hash_fn, NULL, corosync_node_cmp_fn);
 	if (!nodes) {
 		goto failed;
 	}
diff --git a/res/res_fax.c b/res/res_fax.c
index ce5687d..b7aadc1 100644
--- a/res/res_fax.c
+++ b/res/res_fax.c
@@ -4724,7 +4724,9 @@
 	/* initialize the registry */
 	faxregistry.active_sessions = 0;
 	faxregistry.reserved_sessions = 0;
-	if (!(faxregistry.container = ao2_container_alloc(FAX_MAXBUCKETS, session_hash_cb, session_cmp_cb))) {
+	faxregistry.container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		FAX_MAXBUCKETS, session_hash_cb, NULL, session_cmp_cb);
+	if (!faxregistry.container) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index 0ff876b..d52e6b3 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -154,7 +154,8 @@
 		return NULL;
 	}
 
-	server->protocols = ao2_container_alloc(MAX_PROTOCOL_BUCKETS, protocol_hash_fn, protocol_cmp_fn);
+	server->protocols = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		MAX_PROTOCOL_BUCKETS, protocol_hash_fn, NULL, protocol_cmp_fn);
 	if (!server->protocols) {
 		return NULL;
 	}
diff --git a/res/res_odbc.c b/res/res_odbc.c
index 9622beb..cd588ee 100644
--- a/res/res_odbc.c
+++ b/res/res_odbc.c
@@ -190,11 +190,6 @@
 	ast_cond_destroy(&class->cond);
 }
 
-static int null_hash_fn(const void *obj, const int flags)
-{
-	return 0;
-}
-
 static void odbc_obj_destructor(void *data)
 {
 	struct odbc_obj *obj = data;
@@ -1066,7 +1061,8 @@
 
 static int load_module(void)
 {
-	if (!(class_container = ao2_container_alloc(1, null_hash_fn, ao2_match_by_addr)))
+	class_container = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, ao2_match_by_addr);
+	if (!class_container)
 		return AST_MODULE_LOAD_DECLINE;
 	if (load_odbc_config() == -1)
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/res/res_parking.c b/res/res_parking.c
index ddf8012..f5279a8 100644
--- a/res/res_parking.c
+++ b/res/res_parking.c
@@ -387,7 +387,9 @@
 		return NULL;
 	}
 
-	if (!(cfg->parking_lots = ao2_container_alloc(37, parking_lot_cfg_hash_fn, parking_lot_cfg_cmp_fn))) {
+	cfg->parking_lots = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 37,
+		parking_lot_cfg_hash_fn, NULL, parking_lot_cfg_cmp_fn);
+	if (!cfg->parking_lots) {
 		return NULL;
 	}
 
diff --git a/res/res_phoneprov.c b/res/res_phoneprov.c
index 89fb29c..7091b9b 100644
--- a/res/res_phoneprov.c
+++ b/res/res_phoneprov.c
@@ -1414,13 +1414,15 @@
  */
 static int load_module(void)
 {
-	profiles = ao2_container_alloc(MAX_PROFILE_BUCKETS, phone_profile_hash_fn, phone_profile_cmp_fn);
+	profiles = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_PROFILE_BUCKETS,
+		phone_profile_hash_fn, NULL, phone_profile_cmp_fn);
 	if (!profiles) {
 		ast_log(LOG_ERROR, "Unable to allocate profiles container.\n");
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	http_routes = ao2_container_alloc(MAX_ROUTE_BUCKETS, http_route_hash_fn, http_route_cmp_fn);
+	http_routes = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_ROUTE_BUCKETS,
+		http_route_hash_fn, NULL, http_route_cmp_fn);
 	if (!http_routes) {
 		ast_log(LOG_ERROR, "Unable to allocate routes container.\n");
 		goto error;
@@ -1431,13 +1433,15 @@
 		goto error;
 	}
 
-	users = ao2_container_alloc(MAX_USER_BUCKETS, user_hash_fn, user_cmp_fn);
+	users = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MAX_USER_BUCKETS,
+		user_hash_fn, NULL, user_cmp_fn);
 	if (!users) {
 		ast_log(LOG_ERROR, "Unable to allocate users container.\n");
 		goto error;
 	}
 
-	providers = ao2_container_alloc(MAX_PROVIDER_BUCKETS, phoneprov_provider_hash_fn, phoneprov_provider_cmp_fn);
+	providers = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		MAX_PROVIDER_BUCKETS, phoneprov_provider_hash_fn, NULL, phoneprov_provider_cmp_fn);
 	if (!providers) {
 		ast_log(LOG_ERROR, "Unable to allocate providers container.\n");
 		goto error;
diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c
index 3ad4dcc..fed56f9 100644
--- a/res/res_pjsip/config_transport.c
+++ b/res/res_pjsip/config_transport.c
@@ -1376,7 +1376,8 @@
 
 struct ao2_container *ast_sip_get_transport_states(void)
 {
-	struct ao2_container *states = ao2_container_alloc(DEFAULT_STATE_BUCKETS, transport_state_hash, transport_state_cmp);
+	struct ao2_container *states = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DEFAULT_STATE_BUCKETS, transport_state_hash, NULL, transport_state_cmp);
 
 	if (!states) {
 		return NULL;
@@ -1393,7 +1394,8 @@
 	struct ao2_container *transports = NULL;
 
 	/* Create outbound registration states container. */
-	transport_states = ao2_container_alloc(DEFAULT_STATE_BUCKETS, internal_state_hash, internal_state_cmp);
+	transport_states = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DEFAULT_STATE_BUCKETS, internal_state_hash, NULL, internal_state_cmp);
 	if (!transport_states) {
 		ast_log(LOG_ERROR, "Unable to allocate transport states container\n");
 		return -1;
diff --git a/res/res_pjsip/pjsip_transport_management.c b/res/res_pjsip/pjsip_transport_management.c
index e7483e6..89ad1fc 100644
--- a/res/res_pjsip/pjsip_transport_management.c
+++ b/res/res_pjsip/pjsip_transport_management.c
@@ -354,8 +354,8 @@
 {
 	struct ao2_container *transports;
 
-	transports = ao2_container_alloc(TRANSPORTS_BUCKETS, monitored_transport_hash_fn,
-		monitored_transport_cmp_fn);
+	transports = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, TRANSPORTS_BUCKETS,
+		monitored_transport_hash_fn, NULL, monitored_transport_cmp_fn);
 	if (!transports) {
 		ast_log(LOG_ERROR, "Could not create container for transports to perform keepalive on.\n");
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index f8c2392..5622515 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -361,7 +361,8 @@
 		sub->sip_sub = sip_sub;
 	}
 
-	sub->stasis_subs = ao2_container_alloc(STASIS_BUCKETS, stasis_sub_hash, stasis_sub_cmp);
+	sub->stasis_subs = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		STASIS_BUCKETS, stasis_sub_hash, NULL, stasis_sub_cmp);
 	if (!sub->stasis_subs) {
 		ao2_cleanup(sub);
 		return NULL;
diff --git a/res/res_pjsip_outbound_publish.c b/res/res_pjsip_outbound_publish.c
index 2d49cd8..820be54 100644
--- a/res/res_pjsip_outbound_publish.c
+++ b/res/res_pjsip_outbound_publish.c
@@ -1074,7 +1074,8 @@
 		return NULL;
 	}
 
-	state->client->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
+	state->client->datastores = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DATASTORE_BUCKETS, datastore_hash, NULL, datastore_cmp);
 	if (!state->client->datastores) {
 		ao2_ref(state, -1);
 		return NULL;
diff --git a/res/res_pjsip_outbound_registration.c b/res/res_pjsip_outbound_registration.c
index c42f59e..b73b5a7 100644
--- a/res/res_pjsip_outbound_registration.c
+++ b/res/res_pjsip_outbound_registration.c
@@ -2197,8 +2197,8 @@
 	}
 
 	/* Create outbound registration states container. */
-	new_states = ao2_container_alloc(DEFAULT_STATE_BUCKETS,
-		registration_state_hash, registration_state_cmp);
+	new_states = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DEFAULT_STATE_BUCKETS, registration_state_hash, NULL, registration_state_cmp);
 	if (!new_states) {
 		ast_log(LOG_ERROR, "Unable to allocate registration states container\n");
 		unload_module();
diff --git a/res/res_pjsip_pubsub.c b/res/res_pjsip_pubsub.c
index eb4545b..ab3e4b2 100644
--- a/res/res_pjsip_pubsub.c
+++ b/res/res_pjsip_pubsub.c
@@ -1251,7 +1251,8 @@
 	}
 	strcpy(sub->resource, resource); /* Safe */
 
-	sub->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
+	sub->datastores = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DATASTORE_BUCKETS, datastore_hash, NULL, datastore_cmp);
 	if (!sub->datastores) {
 		destroy_subscription(sub);
 		return NULL;
@@ -2741,8 +2742,9 @@
 		return -1;
 	}
 
-	if (!(handler->publications = ao2_container_alloc(PUBLICATIONS_BUCKETS,
-		publication_hash_fn, publication_cmp_fn))) {
+	handler->publications = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		PUBLICATIONS_BUCKETS, publication_hash_fn, NULL, publication_cmp_fn);
+	if (!handler->publications) {
 		ast_log(LOG_ERROR, "Could not allocate publications container for event '%s'\n",
 			handler->event_name);
 		return -1;
@@ -3181,7 +3183,9 @@
 
 	ast_module_ref(ast_module_info->self);
 
-	if (!(publication->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp))) {
+	publication->datastores = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DATASTORE_BUCKETS, datastore_hash, NULL, datastore_cmp);
+	if (!publication->datastores) {
 		ao2_ref(publication, -1);
 		return NULL;
 	}
diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 669315f..ee12099 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -1412,7 +1412,8 @@
 	if (!session->req_caps) {
 		return NULL;
 	}
-	session->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
+	session->datastores = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DATASTORE_BUCKETS, datastore_hash, NULL, datastore_cmp);
 	if (!session->datastores) {
 		return NULL;
 	}
@@ -1434,7 +1435,8 @@
 
 	session->endpoint = ao2_bump(endpoint);
 
-	session->media = ao2_container_alloc(MEDIA_BUCKETS, session_media_hash, session_media_cmp);
+	session->media = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, MEDIA_BUCKETS,
+		session_media_hash, NULL, session_media_cmp);
 	if (!session->media) {
 		return NULL;
 	}
@@ -3267,8 +3269,8 @@
 	}
 	nat_hook->outgoing_external_message = session_outgoing_nat_hook;
 	ast_sorcery_create(ast_sip_get_sorcery(), nat_hook);
-	sdp_handlers = ao2_container_alloc(SDP_HANDLER_BUCKETS,
-			sdp_handler_list_hash, sdp_handler_list_cmp);
+	sdp_handlers = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		SDP_HANDLER_BUCKETS, sdp_handler_list_hash, NULL, sdp_handler_list_cmp);
 	if (!sdp_handlers) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 7b006ce..8841f6d 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -642,9 +642,12 @@
 		return;
 	}
 
-	if (!rtp->ice_proposed_remote_candidates &&
-			!(rtp->ice_proposed_remote_candidates = ao2_container_alloc(1, NULL, ice_candidate_cmp))) {
-		return;
+	if (!rtp->ice_proposed_remote_candidates) {
+		rtp->ice_proposed_remote_candidates = ao2_container_alloc_list(
+			AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, ice_candidate_cmp);
+		if (!rtp->ice_proposed_remote_candidates) {
+			return;
+		}
 	}
 
 	/* If this is going to exceed the maximum number of ICE candidates don't even add it */
@@ -1059,8 +1062,12 @@
 
 	pj_ice_calc_foundation(rtp->ice->real_ice->pool, &foundation, type, addr);
 
-	if (!rtp->ice_local_candidates && !(rtp->ice_local_candidates = ao2_container_alloc(1, NULL, ice_candidate_cmp))) {
-		return;
+	if (!rtp->ice_local_candidates) {
+		rtp->ice_local_candidates = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+			NULL, ice_candidate_cmp);
+		if (!rtp->ice_local_candidates) {
+			return;
+		}
 	}
 
 	if (!(candidate = ao2_alloc(sizeof(*candidate), ast_rtp_ice_candidate_destroy))) {
diff --git a/res/res_sorcery_memory.c b/res/res_sorcery_memory.c
index a05f05d..953bcb2 100644
--- a/res/res_sorcery_memory.c
+++ b/res/res_sorcery_memory.c
@@ -252,7 +252,8 @@
 
 static void *sorcery_memory_open(const char *data)
 {
-	return ao2_container_alloc(OBJECT_BUCKETS, sorcery_memory_hash, sorcery_memory_cmp);
+	return ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, OBJECT_BUCKETS,
+		sorcery_memory_hash, NULL, sorcery_memory_cmp);
 }
 
 static void sorcery_memory_close(void *data)
diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c
index 9a1ade0..42da727 100644
--- a/res/res_sorcery_memory_cache.c
+++ b/res/res_sorcery_memory_cache.c
@@ -3528,7 +3528,8 @@
 {
 	int res;
 
-	caches = ao2_container_alloc(CACHES_CONTAINER_BUCKET_SIZE, sorcery_memory_cache_hash,
+	caches = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		CACHES_CONTAINER_BUCKET_SIZE, sorcery_memory_cache_hash, NULL,
 		sorcery_memory_cache_cmp);
 	if (!caches) {
 		ast_log(LOG_ERROR, "Failed to create container for configured caches\n");
diff --git a/res/res_stasis.c b/res/res_stasis.c
index 8362848..127d0e8 100644
--- a/res/res_stasis.c
+++ b/res/res_stasis.c
@@ -2155,9 +2155,12 @@
 	if (STASIS_MESSAGE_TYPE_INIT(end_message_type) != 0) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
-	apps_registry = ao2_container_alloc(APPS_NUM_BUCKETS, app_hash, app_compare);
-	app_controls = ao2_container_alloc(CONTROLS_NUM_BUCKETS, control_hash, control_compare);
-	app_bridges = ao2_container_alloc(BRIDGES_NUM_BUCKETS, bridges_hash, bridges_compare);
+	apps_registry = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		APPS_NUM_BUCKETS, app_hash, NULL, app_compare);
+	app_controls = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		CONTROLS_NUM_BUCKETS, control_hash, NULL, control_compare);
+	app_bridges = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		BRIDGES_NUM_BUCKETS, bridges_hash, NULL, bridges_compare);
 	app_bridges_moh = ao2_container_alloc_hash(
 		AO2_ALLOC_OPT_LOCK_MUTEX, 0,
 		37, bridges_channel_hash_fn, NULL, NULL);
diff --git a/res/res_stasis_device_state.c b/res/res_stasis_device_state.c
index fbdfb3d..d1a9bf7 100644
--- a/res/res_stasis_device_state.c
+++ b/res/res_stasis_device_state.c
@@ -463,9 +463,10 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	if (!(device_state_subscriptions = ao2_container_alloc(
-		      DEVICE_STATE_BUCKETS, device_state_subscriptions_hash,
-		      device_state_subscriptions_cmp))) {
+	device_state_subscriptions = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		DEVICE_STATE_BUCKETS, device_state_subscriptions_hash, NULL,
+		device_state_subscriptions_cmp);
+	if (!device_state_subscriptions) {
 		ast_devstate_prov_del(DEVICE_STATE_PROVIDER_STASIS);
 		return AST_MODULE_LOAD_DECLINE;
 	}
diff --git a/res/res_stasis_playback.c b/res/res_stasis_playback.c
index 6a0e6c3..999e6d0 100644
--- a/res/res_stasis_playback.c
+++ b/res/res_stasis_playback.c
@@ -667,8 +667,8 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	playbacks = ao2_container_alloc(PLAYBACK_BUCKETS, playback_hash,
-		playback_cmp);
+	playbacks = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, PLAYBACK_BUCKETS,
+		playback_hash, NULL, playback_cmp);
 	if (!playbacks) {
 		STASIS_MESSAGE_TYPE_CLEANUP(stasis_app_playback_snapshot_type);
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/res/res_stasis_recording.c b/res/res_stasis_recording.c
index 93c32c9..66203df 100644
--- a/res/res_stasis_recording.c
+++ b/res/res_stasis_recording.c
@@ -636,8 +636,8 @@
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
-	recordings = ao2_container_alloc(RECORDING_BUCKETS, recording_hash,
-		recording_cmp);
+	recordings = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, RECORDING_BUCKETS,
+		recording_hash, NULL, recording_cmp);
 	if (!recordings) {
 		STASIS_MESSAGE_TYPE_CLEANUP(stasis_app_recording_snapshot_type);
 		return AST_MODULE_LOAD_DECLINE;
diff --git a/res/res_timing_pthread.c b/res/res_timing_pthread.c
index f57c737..eee0749 100644
--- a/res/res_timing_pthread.c
+++ b/res/res_timing_pthread.c
@@ -442,8 +442,9 @@
 
 static int load_module(void)
 {
-	if (!(pthread_timers = ao2_container_alloc(PTHREAD_TIMER_BUCKETS,
-		pthread_timer_hash, pthread_timer_cmp))) {
+	pthread_timers = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		PTHREAD_TIMER_BUCKETS, pthread_timer_hash, NULL, pthread_timer_cmp);
+	if (!pthread_timers) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
 
diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index a85892f..2c2a0a9 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -643,7 +643,9 @@
 		return NULL;
 	}
 
-	if (!(client->buddies = ao2_container_alloc(BUDDY_BUCKETS, xmpp_buddy_hash, xmpp_buddy_cmp))) {
+	client->buddies = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, BUDDY_BUCKETS,
+		xmpp_buddy_hash, NULL, xmpp_buddy_cmp);
+	if (!client->buddies) {
 		ast_log(LOG_ERROR, "Could not initialize buddy container for '%s'\n", name);
 		ao2_ref(client, -1);
 		return NULL;
@@ -709,7 +711,9 @@
 		return NULL;
 	}
 
-	if (!(cfg->buddies = ao2_container_alloc(BUDDY_BUCKETS, xmpp_buddy_hash, xmpp_buddy_cmp))) {
+	cfg->buddies = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, BUDDY_BUCKETS,
+		xmpp_buddy_hash, NULL, xmpp_buddy_cmp);
+	if (!cfg->buddies) {
 		ao2_ref(cfg, -1);
 		return NULL;
 	}
@@ -727,14 +731,6 @@
 	ao2_cleanup(cfg->clients);
 }
 
-/*! \brief Hashing function for configuration */
-static int xmpp_config_hash(const void *obj, const int flags)
-{
-	const struct ast_xmpp_client_config *cfg = obj;
-	const char *name = (flags & OBJ_KEY) ? obj : cfg->name;
-	return ast_str_case_hash(name);
-}
-
 /*! \brief Comparator function for configuration */
 static int xmpp_config_cmp(void *obj, void *arg, int flags)
 {
@@ -756,7 +752,9 @@
 		goto error;
 	}
 
-	if (!(cfg->clients = ao2_container_alloc(1, xmpp_config_hash, xmpp_config_cmp))) {
+	cfg->clients = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		NULL, xmpp_config_cmp);
+	if (!cfg->clients) {
 		goto error;
 	}
 
@@ -2256,7 +2254,9 @@
 		return NULL;
 	}
 
-	if (!(buddy->resources = ao2_container_alloc(RESOURCE_BUCKETS, xmpp_resource_hash, xmpp_resource_cmp))) {
+	buddy->resources = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		RESOURCE_BUCKETS, xmpp_resource_hash, NULL, xmpp_resource_cmp);
+	if (!buddy->resources) {
 		ao2_ref(buddy, -1);
 		return NULL;
 	}
diff --git a/tests/test_astobj2.c b/tests/test_astobj2.c
index 68f48ed..c0b9501 100644
--- a/tests/test_astobj2.c
+++ b/tests/test_astobj2.c
@@ -461,7 +461,7 @@
 	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");
+		ast_test_status_update(test, "ao2_container_alloc_list failed.\n");
 		res = AST_TEST_FAIL;
 		goto cleanup;
 	}
@@ -714,9 +714,9 @@
 		break;
 	}
 
-	c = ao2_container_alloc(1, NULL, test_cmp_cb);
+	c = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, test_cmp_cb);
 	if (!c) {
-		ast_test_status_update(test, "ao2_container_alloc failed.\n");
+		ast_test_status_update(test, "ao2_container_alloc_list failed.\n");
 		res = AST_TEST_FAIL;
 		goto cleanup;
 	}
diff --git a/tests/test_astobj2_thrash.c b/tests/test_astobj2_thrash.c
index 324c4f4..36e0ef7 100644
--- a/tests/test_astobj2_thrash.c
+++ b/tests/test_astobj2_thrash.c
@@ -268,8 +268,8 @@
 	data.preload = MAX_HASH_ENTRIES / 2;
 	data.max_grow = MAX_HASH_ENTRIES - data.preload;
 	data.deadline = ast_tvadd(ast_tvnow(), ast_tv(MAX_TEST_SECONDS, 0));
-	data.to_be_thrashed = ao2_container_alloc(HASH_BUCKETS, hash_string,
-		compare_strings);
+	data.to_be_thrashed = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+		HASH_BUCKETS, hash_string, NULL, compare_strings);
 
 	if (data.to_be_thrashed == NULL) {
 		ast_test_status_update(test, "Allocation failed\n");
diff --git a/tests/test_cel.c b/tests/test_cel.c
index 9a3dc81..1461f76 100644
--- a/tests/test_cel.c
+++ b/tests/test_cel.c
@@ -1839,8 +1839,8 @@
 	ast_cel_set_config(cel_test_config);
 
 	/* init CEL event storage (degenerate hash table becomes a linked list) */
-	cel_received_events = ao2_container_alloc(1, NULL, NULL);
-	cel_expected_events = ao2_container_alloc(1, NULL, NULL);
+	cel_received_events = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
+	cel_expected_events = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
 
 	/* start the CEL event callback */
 	if (ast_cel_backend_register(TEST_BACKEND_NAME, test_sub)) {
diff --git a/tests/test_config.c b/tests/test_config.c
index 88e62bd..0d030f1 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -1366,12 +1366,6 @@
 	struct ao2_container *items;
 };
 
-static int test_item_hash(const void *obj, const int flags)
-{
-	const struct test_item *item = obj;
-	const char *name = (flags & OBJ_KEY) ? obj : item->name;
-	return ast_str_case_hash(name);
-}
 static int test_item_cmp(void *obj, void *arg, int flags)
 {
 	struct test_item *one = obj, *two = arg;
@@ -1424,7 +1418,8 @@
 	if (!(cfg->global_defaults = test_item_alloc("global_defaults"))) {
 		goto error;
 	}
-	if (!(cfg->items = ao2_container_alloc(1, test_item_hash, test_item_cmp))) {
+	cfg->items = ao2_container_alloc_list(AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, test_item_cmp);
+	if (!cfg->items) {
 		goto error;
 	}
 	return cfg;
diff --git a/tests/test_scoped_lock.c b/tests/test_scoped_lock.c
index 1881bce..0be86eb 100644
--- a/tests/test_scoped_lock.c
+++ b/tests/test_scoped_lock.c
@@ -199,8 +199,8 @@
 	enum ast_test_result_state res = AST_TEST_PASS;
 	struct ao2_iterator iter;
 	struct test_struct *object_iter;
-	RAII_VAR(struct ao2_container*, container, ao2_container_alloc(13, NULL, NULL), ao2_cleanup);
-	RAII_VAR(struct test_struct *, object, ao2_alloc(sizeof(*object), NULL), ao2_cleanup);
+	RAII_VAR(struct ao2_container*, container, NULL, ao2_cleanup);
+	RAII_VAR(struct test_struct *, object, NULL, ao2_cleanup);
 
 	switch(cmd) {
 	case TEST_INIT:
@@ -216,6 +216,8 @@
 	}
 	current_test = test;
 
+	container = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0, 13, NULL, NULL, NULL);
+	object = ao2_alloc(sizeof(*object), NULL);
 	if (!object || !container) {
 		/* Allocation failure. We can't even pretend to do this test properly */
 		return AST_TEST_FAIL;

-- 
To view, visit https://gerrit.asterisk.org/10698
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I0907d78bc66efc775672df37c8faad00f2f6c088
Gerrit-Change-Number: 10698
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20181119/2fb92f41/attachment-0001.html>


More information about the asterisk-code-review mailing list