]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
astobj2: Eliminate usage of legacy ao2_container_alloc routine.
authorCorey Farrell <git@cfware.com>
Mon, 19 Nov 2018 20:10:15 +0000 (15:10 -0500)
committerCorey Farrell <git@cfware.com>
Wed, 21 Nov 2018 14:56:12 +0000 (09:56 -0500)
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

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

index 5936400216be0fa55beef0c9b97279c864c2c2dd..ad871e0fe7d70eff94358bd52c753610a30c7e60 100644 (file)
@@ -4196,8 +4196,9 @@ static int load_module(void)
        }
 
        /* 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;
index 40c0bd29db15d5c84216b378049faadb4d1b0024..6984bd2eb61cc7de04479f490f0d061ad1a7b331 100644 (file)
@@ -1624,8 +1624,14 @@ static struct ast_conference *build_conf(const char *confno, const char *pin,
 
        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;
        }
 
@@ -7395,13 +7401,6 @@ static void sla_station_destructor(void *obj)
        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;
@@ -7409,13 +7408,6 @@ static int sla_trunk_cmp(void *obj, void *arg, int flags)
        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;
@@ -7869,8 +7861,10 @@ static int sla_load_config(int reload)
        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))) {
index 5bb8733ef82d0e44556b1449b8a9318fc7e60cce..17e35f9bbb03545f4a9044f2cd2e5315ca6eed7a 100644 (file)
@@ -2800,10 +2800,11 @@ static void init_queue(struct call_queue *q)
        q->autopausedelay = 0;
        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);
+                       /* linear strategy depends on order, so we have to place all members in a list */
+                       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;
@@ -11240,13 +11241,14 @@ static int load_module(void)
        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;
index e58f6252f6734b394233d67cd6ba88294e6e1bfb..e0b8bca7bc52d92db5256ae7b3bbd8be64b9f845 100644 (file)
@@ -580,7 +580,9 @@ static void *skel_config_alloc(void)
                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;
        }
 
@@ -725,7 +727,9 @@ static int load_module(void)
        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;
        }
 
index 554363a5c24f6c31a20796e5a26c33b0ddc131bb..595c2dccfaef6144a0659706e50ee3de365405c2 100644 (file)
@@ -15066,11 +15066,14 @@ static int load_module(void)
        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);
index 9e56b3665bcc87cf55d84a7ea08d6acb8489c00d..53061ba60f05b3bf1ed59f3d5ff19046c86f6ddf 100644 (file)
@@ -1987,15 +1987,21 @@ void *confbridge_cfg_alloc(void)
                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;
        }
 
index 7692b26cc244bd038ec5cb4a66623341ac4d531a..9113ffa92596f00c95b49da25d0e6d252d0a3a13 100644 (file)
@@ -1534,7 +1534,9 @@ static int load_module(void)
 
        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))
index 0ca4234d7d15234546babcb0f9f4cc039c1caba8..6f88d098cd17b20886ac8b1c18a9dd992cd9db32 100644 (file)
@@ -14714,23 +14714,54 @@ static int load_objects(void)
        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;
        }
 
index 05184ca04970b966142634c40352f0cdc42f9b44..a9dd2afcf039ac1cb8b3bb2d318532c74298eff9 100644 (file)
@@ -471,7 +471,9 @@ static struct jingle_endpoint_state *jingle_endpoint_state_create(void)
                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;
        }
@@ -601,7 +603,9 @@ static void *jingle_config_alloc(void)
                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;
        }
index 9089b5e10044ea6e6d9ada4405b25d78ec922b42..3be80d57e25dbaaca32eb35582d6a1a36a534f94 100644 (file)
@@ -1815,8 +1815,9 @@ static int initialize_escs(void)
 {
        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;
                }
        }
@@ -35517,7 +35518,9 @@ static int load_module(void)
                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;
        }
index 28d84eeea7d903dd48698a4dcbe433b57c74350f..7051961018dc3b02ac16fee4981097352503bf71 100644 (file)
@@ -813,7 +813,9 @@ static const char *ustmtext(const char *str, struct unistimsession *pte)
                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;
                }
