All pastes #775851 Raw Edit

snuffy

public diff v1 · immutable
·published 2007-11-15 19:19 UTC
rendered paste body
Index: main/hashtab.c===================================================================--- main/hashtab.c	(revision 89283)+++ main/hashtab.c	(working copy)@@ -26,22 +26,17 @@  ASTERISK_FILE_VERSION(__FILE__, "$Revision") -#include <stdio.h>-#include <stdlib.h> #include <unistd.h>-#include <string.h> #include <ctype.h> #include <errno.h> #include <stddef.h> -#include "asterisk/lock.h"+#include "asterisk/utils.h" #include "asterisk/frame.h"-#include "asterisk/logger.h" #include "asterisk/options.h" #include "asterisk/channel.h" #include "asterisk/cli.h" #include "asterisk/term.h"-#include "asterisk/utils.h" #include "asterisk/threadstorage.h" #include "asterisk/linkedlists.h" #include "asterisk/hashtab.h"@@ -390,66 +385,27 @@  int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj) {-	/* normally, you'd insert "safely" by checking to see if the element is-	   already there; in this case, you must already have checked. If an element-	   is already in the hashtable, that matches this one, most likely this one-	   will be found first, but.... */--	/* will force a resize if the resize func returns 1 */-	/* returns 1 on success, 0 if there's a problem */ 	unsigned int h;-	int c;-	struct ast_hashtab_bucket *b;+	int res=0; 	-	if (!tab)-		return 0;+	if (!tab || !obj)+		return res; -	if (!obj)-		return 0;- 	if (tab->do_locking) 		ast_rwlock_wrlock(&tab->lock);  	h = (*tab->hash)(obj) % tab->hash_tab_size; -	for (c = 0, b = tab->array[h]; b; b = b->next)-		c++;+	res = ast_hashtab_insert_immediate_bucket(tab,obj,h); -	if (c + 1 > tab->largest_bucket_size)-		tab->largest_bucket_size = c + 1;--	if (!(b = ast_calloc(1, sizeof(*b))))-		return 0;--	b->object = obj;-	b->next = tab->array[h];--	if (b->next)-		b->next->prev = b;--	tlist_add_head(&(tab->tlist), b);-	-	tab->array[h] = b;-	tab->hash_tab_elements++;--	if ((*tab->resize)(tab))-		ast_hashtab_resize(tab);- 	if (tab->do_locking) 		ast_rwlock_unlock(&tab->lock); -	return 1;+	return res; }  int ast_hashtab_insert_immediate_bucket(struct ast_hashtab *tab, const void *obj, unsigned int h) {-	/* normally, you'd insert "safely" by checking to see if the element is-	   already there; in this case, you must already have checked. If an element-	   is already in the hashtable, that matches this one, most likely this one-	   will be found first, but.... */--	/* will force a resize if the resize func returns 1 */-	/* returns 1 on success, 0 if there's a problem */ 	int c; 	struct ast_hashtab_bucket *b; 	@@ -766,8 +722,7 @@ void *ast_hashtab_remove_object_via_lookup(struct ast_hashtab *tab, void *obj) { 	/* looks up the object; removes the corresponding bucket */-	unsigned int h;-	struct ast_hashtab_bucket *b;+	const void *obj2;  	if (!tab || !obj) 		return 0;@@ -775,24 +730,12 @@ 	if (tab->do_locking) 		ast_rwlock_wrlock(&tab->lock); -	h = (*tab->hash)(obj) % tab->hash_tab_size;-	for (b = tab->array[h]; b; b = b->next) {-		void *obj2;-		-		if (!(*tab->compare)(obj,b->object)) {-			obj2 = ast_hashtab_remove_object_internal(tab,b,h);-			-			if (tab->do_locking)-				ast_rwlock_unlock(&tab->lock);-			-			return (void *) obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */-		}-	}+	obj2 = ast_hashtab_remove_object_via_lookup_nolock(tab,obj);  	if (tab->do_locking) 		ast_rwlock_unlock(&tab->lock); -	return 0;+	return obj2; }  void *ast_hashtab_remove_object_via_lookup_nolock(struct ast_hashtab *tab, void *obj)@@ -806,15 +749,12 @@  	h = (*tab->hash)(obj) % tab->hash_tab_size; 	for (b = tab->array[h]; b; b = b->next) {-		void *obj2;+		const void *obj2; 		 		if (!(*tab->compare)(obj, b->object)) {  			obj2 = ast_hashtab_remove_object_internal(tab, b, h); 			-			if (tab->do_locking)-				ast_rwlock_unlock(&tab->lock);-			 			return (void *) obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */ 		} 	}@@ -829,6 +769,7 @@ 	/* looks up the object; removes the corresponding bucket */ 	unsigned int h; 	struct ast_hashtab_bucket *b;+	const void *obj2;  	if (!tab || !obj) 		return 0;@@ -836,23 +777,12 @@ 	if (tab->do_locking) 		ast_rwlock_wrlock(&tab->lock); -	h = (*tab->hash)(obj) % tab->hash_tab_size;-	for (b = tab->array[h]; b; b = b->next) {-		const void *obj2;-		-		if (obj == b->object) {-			obj2 = ast_hashtab_remove_object_internal(tab, b, h);-			if (tab->do_locking)-				ast_rwlock_unlock(&tab->lock);--			return (void *) obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */-		}-	}+	obj2 = ast_hashtab_remove_this_object_nolock(tab,obj); 	 	if (tab->do_locking) 		ast_rwlock_unlock(&tab->lock); -	return 0;+	return obj2; }  void *ast_hashtab_remove_this_object_nolock(struct ast_hashtab *tab, void *obj)@@ -873,9 +803,6 @@ 		if (obj == b->object) { 			obj2 = ast_hashtab_remove_object_internal(tab, b, h); 			-			if (tab->do_locking)-				ast_rwlock_unlock(&tab->lock);- 			return (void *) obj2; /* inside this code, the obj's are untouchable, but outside, they aren't */ 		} 	}