[Asterisk-code-review] res sorcery memory cache.c: Misc tweaks. (asterisk[master])

Richard Mudgett asteriskteam at digium.com
Thu Oct 1 17:31:26 CDT 2015


Richard Mudgett has uploaded a new change for review.

  https://gerrit.asterisk.org/1357

Change subject: res_sorcery_memory_cache.c: Misc tweaks.
......................................................................

res_sorcery_memory_cache.c: Misc tweaks.

Change-Id: I8cd32dffbb4f33bb0c39518d6e4c991e73573160
---
M res/res_sorcery_memory_cache.c
1 file changed, 7 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/1357/1

diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c
index a51e8df..0a33ae4 100644
--- a/res/res_sorcery_memory_cache.c
+++ b/res/res_sorcery_memory_cache.c
@@ -369,10 +369,10 @@
 	struct sorcery_memory_cache *cache = obj;
 
 	ast_free(cache->name);
-	ao2_cleanup(cache->objects);
 	if (cache->object_heap) {
 		ast_heap_destroy(cache->object_heap);
 	}
+	ao2_cleanup(cache->objects);
 }
 
 /*!
@@ -411,8 +411,7 @@
 	struct sorcery_memory_cached_object *oldest_object;
 	struct sorcery_memory_cached_object *heap_object;
 
-	hash_object = ao2_find(cache->objects, id,
-		OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NOLOCK);
+	hash_object = ao2_find(cache->objects, id, OBJ_SEARCH_KEY | OBJ_UNLINK | OBJ_NOLOCK);
 	if (!hash_object) {
 		return -1;
 	}
@@ -448,7 +447,7 @@
 
 	cache->expire_id = -1;
 
-	/* This is an optimization for objects which have been cached close to eachother */
+	/* This is an optimization for objects which have been cached close to each other */
 	while ((cached = ast_heap_peek(cache->object_heap, 1))) {
 		int expiration;
 
@@ -483,7 +482,8 @@
  */
 static void remove_all_from_cache(struct sorcery_memory_cache *cache)
 {
-	while (ast_heap_pop(cache->object_heap));
+	while (ast_heap_pop(cache->object_heap)) {
+	}
 
 	ao2_callback(cache->objects, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA | OBJ_MULTIPLE,
 		NULL, NULL);
@@ -717,8 +717,8 @@
 		if (remove_oldest_from_cache(cache)) {
 			ast_log(LOG_ERROR, "Unable to make room in cache for sorcery object '%s'.\n",
 				ast_sorcery_object_get_id(object));
-			ao2_ref(cached, -1);
 			ao2_unlock(cache->objects);
+			ao2_ref(cached, -1);
 			return -1;
 		}
 		ast_assert(ao2_container_count(cache->objects) != cache->maximum_objects);
@@ -726,8 +726,8 @@
 	if (add_to_cache(cache, cached)) {
 		ast_log(LOG_ERROR, "Unable to add object '%s' to the cache\n",
 			ast_sorcery_object_get_id(object));
-		ao2_ref(cached, -1);
 		ao2_unlock(cache->objects);
+		ao2_ref(cached, -1);
 		return -1;
 	}
 	ao2_unlock(cache->objects);

-- 
To view, visit https://gerrit.asterisk.org/1357
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8cd32dffbb4f33bb0c39518d6e4c991e73573160
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>



More information about the asterisk-code-review mailing list