From e65f170d9c5966d33b32eab57b7e67196126cdc7 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Fri, 26 Aug 2016 18:22:51 -0400 Subject: sorcery: Create function ast_sorcery_lockable_alloc. Create an alternative to ast_sorcery_generic_alloc which uses astobj2 shared locking. Use this new method for the 'struct ast_sip_aor' allocator. Change-Id: I3f62f2ada64b622571950278fbb6ad57395b5d6f --- res/res_pjsip/location.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'res/res_pjsip') diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c index 0ab69ec5b..5abfcabad 100644 --- a/res/res_pjsip/location.c +++ b/res/res_pjsip/location.c @@ -49,11 +49,22 @@ static void aor_destroy(void *obj) /*! \brief Allocator for AOR */ static void *aor_alloc(const char *name) { - struct ast_sip_aor *aor = ast_sorcery_generic_alloc(sizeof(struct ast_sip_aor), aor_destroy); + void *lock; + struct ast_sip_aor *aor; + + lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", name); + if (!lock) { + return NULL; + } + + aor = ast_sorcery_lockable_alloc(sizeof(struct ast_sip_aor), aor_destroy, lock); + ao2_ref(lock, -1); + if (!aor) { return NULL; } ast_string_field_init(aor, 128); + return aor; } @@ -206,17 +217,11 @@ struct ao2_container *ast_sip_location_retrieve_aor_contacts_nolock(const struct struct ao2_container *ast_sip_location_retrieve_aor_contacts(const struct ast_sip_aor *aor) { struct ao2_container *contacts; - struct ast_named_lock *lock; - lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", ast_sorcery_object_get_id(aor)); - if (!lock) { - return NULL; - } - - ao2_lock(lock); + /* ao2_lock / ao2_unlock do not actually write aor since it has an ao2 lockobj. */ + ao2_lock((void*)aor); contacts = ast_sip_location_retrieve_aor_contacts_nolock(aor); - ao2_unlock(lock); - ast_named_lock_put(lock); + ao2_unlock((void*)aor); return contacts; } @@ -369,19 +374,12 @@ int ast_sip_location_add_contact(struct ast_sip_aor *aor, const char *uri, struct ast_sip_endpoint *endpoint) { int res; - struct ast_named_lock *lock; - - lock = ast_named_lock_get(AST_NAMED_LOCK_TYPE_MUTEX, "aor", ast_sorcery_object_get_id(aor)); - if (!lock) { - return -1; - } - ao2_lock(lock); + ao2_lock(aor); res = ast_sip_location_add_contact_nolock(aor, uri, expiration_time, path_info, user_agent, via_addr, via_port, call_id, endpoint); - ao2_unlock(lock); - ast_named_lock_put(lock); + ao2_unlock(aor); return res; } -- cgit v1.2.3