index ec6d666aea6c2360cb88df1be4ee30b93e1b8434..3675b0efaaf5d2536f41ee9baba9758d002e9cf1 100644 (file)
@@ -10133,8 +10133,8 @@ int sig_pri_load(const char *cc_type_name)
 
 #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;
        }
index e57800010645e0d7240e967e3f866930d4434d9d..9a98b3ca24d406cd00b3b82e5d858510578f2a27 100644 (file)
@@ -221,7 +221,8 @@ static int dialgroup_write(struct ast_channel *chan, const char *cmd, char *data
                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;
@@ -236,7 +237,9 @@ static int dialgroup_write(struct ast_channel *chan, const char *cmd, char *data
 
                /* 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;
@@ -297,7 +300,9 @@ static int load_module(void)
        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) {
index 5cb83101996b7612c71d5d1aede85fff30edb723..acb5fc935cc8149d0053f8a1b53ab8a75b2285ea 100644 (file)
@@ -215,12 +215,6 @@ static void *lock_broker(void *unused)
        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;
@@ -296,7 +290,9 @@ static int get_lock(struct ast_channel *chan, char *lockname, int trylock)
                        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);
index 66722df141ed31c59a14aebe6530cb115b182618..9a124c1167705901ddb14f33f07dfb8ec28953eb 100644 (file)
@@ -1793,7 +1793,8 @@ static int load_module(void)
        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);
@@ -1891,7 +1892,8 @@ static int reload(void)
        }
 
        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);
index 2910304dc3249f99e148ac63f729a1128bb0b708..beba26eb63e96b2f44bd268c8148328dc62b0ddc 100644 (file)
@@ -93,7 +93,8 @@ parameters. At the moment, this is done as follows:
 
     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
@@ -109,7 +110,7 @@ A container knows little or nothing about the objects it stores,
 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() --
@@ -936,20 +937,8 @@ and perform various operations on them.
 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
@@ -1297,6 +1286,10 @@ typedef int (ao2_sort_fn)(const void *obj_left, const void *obj_right, int flags
 /*@{ */
 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.
@@ -1316,17 +1309,13 @@ 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_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
index 0ec728e558336ae199247b15c567b8cc272dccef..feb3bee865794fb46804125067704727109ad4a9 100644 (file)
@@ -1561,15 +1561,16 @@ static int load_module(void)
 {
        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 AST_MODULE_LOAD_FAILURE;
        }
 
-       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 @@ static int load_module(void)
                return AST_MODULE_LOAD_FAILURE;
        }
 
-       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) {
index a72439c3722074fc8156a0f4c593b923637b62bd..6c6e9f758b4e12a321249b679362e4ad3ca34303 100644 (file)
@@ -7856,8 +7856,8 @@ static void channels_shutdown(void)
 
 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;
        }
index b926514ca48e7b11d8356e304fb20c217eb890f7..a963a7d3ea03e13a30b7e1d2e454fdee42390468 100644 (file)
@@ -1302,7 +1302,9 @@ struct ast_channel *__ast_channel_internal_alloc(void (*destructor)(void *obj),
                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);
        }
 
index 1961b24fe5a5c01982137310d829256dfa8dc2c2..f694c2bd8c6bda8f3a082e5fe2fb19e1e259eeea 100644 (file)
@@ -2536,7 +2536,8 @@ int ast_config_text_file_save2(const char *configfile, const struct ast_config *
        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;
@@ -4104,8 +4105,12 @@ int ast_config_hook_register(const char *name,
                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))) {
index 2d5e09c8d000ac7f8ca3ab317c961755888f2abb..cbd762235dc5adce3e7c52a7934a324ad894fe43 100644 (file)
@@ -405,7 +405,8 @@ static struct aco_option *aco_option_find(struct aco_type *type, const char *nam
 
 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)
index 5edad24133e22945c39d8e115d6eef59e18f29c7..f37ee6c4d4de0cbbc3d506fcbb68701ba1fc0263 100644 (file)
@@ -94,7 +94,8 @@ AO2_STRING_FIELD_CMP_FN(ast_datastore, uid);
 
 struct ao2_container *ast_datastores_alloc(void)
 {
-       return ao2_container_alloc(DATASTORE_BUCKETS, ast_datastore_hash_fn, ast_datastore_cmp_fn);
+       return ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+               DATASTORE_BUCKETS, ast_datastore_hash_fn, NULL, ast_datastore_cmp_fn);
 }
 
 int ast_datastores_add(struct ao2_container *datastores, struct ast_datastore *datastore)
