diff options
author | Jonathan Rose <jrose@digium.com> | 2012-09-11 22:40:02 +0000 |
---|---|---|
committer | Jonathan Rose <jrose@digium.com> | 2012-09-11 22:40:02 +0000 |
commit | 6f8bad0eace50f04f41e6db2d6a7d4de6dcdce6d (patch) | |
tree | 3cdf4e5bc831e2d9b0f854ab7226188b27c8f5a2 /channels/chan_local.c | |
parent | 8963829390ca45b269c99144b1ffb96d17d9a3d3 (diff) |
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.
(issue ASTERISK-20318)
Reported by: Dan Cropp
Review: https://reviewboard.asterisk.org/r/2104/
........
Merged revisions 372902 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 372916 from http://svn.asterisk.org/svn/asterisk/branches/10
........
Merged revisions 372917 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@372918 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_local.c')
-rw-r--r-- | channels/chan_local.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/channels/chan_local.c b/channels/chan_local.c index 20e46c9aa..c9740cd27 100644 --- a/channels/chan_local.c +++ b/channels/chan_local.c @@ -85,6 +85,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, .max_size = -1, @@ -1195,8 +1197,8 @@ static struct local_pvt *local_alloc(const char *data, struct ast_format_cap *ca static struct ast_channel *local_new(struct local_pvt *p, int state, const char *linkedid, struct ast_callid *callid) { struct ast_channel *tmp = NULL, *tmp2 = NULL; - int randnum = ast_random() & 0xffff; struct ast_format fmt; + int generated_seqno = ast_atomic_fetchadd_int((int *)&name_sequence, +1); const char *t; int ama; @@ -1214,8 +1216,8 @@ static struct ast_channel *local_new(struct local_pvt *p, int state, const char /* 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, ast_channel_linkedid(tmp), 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, ast_channel_linkedid(tmp), ama, "Local/%s@%s-%08x;2", p->exten, p->context, generated_seqno))) { if (tmp) { tmp = ast_channel_release(tmp); } |