[asterisk-commits] murf: branch murf/datastructs r66704 - in /team/murf/datastructs: funcs/ incl...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu May 31 00:05:05 MST 2007


Author: murf
Date: Thu May 31 02:05:04 2007
New Revision: 66704

URL: http://svn.digium.com/view/asterisk?view=rev&rev=66704
Log:
This completes a hashtable implementation. Still have to write a good doc for this, tho. In this package is a generic hash table with locking mechanisms. Also provided is hashtest, a process to thrash a hashtable with multiple threads. It runs each thread thru a random sequence of adds, removes, and lookups for 100K iterations. If the hashtab survives-- doesn't deadlock, crash, or go weird, then the hashtab code is in good shape. I suggest 10 threads for a good pounding. Wrote dialplan code to test all the funcs, and all seem to be working OK.

Added:
    team/murf/datastructs/utils/hashtest.c   (with props)
Modified:
    team/murf/datastructs/funcs/func_hashtab.c
    team/murf/datastructs/include/asterisk/hashtab.h
    team/murf/datastructs/main/hashtab.c
    team/murf/datastructs/utils/Makefile

Modified: team/murf/datastructs/funcs/func_hashtab.c
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/funcs/func_hashtab.c?view=diff&rev=66704&r1=66703&r2=66704
==============================================================================
--- team/murf/datastructs/funcs/func_hashtab.c (original)
+++ team/murf/datastructs/funcs/func_hashtab.c Thu May 31 02:05:04 2007
@@ -189,6 +189,8 @@
 		return -1;
 	}
 
+	ht = (struct ast_hashtab*)strtoul(args.handle, NULL, 10);
+	
 	lookup.key = args.key;
 	lookup.val = 0;
 	entry = ast_hashtab_lookup(ht, &lookup);
@@ -197,12 +199,14 @@
 		if (entry->val)
 			free(entry->val);
 		entry->val = ast_strdup(value);
+		ast_log(LOG_NOTICE,"Set key %s' value to: %s\n", lookup.key, entry->val);
 	} else { /* insert this into the table */
 		entry = ast_calloc(sizeof(struct ht_element),1);
 		entry->val = ast_strdup(value);
 		entry->key = ast_strdup(args.key);
 		
-		ast_hashtab_insert_immediate(ht, entry);
+		if (!ast_hashtab_insert_immediate(ht, entry))
+			ast_log(LOG_NOTICE,"Did NOT add key %s = value %s\n", lookup.key, entry->val);
 	}
 	
 	return 0;
@@ -290,8 +294,7 @@
 "     HASHTAB_SIZE(handle)         -- returns the number of elements stored in the hashtab\n"
 "     HASHTAB_TRAVERSE(handle)     -- returns a hashtab iterator handle\n"
 "A Hashtab iterator can be manipulated with these functions:\n"
-"     HASHTAB_ITERATOR_NEXT(it_handle)  -- returns the first/next element in the hashtab\n"
-	"     HASHTAB_ITERATOR_FREE(it_handle)  -- Please free the iterator when done\n",
+	"     HASHTAB_NEXT(it_handle)  -- returns the first/next element in the hashtab, empty string when done\n",
 	.read = function_hashtab_create
 };
 