index 3129fb49f7c8852c25092972121cead1394c9adf..030e26cb5b32ac36d697401af20c46650d7a97a3 100644 (file)
@@ -482,14 +482,14 @@ int ast_endpoint_init(void)
 {
        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;
        }
index 77755a9b2f6c2ab4b16cae77ff70869d2dc54285..1f77ca1d172069f286f127c21b9cb927504bac07 100644 (file)
@@ -1133,8 +1133,8 @@ static int unload_module(void)
 /*! \brief Load indications module */
 static int load_module(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 AST_MODULE_LOAD_FAILURE;
        }
index 0da023a518949808a2e21d494314b87ed0ed4323..0469a737eeee0581d8c353b2bc4a840ac6c95342 100644 (file)
@@ -2224,8 +2224,8 @@ static struct mansession_session *build_mansession(const struct ast_sockaddr *ad
                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;
@@ -7639,7 +7639,8 @@ static void xml_translate(struct ast_str **out, char *in, struct ast_variable *g
                        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;
                }
 
@@ -9067,7 +9068,7 @@ static int __init_manager(int reload, int by_external_config)
 #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;
                }
@@ -9323,8 +9324,8 @@ static int __init_manager(int reload, int by_external_config)
                        /* 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;
index bfaa58003cc496709ff67ea43ac18a5ecd787d34..2d1bc6bbd6907fa3f9ba9b0fcaa998f8c7104c7d 100644 (file)
@@ -121,7 +121,8 @@ static struct media_info *media_info_alloc(const char *name)
 
        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 @@ struct ast_media_index *ast_media_index_create(const char *base_dir)
 
        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);
 
index b7d14f1e8fc405bbdaa0ed4f892a1682817a3460..487416277781fd286152f09d6f36b27e259bb37e 100644 (file)
@@ -367,12 +367,6 @@ static void msg_ds_destroy(void *data)
        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;
@@ -406,7 +400,9 @@ struct ast_msg *ast_msg_alloc(void)
                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;
        }
index 8cf09c2a07a812ebee650d4e5824d333a988228f..8e9da3a1d8618c266d98ab4a356e6d202808d146 100644 (file)
@@ -131,7 +131,9 @@ static void *named_acl_config_alloc(void)
                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;
        }
 
index 0a23735c05f12de6a892a8aac99ac746dc828ae3..9e19f353c0a0edccfbc60344e00ef3f08c5440ae 100644 (file)
@@ -3953,7 +3953,7 @@ static int ast_add_hint(struct ast_exten *e)
        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;
@@ -8912,11 +8912,13 @@ static void print_statecbs_key(void *v_obj, void *where, ao2_prnt_fn *prnt)
 
 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);
        }
@@ -8926,7 +8928,7 @@ int ast_pbx_init(void)
        if (autohints) {
                ao2_container_register("autohints", autohints, print_autohint_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);
        }
index 417caaf19521c3124aaebd2e6a36436f328d2528..0c60b13290bdf2361854f74bca141658e81afce2 100644 (file)
@@ -1284,8 +1284,8 @@ 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);
+       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;
index 8041c8e4964d019028b2c939f33e1409cf8d3454..0da80057d95531aa43286d198c9131e694a77458 100644 (file)
@@ -615,8 +615,8 @@ struct ast_multi_channel_blob *ast_multi_channel_blob_create(struct ast_json *bl
                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;
@@ -719,8 +719,9 @@ struct ao2_container *ast_multi_channel_blob_get_channels(struct ast_multi_chann
                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;
        }
index 68bd29ce9736ab273cd482cbd45a612a723fbd87..30aeddbd826d24be01f3e33c7208dfd2120016c1 100644 (file)
@@ -278,7 +278,9 @@ static void tps_shutdown(void)
 /* 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;
        }
index 77299305454ad4f0b16d04cae538a1ad39b60825..2ab093663cc9dccf0848562de0ec5fed22edd61c 100644 (file)
@@ -420,15 +420,18 @@ static struct ast_threadpool *threadpool_alloc(const char *name, const struct as
        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;
        }
index 43ae074d06e6942f08006b1c4c62448307705871..8b273f0297475b3a3c7aef4f99524200da3bb72c 100644 (file)
@@ -2657,7 +2657,9 @@ struct ao2_container *ast_xmldoc_build_documentation(const char *type)
        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;
        }
index 29d2e0820d2338ac2cd6c95e25270a406a96d8cf..75e6654f07be863946f078e0290a0de7d346910b 100644 (file)
@@ -401,7 +401,9 @@ static int unload_module(void)
 
 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;
        }
 
index 5a8e8985858cd5c69fa4bf0ed6a74ad5845199b0..5983f7b531be94f9dc7ac752ba18349a182e7b78 100644 (file)
@@ -467,9 +467,8 @@ void ast_ari_websocket_events_event_websocket_dtor(void)
 int ast_ari_websocket_events_event_websocket_init(void)
 {
        /* Try to instantiate the registry */
