[asterisk-commits] mmichelson: branch 1.6.1 r156894 - in /branches/1.6.1: apps/ include/asterisk/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Nov 14 10:57:05 CST 2008


Author: mmichelson
Date: Fri Nov 14 10:57:04 2008
New Revision: 156894

URL: http://svn.digium.com/view/asterisk?view=rev&rev=156894
Log:
This is the 1.6.1 version of trunk commit 156883.
It is functionally equivalent to the 1.6.0 commit


Modified:
    branches/1.6.1/apps/app_queue.c
    branches/1.6.1/include/asterisk/strings.h

Modified: branches/1.6.1/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/apps/app_queue.c?view=diff&rev=156894&r1=156893&r2=156894
==============================================================================
--- branches/1.6.1/apps/app_queue.c (original)
+++ branches/1.6.1/apps/app_queue.c Fri Nov 14 10:57:04 2008
@@ -67,6 +67,7 @@
 #include <sys/time.h>
 #include <sys/signal.h>
 #include <netinet/in.h>
+#include <ctype.h>
 
 #include "asterisk/lock.h"
 #include "asterisk/file.h"
@@ -589,7 +590,8 @@
 static int queue_hash_cb(const void *obj, const int flags)
 {
 	const struct call_queue *q = obj;
-	return ast_str_hash(q->name);
+
+	return ast_str_case_hash(q->name);
 }
 
 static int queue_cmp_cb(void *obj, void *arg, int flags)
@@ -1483,7 +1485,6 @@
 			/* Delete if unused (else will be deleted when last caller leaves). */
 			ao2_unlink(queues, q);
 			ao2_unlock(q);
-			queue_unref(q);
 		}
 		return NULL;
 	}
@@ -2019,8 +2020,6 @@
 	if (q->dead) {	
 		/* It's dead and nobody is in it, so kill it */
 		ao2_unlink(queues, q);
-		/* unref the container's reference to the queue */
-		queue_unref(q);
 	}
 	/* unref the explicit ref earlier in the function */
 	queue_unref(q);
@@ -2075,11 +2074,10 @@
 			}
 		}
 		ao2_unlock(q);
+		queue_unref(q);
 		if (found) {
-			queue_unref(q);
 			break;
 		}
-		queue_unref(q);
 	}
 	return found;
 }
@@ -4043,6 +4041,8 @@
 			if (!mem->dynamic) {
 				ao2_ref(mem, -1);
 				ao2_unlock(q);
+				queue_unref(q);
+				ao2_unlock(queues);
 				return RES_NOT_DYNAMIC;
 			}
 			q->membercount--;
@@ -5619,13 +5619,15 @@
 		}
 	}
 
-	queue_iter = ao2_iterator_init(queues, 0);
+	queue_iter = ao2_iterator_init(queues, F_AO2I_DONTLOCK);
+	ao2_lock(queues);
 	while ((q = ao2_iterator_next(&queue_iter))) {
 		float sl;
 
 		ao2_lock(q);
 		if (argc == 3 && strcasecmp(q->name, argv[2])) {
 			ao2_unlock(q);
+			queue_unref(q);
 			continue;
 		}
 		found = 1;
@@ -5696,6 +5698,7 @@
 		}
 		queue_unref(q); /* Unref the iterator's reference */
 	}
+	ao2_unlock(queues);
 	if (!found) {
 		if (argc == 3)
 			ast_str_set(&out, 0, "No such queue: %s.", argv[2]);

Modified: branches/1.6.1/include/asterisk/strings.h
URL: http://svn.digium.com/view/asterisk/branches/1.6.1/include/asterisk/strings.h?view=diff&rev=156894&r1=156893&r2=156894
==============================================================================
--- branches/1.6.1/include/asterisk/strings.h (original)
+++ branches/1.6.1/include/asterisk/strings.h Fri Nov 14 10:57:04 2008
@@ -22,6 +22,8 @@
 
 #ifndef _ASTERISK_STRINGS_H
 #define _ASTERISK_STRINGS_H
+
+#include <ctype.h>
 
 #include "asterisk/inline_api.h"
 #include "asterisk/utils.h"
@@ -723,4 +725,21 @@
 	return abs(hash);
 }
 
+/*!
+ * \brief Compute a hash value on a case-insensitive string
+ *
+ * Uses the same hash algorithm as ast_str_hash, but converts
+ * all characters to lowercase prior to computing a hash. This
+ * allows for easy case-insensitive lookups in a hash table.
+ */
+static force_inline int ast_str_case_hash(const char *str)
+{
+	int hash = 5381;
+
+	while (*str) {
+		hash = hash * 33 ^ tolower(*str++);
+	}
+
+	return abs(hash);
+}
 #endif /* _ASTERISK_STRINGS_H */




More information about the asterisk-commits mailing list