@@ -396,7 +399,7 @@
 static int function_hashtab_size(struct ast_channel *chan, const char *cmd,
 								   char *parse, char *buf, size_t len)
 {
-	char *handle;
+	char *handle1;
 	struct ast_hashtab *ht = 0;
 	
 	AST_DECLARE_APP_ARGS(args,
@@ -406,23 +409,23 @@
 	buf[0] = '\0';
 
 	if (ast_strlen_zero(parse)) {
-		ast_log(LOG_WARNING, "HASHTAB_SIZE requires an argument, HASHTAB_SIZE(<handle>)\n");
-		return -1;
-	}
-
-	AST_STANDARD_APP_ARGS(args, parse);
-
-	if (args.argc < 2) {
-		ast_log(LOG_WARNING, "HASHTAB_SIZE requires an argument, HASHTAB_SIZE(<handle>)\n");
+		ast_log(LOG_WARNING, "HASHTAB_SIZE requires an argument(%s), HASHTAB_SIZE(<handle>)\n",parse);
+		return -1;
+	}
+
+	AST_STANDARD_APP_ARGS(args, parse);
+
+	if (args.argc < 1) {
+		ast_log(LOG_WARNING, "HASHTAB_SIZE requires an argument[%s], HASHTAB_SIZE(<handle>)\n",parse);
 		return -1;
 	}
 
 	ht = (struct ast_hashtab*)strtoul(args.handle, NULL, 10);
 	
-	asprintf(&handle, "%lu", (unsigned long)ast_hashtab_size(ht));
-	
-	ast_copy_string(buf, handle, len);
-	free(handle);
+	asprintf(&handle1, "%lu", (unsigned long)ast_hashtab_size(ht));
+	
+	ast_copy_string(buf, handle1, len);
+	free(handle1);
 	
 	return 0;
 }

Modified: team/murf/datastructs/include/asterisk/hashtab.h
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/include/asterisk/hashtab.h?view=diff&rev=66704&r1=66703&r2=66704
==============================================================================
--- team/murf/datastructs/include/asterisk/hashtab.h (original)
+++ team/murf/datastructs/include/asterisk/hashtab.h Thu May 31 02:05:04 2007
@@ -17,7 +17,7 @@
  */
 #ifndef _ASTERISK_HASHTAB_H_
 #define _ASTERISK_HASHTAB_H_
-#define __USE_UNIX98 1 /* what on earth? */
+#define __USE_UNIX98 1          /* to get the MUTEX_RECURSIVE stuff */
 
 /* generic (perhaps overly so) hashtable implementation */
 
@@ -201,6 +201,9 @@
 	/* this function returns the number of elements stored in the hashtab */
 int  ast_hashtab_size( struct ast_hashtab *tab);
 
+	/* this function returns the size of the bucket array in the hashtab */
+int  ast_hashtab_capacity( struct ast_hashtab *tab);
+
 	/* returns an iterator */
 struct ast_hashtab_iter *ast_hashtab_start_traversal(struct ast_hashtab *tab);
 	/* end the traversal, free the iterator, unlock if necc. */

Modified: team/murf/datastructs/main/hashtab.c
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/main/hashtab.c?view=diff&rev=66704&r1=66703&r2=66704
==============================================================================
--- team/murf/datastructs/main/hashtab.c (original)
+++ team/murf/datastructs/main/hashtab.c Thu May 31 02:05:04 2007
@@ -246,22 +246,23 @@
 {
 	/* item had better be in the list! or suffer the weirdness that occurs, later! */
 	if (*head == item) { /* first item in the list */
-		*head = item->next;
-		item->next->prev = NULL;
+		*head = item->tnext;
+		if (item->tnext)
+			item->tnext->tprev = NULL;
 	} else {
 		/* short circuit stuff */
-		item->prev->next = item->next;
-		if (item->next)
-			item->next->prev = item->prev;
+		item->tprev->tnext = item->tnext;
+		if (item->tnext)
+			item->tnext->tprev = item->tprev;
 	}
 }
 
 static void tlist_add_head(struct ast_hashtab_bucket **head, struct ast_hashtab_bucket *item)
 {
 	if (*head) {
-		item->next = *head;
-		item->prev = NULL;
-		(*head)->prev = item;
+		item->tnext = *head;
+		item->tprev = NULL;
+		(*head)->tprev = item;
 		*head = item;
 	} else {
 		/* the list is empty */
@@ -275,10 +276,11 @@
 {
 	/* this func will free the hash table and all its memory. It
 	   doesn't touch the objects stored in it */
-	if (tab->do_locking)
-		ast_rwlock_wrlock(&tab->lock);
 	if (tab) {
 		
+		if (tab->do_locking)
+			ast_rwlock_wrlock(&tab->lock);
+
 		if (tab->array) {
 			/* go thru and destroy the buckets */
 			struct ast_hashtab_bucket *t;
@@ -317,8 +319,14 @@
 	int c;
 	struct ast_hashtab_bucket *b;
 	
-	if (!tab || !obj)
-		return 0;
+	if (!tab) {
+		ast_log(LOG_WARNING,"NULL table pointer given to INSERT.\n");
+		return 0;
+	}
+	if (!obj) {
+		ast_log(LOG_WARNING,"NULL object pointer given to INSERT.\n");
+		return 0;
+	}
 	if (tab->do_locking)
 		ast_rwlock_wrlock(&tab->lock);
 	h = (*tab->hash)(obj, tab->hash_tab_size);
@@ -331,7 +339,8 @@
 	b->object = obj;
 	b->next = tab->array[h];
 	b->prev = NULL;
-	b->next->prev = b;
+	if (b->next)
+		b->next->prev = b;
 	tlist_add_head(&(tab->tlist),b);
 	
 	tab->array[h] = b;
@@ -405,8 +414,8 @@
 	if (tab->do_locking)
 		ast_rwlock_rdlock(&tab->lock);
 	h = (*tab->hash)(obj, tab->hash_tab_size);
-	for(b=tab->array[h]; b; b=b->next) {
-		if( (*tab->compare)(obj,b->object) == 0 ) {
+	for (b=tab->array[h]; b; b=b->next) {
+		if ((*tab->compare)(obj,b->object) == 0) {
 			if (tab->do_locking)
 				ast_rwlock_unlock(&tab->lock);
 			return (void*)b->object; /* I can't touch obj in this func, but the outside world is welcome to */
@@ -429,8 +438,8 @@
 	if (tab->do_locking)
 		ast_rwlock_rdlock(&tab->lock);
 	h = (*tab->hash)(obj, tab->hash_tab_size);
-	for(b=tab->array[h]; b; b=b->next) {
-		if( (*tab->compare)(obj,b->object) == 0 ) {
+	for (b=tab->array[h]; b; b=b->next) {
+		if ((*tab->compare)(obj,b->object) == 0) {
 			if (tab->do_locking)
 				ast_rwlock_unlock(&tab->lock);
 			return (void*)b->object; /* I can't touch obj in this func, but the outside world is welcome to */
@@ -458,6 +467,12 @@
 	/* this function returns the number of elements stored in the hashtab */
 int  ast_hashtab_size( struct ast_hashtab *tab)
 {
+	return tab->hash_tab_elements;
+}
+
+	/* this function returns the size of the bucket array in the hashtab */
+int  ast_hashtab_capacity( struct ast_hashtab *tab)
+{
 	return tab->hash_tab_size;
 }
 
@@ -476,7 +491,7 @@
 	/* Since we keep a DLL of all the buckets in tlist,
 	   all we have to do is free the array, malloc a new one,
 	   and then go thru the tlist array and reassign them into 
-	   the bucket array.
+	   the bucket arrayj.
 	*/
 	for (i=0;i<tab->hash_tab_size;i++) { /* don't absolutely have to do this, but
 											why leave ptrs laying around */
@@ -491,6 +506,7 @@
 
 	for (b=tab->tlist;b;b=bn)
 	{
+		b->prev = 0;
 		bn = b->tnext;
 		h = (*tab->hash)(b->object, tab->hash_tab_size);
 		b->next = tab->array[h];
@@ -504,7 +520,7 @@
 		for (b=tab->array[i]; b; b=b->next) {
 			c++;
 		}
-		if( c > tab->largest_bucket_size )
+		if (c > tab->largest_bucket_size)
 			tab->largest_bucket_size = c;
 	}
 }
@@ -534,9 +550,8 @@
 	
 	if (it && it->next) { /* there's a next in the bucket list */
 		retval = it->next;
-		if (retval)
-			it->next = retval->next;
-		return retval;
+		it->next = retval->tnext;
+		return (void*)retval->object;
 	}
 	return NULL;
 }
@@ -545,16 +560,17 @@
 {
 	/* looks up the object; removes the corresponding bucket */
 	int h;
-	struct ast_hashtab_bucket *b;
+	struct ast_hashtab_bucket *b,*b2;
 
 	if (!tab || !obj)
 		return 0;
 	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)
+	for (b=tab->array[h]; b; b=b->next)
 	{
 		const void *obj2;
+		int c2;
 		
 		if ((*tab->compare)(obj,b->object) == 0) {
 			if (b->prev) {
@@ -567,9 +583,20 @@
 				b->next->prev = b->prev;
 			}
 			
+			tlist_del_item(&(tab->tlist), b);
+
 			obj2 = b->object;
-			b->object = b->next = 0;
+			b->object = b->next = (void*)2;
 			free(b); /* free up the hashbucket */
+			tab->hash_tab_elements--;
+			/* do a little checking */
+			for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
+				c2++;
+			}
+			if (c2 != tab->hash_tab_elements) {
+				printf("Hey! we didn't delete right! there are %d elements in the list, and we expected %d\n",
+					   c2, tab->hash_tab_elements);
+			}
 			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 */
@@ -585,8 +612,8 @@
 	/* looks up the object by hash and then comparing pts in bucket list instead of
 	   calling the compare routine; removes the bucket -- a slightly cheaper operation */
 	/* looks up the object; removes the corresponding bucket */
-	int h;
-	struct ast_hashtab_bucket *b;
+	int h,c2;
+	struct ast_hashtab_bucket *b,*b2;
 
 	if (!tab || !obj)
 		return 0;
@@ -609,10 +636,34 @@
 				b->next->prev = b->prev;
 			}
 			
+			tlist_del_item(&(tab->tlist), b);
 
 			obj2 = b->object;
-			b->object = b->next = 0;
+			b->object = b->next = (void*)1;
 			free(b); /* free up the hashbucket */
+			tab->hash_tab_elements--;
+			/* do a little checking */
+			for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
+				c2++;
+			}
+			if (c2 != tab->hash_tab_elements) {
+				printf("Hey! we didn't delete right! there are %d elements in the list, and we expected %d\n",
+					   c2, tab->hash_tab_elements);
+			}
+			for (c2 = 0, b2 = tab->tlist;b2;b2=b2->tnext) {
+				unsigned int obj3 = (unsigned long)obj2;
+				unsigned int b3 = (unsigned long)b;
+				if (b2->object == obj2)
+					printf("Hey-- you've still got a bucket pointing at ht_element %x\n", obj3);
+				if (b2->next == b)
+					printf("Hey-- you've still got a bucket with next ptr pointing to deleted bucket %x\n", b3);
+				if (b2->prev == b)
+					printf("Hey-- you've still got a bucket with prev ptr pointing to deleted bucket %x\n", b3);
+				if (b2->tprev == b)
+					printf("Hey-- you've still got a bucket with tprev ptr pointing to deleted bucket %x\n", b3);
+				if (b2->tnext == b)
+					printf("Hey-- you've still got a bucket with tnext ptr pointing to deleted bucket %x\n", b3);
+			}
 			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 */

Modified: team/murf/datastructs/utils/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/utils/Makefile?view=diff&rev=66704&r1=66703&r2=66704
==============================================================================
--- team/murf/datastructs/utils/Makefile (original)
+++ team/murf/datastructs/utils/Makefile Thu May 31 02:05:04 2007
@@ -16,7 +16,7 @@
 .PHONY: clean all uninstall
 
 # to get check_expr, add it to the ALL_UTILS list
-ALL_UTILS:=astman smsq stereorize streamplayer aelparse muted check_expr
+ALL_UTILS:=astman smsq stereorize streamplayer aelparse muted check_expr hashtest
 UTILS:=$(ALL_UTILS)
 
 include $(ASTTOPDIR)/Makefile.rules
@@ -108,6 +108,25 @@
 
 aelparse: aelparse.o aelbison.o pbx_ael.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o
 
+hashtab.c : ../main/hashtab.c  ../include/asterisk/hashtab.h
+	cp ../main/hashtab.c .
+
+utils.c : ../main/utils.c
+	cp ../main/utils.c .
+
+sha1.c : ../main/sha1.c
+	cp ../main/sha1.c .
+
+sha1.o : sha1.c
+utils.o : utils.c
+hashtab.o : hashtab.c
+
+hashtest.o : hashtest.c
+	$(CC) -g -c hashtest.c -I/usr/include -I../include
+
+hashtest : hashtest.o md5.o utils.o hashtab.o sha1.o
+	$(CC) -o hashtest hashtest.o hashtab.o utils.o md5.o sha1.o -lpthread
+
 testexpr2s: ../main/ast_expr2f.c ../main/ast_expr2.c ../main/ast_expr2.h
 	$(CC) -g -c -I../include -DSTANDALONE_AEL ../main/ast_expr2f.c -o ast_expr2f.o
 	$(CC) -g -c -I../include -DSTANDALONE_AEL ../main/ast_expr2.c -o ast_expr2.o

Added: team/murf/datastructs/utils/hashtest.c
URL: http://svn.digium.com/view/asterisk/team/murf/datastructs/utils/hashtest.c?view=auto&rev=66704
==============================================================================
--- team/murf/datastructs/utils/hashtest.c (added)
+++ team/murf/datastructs/utils/hashtest.c Thu May 31 02:05:04 2007
@@ -1,0 +1,342 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Steve Murphy
+ *
+ * Steve Murphy <murf at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+/*! \file
+ *
+ *  \brief A program to thoroughly thrash a hash table, testing
+ *         out locking safety, and making sure all functionality
+ *         is functioning. Run with 5 or more threads to get that
+ *         fully intense firestorm of activity. If your
+ *         hash tables don't crash, lock up, or go weird, it must
+ *         be good code! Even features some global counters
+ *         that will get slightly behind because they aren't lock-protected.
+ *
+ *  \author Steve Murphy <murf at digium.com>
+ */
+
+#include "asterisk.h"
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <alloca.h>
+#include <string.h>
+#include <pthread.h>
+#include <sys/stat.h>
+#include <signal.h>
+#include <errno.h>
+#include <unistd.h>
+int testno = 1;
+
+/* stuff we need to make this work with the hashtab stuff */
+
+struct ht_element 
+{
+	char *key;
+	char *val;
+};
+
+static int hashtab_compare_strings_nocase(const void *a, const void *b)
+{
+	const struct ht_element *ae = a, *be = b;
+	return ast_hashtab_compare_strings_nocase(ae->key, be->key);
+}
+
+static int hashtab_compare_strings(const void *a, const void *b)
+{
+	const struct ht_element *ae = a, *be = b;
+	return ast_hashtab_compare_strings(ae->key, be->key);
+}
+
+static int hashtab_hash_string(const void *obj, int modulus)
+{
+	const struct ht_element *o = obj;
+	return ast_hashtab_hash_string(o->key, modulus);
+}
+
+static int hashtab_hash_string_nocase(const void *obj, int modulus)
+{
+	const struct ht_element *o = obj;
+	return ast_hashtab_hash_string_nocase(o->key, modulus);
+}
+
+/* random numbers */
+
+my_rand(int incl_low, int incl_high, unsigned int *seedp)
+{
+	if (incl_high == 0)
+		return 0;
+	
+	return incl_low + (rand_r(seedp) % incl_high);
+}
+
+
+#include "asterisk/lock.h"
+#include "asterisk/hashtab.h"
+#include "asterisk/channel.h"
+#include "asterisk/utils.h"
+#include "asterisk/module.h"
+
+
+/* the testing routines */
+
+static int glob_highwater = 0;
+struct ast_hashtab *glob_hashtab = 0;
+unsigned int glob_seed = 0;
+int els_removed = 0;
+int els_added = 0;
+int els_lookedup = 0;
+int els_found = 0;
+
+/* all the operations to perform on the hashtab */
+
+static void add_element(void)
+{
+	char keybuf[100];
+	struct ht_element *x = malloc(sizeof(struct ht_element));
+	sprintf(keybuf,"key%08d", glob_highwater++);
+	x->key = strdup(keybuf);
+	x->val = strdup("interesting data");
+	ast_hashtab_insert_immediate(glob_hashtab, x);
+	els_added++;
+}
+
+static void * del_element(unsigned int *seedp)
+{
+	char keybuf[100];
+	struct ht_element *el, lookup;
+	int x;
+	
+	/* pick a random element from 0 to highwater-1 */
+	x = my_rand(0,glob_highwater-1,seedp);
+	sprintf(keybuf, "key%08d", x);
+#ifdef DEBUG
+	printf("Removing %s\n", keybuf);
+#endif
+	lookup.key = keybuf;
+	el = ast_hashtab_lookup(glob_hashtab, &lookup);
+	if (el) {
+		if (!ast_hashtab_remove_this_object(glob_hashtab, el)) {
+			printf("Problem: key %s could not be removed from the hashtab\n", keybuf);
+		}
+		else
+			els_removed++;
+	}
+	return el;
+}
+
+static int lookup_element(unsigned int *seedp)
+{
+	char keybuf[100];
+	struct ht_element *el, lookup;
+	int x;
+	
+	/* pick a random element from 0 to highwater-1 */
+	x = my_rand(0,glob_highwater-1,seedp);
+	sprintf(keybuf, "key%08d", x);
+	lookup.key = keybuf;
+	el = ast_hashtab_lookup(glob_hashtab, &lookup);
+	els_lookedup++;
+	if (el)
+		els_found++;
+	if (el)
+		return 1;
+	return 0;
+}
+
+
+static void *hashtest(void *data)
+{
+	int my_els_removed = 0;
+	int my_els_added = 0;
+	int my_els_lookedup = 0;
+	int my_els_found = 0;
+	int my_testno = testno++;
+	
+	/* data will be a random number == use as a seed for random numbers */
+	unsigned long seed = (unsigned long)data;
+	printf("hashtest thread created... test beginning\n");
+	
+	/* main test routine-- a global hashtab exists, pound it like crazy  */
+	int its;
+	for(its=0;its<100000;its++)
+	{
+		void *seed2 = &seed;
+		int op = my_rand(0,100, seed2);
+		if (op<70) {
+			my_els_lookedup++;
+#ifdef DEBUG
+			printf("%d[%d]: LOOKUP\n", my_testno, its);
+#endif			
+			if ((my_els_lookedup%100)==0) {
+				printf(".");
+				fflush(stdout);
+			}
+			if (lookup_element(seed2))
+				my_els_found++;
+		} else if (op < 80) {
+#ifdef DEBUG
+			printf("%d[%d]: REMOVE\n", my_testno, its);
+#endif
+			if (del_element(seed2))
+				my_els_removed++;
+		} else {
+			my_els_added++;
+#ifdef DEBUG
+			printf("%d[%d]: ADD\n", my_testno, its);
+#endif
+			add_element();
+		}
+	}
+	printf("\nhashtest thread %d exiting.... lookups=%d/%d, added=%d, removed=%d;\n",
+		   my_testno, my_els_found, my_els_lookedup, my_els_added, my_els_removed);
+	printf("\ntotals..................... lookups=%d/%d, added=%d, removed=%d;\n",
+		   els_found, els_lookedup, els_added, els_removed);
+	pthread_exit(0);
+}
+
+void run_hashtest(int numthr)
+{
+	pthread_t thr[numthr];
+	void *thrres[numthr];
+	int i;
+	
+	/* init a single global hashtab, then... */
+	glob_hashtab = ast_hashtab_create(100, hashtab_compare_strings_nocase, ast_hashtab_resize_java, ast_hashtab_newsize_java, hashtab_hash_string_nocase, 1);
+
+	/* set a random seed  */
+	glob_seed = (unsigned int)time(0);
+	srand(glob_seed);
+	
+	/* create threads, each running hashtest */
+	for(i=0;i<numthr;i++)
+	{
+		unsigned long z = rand();
+		
+		printf("starting hashtest thread %d....\n",i+1);
+		if (ast_pthread_create(&thr[i], NULL, hashtest, (void*)z)) {
+			printf("Sorry, couldn't create thread #%d\n", i+1);
+		}
+		printf("hashtest thread spawned.... \n");
+	}
+	/* collect threads, each running hashtest */
+	for(i=0;i<numthr;i++)
+	{
+		printf("waiting for thread %d....\n", i+1);
+		if (pthread_join(thr[i], &thrres[i])) {
+			printf("Sorry, couldn't join thread #%d\n", i+1);
+		}
+		printf("hashtest thread %d done.... \n",i+1);
+	}
+	/* user has to kill/intr the process to stop the test? */
+}
+
+
+int main(int argc,char **argv)
+{
+	if (argc < 2 || argc > 2 || atoi(argv[1]) < 1)
+	{
+		printf("Usage: hashtest <number of threads>\n");
+		exit(1);
+	}
+	
+	/* one arg == number of threads to create */
+	run_hashtest(atoi(argv[1]));
+	
+	return 0;
+}
+
+
+struct ast_app *pbx_findapp(const char *app)
+{
+	return (struct ast_app*)1; /* so as not to trigger an error */
+}
+
+int  ast_add_profile(const char *x, uint64_t scale)
+{
+}
+
+int ast_loader_register(int (*updater)(void))
+{
+	return 1;
+}
+
+int ast_loader_unregister(int (*updater)(void))
+{
+	return 1;
+}
+void ast_module_register(const struct ast_module_info *x)
+{
+}
+
+void ast_module_unregister(const struct ast_module_info *x)
+{
+}
+
+
+void ast_cli_register_multiple(void)
+{
+}
+
+void ast_register_file_version(const char *file, const char *version)
+{
+}
+
+void ast_unregister_file_version(const char *file)
+{
+
+}
+
+void ast_cli_unregister_multiple(void)
+{
+}
+
+void ast_context_destroy(void)
+{
+}
+
+void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
+{
+	va_list vars;
+	va_start(vars,fmt);
+	printf("LOG: lev:%d file:%s  line:%d func: %s  ",
+		   level, file, line, function);
+	vprintf(fmt, vars);
+	fflush(stdout);
+	va_end(vars);
+}
+
+void ast_verbose(const char *fmt, ...)
+{
+        va_list vars;
+        va_start(vars,fmt);
+
+        printf("VERBOSE: ");
+        vprintf(fmt, vars);
+        fflush(stdout);
+        va_end(vars);
+}
+
+void ast_register_thread(char *name)
+{
+
+}
+
+void ast_unregister_thread(void *id)
+{
+}

Propchange: team/murf/datastructs/utils/hashtest.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/datastructs/utils/hashtest.c
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/datastructs/utils/hashtest.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



More information about the asterisk-commits mailing list