-       event_session_registry = ao2_container_alloc(EVENT_SESSION_NUM_BUCKETS,
-                                                    event_session_hash,
-                                                    event_session_compare);
+       event_session_registry = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+               EVENT_SESSION_NUM_BUCKETS, event_session_hash, NULL, event_session_compare);
        if (!event_session_registry) {
                /* This is bad, bad. */
                ast_log(LOG_WARNING,
index c46307f9523847946acbb1a467ac51ca476eada3..f629e3d020f43ab3dcf3cc2e80b4ca066665760c 100644 (file)
@@ -415,7 +415,9 @@ static struct ast_calendar *build_calendar(struct ast_config *cfg, const char *c
                        return NULL;
                }
 
-               if (!(cal->events = ao2_container_alloc(CALENDAR_BUCKETS, event_hash_fn, event_cmp_fn))) {
+               cal->events = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+                       CALENDAR_BUCKETS, event_hash_fn, NULL, event_cmp_fn);
+               if (!cal->events) {
                        ast_log(LOG_ERROR, "Could not allocate events container for %s\n", cat);
                        cal = unref_calendar(cal);
                        return NULL;
@@ -686,7 +688,8 @@ struct ast_calendar_event *ast_calendar_event_alloc(struct ast_calendar *cal)
 
 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)
@@ -1896,7 +1899,9 @@ static int unload_module(void)
  */
 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;
        }
index eaf9b9fec37824e0747e3ddaacd14032a01ab2f0..9658c17bd4098e7bb3d482fdbbd8131638f37f47 100644 (file)
@@ -282,7 +282,9 @@ static int unload_module(void)
  */
 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;
        }
 
index 854034f38fae7371f38647d83fda6e91f5e93503..6446f172e6b51640e5f4735ce74c8654700a32e2 100644 (file)
@@ -1194,7 +1194,9 @@ static int realtime_sqlite3_require(const char *database, const char *table, va_
                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;
        }
@@ -1369,7 +1371,9 @@ static int load_module(void)
 {
        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;
        }
 
index 50dd510e0451d90120ee3d3c1f4ddcfb41e1b830..bf172e31837bb05f2e07b4159c8f84a504dc55dd 100644 (file)
@@ -1125,7 +1125,8 @@ static int load_module(void)
                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;
        }
index f03fdc912a78853ab0ade89af786ce16e20b6ccb..39a7a64c2a52d9e6289381cfdbbf9598312ea396 100644 (file)
@@ -4724,7 +4724,9 @@ static int load_module(void)
        /* 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;
        }
 
index d64ecba7f7b9efcaf16921885dd32813a213f708..0b75721097e78681f78169a6a6fa3ee9410590bd 100644 (file)
@@ -147,7 +147,8 @@ static struct ast_websocket_server *websocket_server_create_impl(void)
                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;
        }
index 1c82e3f55fafc764188865b46887daeae7ab7775..a9fe7c7455281253596533b4d1101cded785642e 100644 (file)
@@ -178,11 +178,6 @@ static void odbc_class_destructor(void *data)
        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;
@@ -1001,7 +996,8 @@ static int unload_module(void)
 
 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;
        }
 
index 5d1b30c2305792a04c6e525e923aab6706de35d6..afde599265c75c4e310599a24eb81ee26316fc50 100644 (file)
@@ -385,7 +385,9 @@ static void *parking_config_alloc(void)
                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;
        }
 
index 70e13332892c192424926d4a1ed60a1ee55ea8cb..9b26ab2ed88a85693f66bf50a886286314b7f203 100644 (file)
@@ -1413,13 +1413,15 @@ static int unload_module(void)
  */
 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;
