[asterisk-commits] jrose: branch 1.8 r372902 - /branches/1.8/channels/chan_local.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 11 17:12:01 CDT 2012


Author: jrose
Date: Tue Sep 11 17:11:58 2012
New Revision: 372902

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=372902
Log:
chan_local: Switch from using a random 4 digit hex identifier to unique id

Changes chan_local channels to use an 8 digit hex identifier generated
atomically and sequentially in order to eliminate the chance of having
multiple channels with the same name during high call volume situations.

(closes issue ASTERISK-20318)
Reported by: Dan Cropp
Review: https://reviewboard.asterisk.org/r/2104/

Modified:
    branches/1.8/channels/chan_local.c

Modified: branches/1.8/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_local.c?view=diff&rev=372902&r1=372901&r2=372902
==============================================================================
--- branches/1.8/channels/chan_local.c (original)
+++ branches/1.8/channels/chan_local.c Tue Sep 11 17:11:58 2012
@@ -83,6 +83,8 @@
 static const int BUCKET_SIZE = 1;
 
 static struct ao2_container *locals;
+
+static unsigned int name_sequence = 0;
 
 static struct ast_jb_conf g_jb_conf = {
 	.flags = 0,
@@ -1150,7 +1152,8 @@
 static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid)
 {
 	struct ast_channel *tmp = NULL, *tmp2 = NULL;
-	int randnum = ast_random() & 0xffff, fmt = 0;
+	int fmt = 0;
+	int generated_seqno = ast_atomic_fetchadd_int((int *)&name_sequence, +1);
 	const char *t;
 	int ama;
 
@@ -1168,8 +1171,8 @@
 
 	/* Make sure that the ;2 channel gets the same linkedid as ;1. You can't pass linkedid to both
 	 * allocations since if linkedid isn't set, then each channel will generate its own linkedid. */
-	if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, linkedid, ama, "Local/%s@%s-%04x;1", p->exten, p->context, randnum)) 
-		|| !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, tmp->linkedid, ama, "Local/%s@%s-%04x;2", p->exten, p->context, randnum))) {
+	if (!(tmp = ast_channel_alloc(1, state, 0, 0, t, p->exten, p->context, linkedid, ama, "Local/%s@%s-%08x;1", p->exten, p->context, generated_seqno))
+		|| !(tmp2 = ast_channel_alloc(1, AST_STATE_RING, 0, 0, t, p->exten, p->context, tmp->linkedid, ama, "Local/%s@%s-%08x;2", p->exten, p->context, generated_seqno))) {
 		if (tmp) {
 			tmp = ast_channel_release(tmp);
 		}




More information about the asterisk-commits mailing list