summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins2 <jenkins2@gerrit.asterisk.org>2017-10-12 10:37:25 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2017-10-12 10:37:25 -0500
commitafb7c500556426650c5893ff3292ded027de5a0c (patch)
tree9d36bbe3755d6a55eb5c038600499714ef0e697c
parent765dfdc52953fef59f806599375696fc30a05c6d (diff)
parentfa3aa3417bdfa031da15ff86bc88224894a96e6d (diff)
Merge "named_locks: Use ao2_weakproxy_find." into 14
-rw-r--r--main/named_locks.c24
1 files changed, 7 insertions, 17 deletions
diff --git a/main/named_locks.c b/main/named_locks.c
index 92b8262c1..6bec8f90e 100644
--- a/main/named_locks.c
+++ b/main/named_locks.c
@@ -110,31 +110,21 @@ static void named_lock_proxy_cb(void *weakproxy, void *data)
struct ast_named_lock *__ast_named_lock_get(const char *filename, int lineno, const char *func,
enum ast_named_lock_type lock_type, const char *keyspace, const char *key)
{
- struct named_lock_proxy *proxy = NULL;
- struct ast_named_lock *lock = NULL;
+ struct named_lock_proxy *proxy;
+ struct ast_named_lock *lock;
int keylen = strlen(keyspace) + strlen(key) + 2;
char *concat_key = ast_alloca(keylen);
sprintf(concat_key, "%s-%s", keyspace, key); /* Safe */
ao2_lock(named_locks);
- proxy = ao2_find(named_locks, concat_key, OBJ_SEARCH_KEY | OBJ_NOLOCK);
- if (proxy) {
+ lock = __ao2_weakproxy_find(named_locks, concat_key, OBJ_SEARCH_KEY | OBJ_NOLOCK,
+ __PRETTY_FUNCTION__, filename, lineno, func);
+ if (lock) {
+ ast_assert((ao2_options_get(lock) & AO2_ALLOC_OPT_LOCK_MASK) == lock_type);
ao2_unlock(named_locks);
- lock = __ao2_weakproxy_get_object(proxy, 0, __PRETTY_FUNCTION__, filename, lineno, func);
- if (lock) {
- /* We have an existing lock and it's not being destroyed. */
- ao2_ref(proxy, -1);
- ast_assert((ao2_options_get(lock) & AO2_ALLOC_OPT_LOCK_MASK) == lock_type);
-
- return lock;
- }
-
- /* the old proxy is being destroyed, clean list before creating/adding new one */
- ao2_lock(named_locks);
- ao2_unlink_flags(named_locks, proxy, OBJ_NOLOCK);
- ao2_ref(proxy, -1);
+ return lock;
}
proxy = ao2_t_weakproxy_alloc(sizeof(*proxy) + keylen, NULL, concat_key);