@@ -1430,13 +1432,15 @@ static int load_module(void)
                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;
index 13a9ff88ae8ed2c0001900a7f9437a23030bd555..3b86df92e15b7c826fb11066d5a3bb21e4d9dafa 100644 (file)
@@ -1377,7 +1377,8 @@ static int populate_transport_states(void *obj, void *arg, int flags)
 
 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;
@@ -1394,7 +1395,8 @@ int ast_sip_initialize_sorcery_transport(void)
        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;
index efacb5809d6095f40fdb2d178e866f85696c36fa..a3cfde9920f77c07a28e58b1e56e6a053e9db935 100644 (file)
@@ -354,8 +354,8 @@ int ast_sip_initialize_transport_management(void)
 {
        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;
index 47ec8b461d8eb454b769caddc391f56e5fc8c222..df9a35f3326b36a01703c900d939478dfbce71e8 100644 (file)
@@ -959,8 +959,8 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-       publishers = ao2_container_alloc(PUBLISHER_BUCKETS, exten_state_publisher_hash,
-               exten_state_publisher_cmp);
+       publishers = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+               PUBLISHER_BUCKETS, exten_state_publisher_hash, NULL, exten_state_publisher_cmp);
        if (!publishers) {
                ast_log(LOG_WARNING, "Unable to create container to store extension state publishers\n");
                return AST_MODULE_LOAD_DECLINE;
index 83bff8893c07619202f45746c9f243aa8e1158ba..eeb8a18a63d7bd2687ffba0cae89d17535d31636 100644 (file)
@@ -361,7 +361,8 @@ 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);
+       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;
index e4e9fd4ac4c5a0cdba6e343d318f53da4a67eb76..242e43f07466a19d792e3954e6576e866ad7a072 100644 (file)
@@ -1435,14 +1435,16 @@ static struct ast_sip_outbound_publish_state *sip_outbound_publish_state_alloc(
                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;
        }
 
-       state->client->publishers = ao2_container_alloc(DATASTORE_BUCKETS, sip_outbound_publisher_hash_fn,
-                                                       sip_outbound_publisher_cmp_fn);
+       state->client->publishers = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+               DATASTORE_BUCKETS,
+               sip_outbound_publisher_hash_fn, NULL, sip_outbound_publisher_cmp_fn);
        if (!state->client->publishers) {
                ao2_ref(state, -1);
                return NULL;
index 7aba73441db66d4b589fe1843722aca0d837c86c..efeae23c03f91a4cbe891943b91a4ce4c49b1c21 100644 (file)
@@ -2194,8 +2194,8 @@ static int load_module(void)
        }
 
        /* 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();
index 9e8a32bf7961add946c349a70e29cc861cec51a9..394b1acc548f47b1b6cd3b33bc3ec41e728b7334 100644 (file)
@@ -2676,8 +2676,9 @@ int ast_sip_register_publish_handler(struct ast_sip_publish_handler *handler)
                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;
index 13c123ae10ca55fbc2b8de4d0c450df2d9d3bce8..0df0141946faaa1f5b7277a1fe19be6725bcadf9 100644 (file)
@@ -2181,7 +2181,8 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
        if (!session->direct_media_cap) {
                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;
        }
@@ -4266,8 +4267,8 @@ static int load_module(void)
        }
        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;
        }
index 465f9bc23ac51e381bf88d74feb00d1fb700243c..00d88831ae87d226c57f1c5b37dcd51c550c63ce 100644 (file)
@@ -686,9 +686,12 @@ static void ast_rtp_ice_add_remote_candidate(struct ast_rtp_instance *instance,
                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 */
@@ -1103,8 +1106,12 @@ static void ast_rtp_ice_add_cand(struct ast_rtp_instance *instance, struct ast_r
 
        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))) {
index 6c91dad2d732f7d403cb9c37c550271a1fb1802b..1e8bef94b7720e14a7c8d98de135c2078b386494 100644 (file)
@@ -250,7 +250,8 @@ static int sorcery_memory_delete(const struct ast_sorcery *sorcery, void *data,
 
 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)
index 9a1ade09f3904a8b115e63fbd4e2b637ec04c141..42da7273d3e52e8d7f0ac9a01091e58009633785 100644 (file)
@@ -3528,7 +3528,8 @@ static int load_module(void)
 {
        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");
index 82d879240628755a20615ac8a9f15bd75a797bb8..704d779c48485b835750b8b89efe06b151135a15 100644 (file)
@@ -2167,9 +2167,12 @@ static int load_module(void)
        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);
index 1c80f9efaa221dbe26fec06621039b3692a7f100..71b9c15ffed9f0193483af9a23b50f22e54d36ca 100644 (file)
@@ -461,9 +461,10 @@ static int load_module(void)
                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;
        }
index a25a3005b545a8738ac4b4188a8bfe033b390c43..4a8e84dc241aa9cd23d12033bb7f37fc4a1dbfe5 100644 (file)
@@ -738,8 +738,8 @@ static int load_module(void)
                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;
index 755bdcf3aa6d9912759631d98e95ac2f0ff6398d..4077fc8a34e63c14bcaba55ed605813cbcc005fa 100644 (file)
@@ -634,8 +634,8 @@ static int load_module(void)
                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;
index bcc9eb0e8c5a5221b3f5f557e41b5a7a2dffcf3d..c1015798104d42f9f45d4e984d52223d8f4d21f7 100644 (file)
@@ -440,8 +440,9 @@ static int init_timing_thread(void)
 
 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;
        }
 
index 7d032ad5d534d517ae04102380c26efcd92fe132..3a2d7497a06bce87bebdc9cc179c995d85623857 100644 (file)
@@ -641,7 +641,9 @@ static struct ast_xmpp_client *xmpp_client_alloc(const char *name)
                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;
@@ -707,7 +709,9 @@ static void *ast_xmpp_client_config_alloc(const char *cat)
                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;
        }
@@ -725,14 +729,6 @@ static void xmpp_config_destructor(void *obj)
        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)
 {
@@ -754,7 +750,9 @@ static void *xmpp_config_alloc(void)
                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;
        }
 
@@ -2254,7 +2252,9 @@ static struct ast_xmpp_buddy *xmpp_client_create_buddy(struct ao2_container *con
                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;
        }
index 4abe28a9619064d471e2751bdac77a9b322dc317..ce519acfc809fceaa8e08642f5240269c184d9d1 100644 (file)
@@ -712,9 +712,9 @@ AST_TEST_DEFINE(astobj2_test_2)
                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;
        }
index a3592468d911e250ab2801bff9f0cd425e886560..8a7e64c6aed6871790352f42e2962b840075dd25 100644 (file)
@@ -267,8 +267,8 @@ AST_TEST_DEFINE(hash_test)
        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");
index c9ceaf93c94b3154544ba1b767f1998ea50b1424..0b17d488b6956995f3f61e4372376343537f696d 100644 (file)
@@ -1837,8 +1837,8 @@ static int test_cel_init_cb(struct ast_test_info *info, struct ast_test *test)
        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)) {
index e00b30b3945fb15bb9f612313628ee6255a63672..c429bbea828c2791407939098c8ceedcaffb7c55 100644 (file)
@@ -1364,12 +1364,6 @@ struct test_config {
        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;
@@ -1422,7 +1416,8 @@ static void *test_config_alloc(void)
        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;
index 1881bce7e135a6d3dd590ab1da33632674c37e0e..0be86ebae889566d84e0b0665a065f410084c87f 100644 (file)
@@ -199,8 +199,8 @@ AST_TEST_DEFINE(cleanup_order)
        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 @@ AST_TEST_DEFINE(cleanup_order)
        }
        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;