channels: Return allocated channels locked.

This change makes ast_channel_alloc return allocated channels
locked. By doing so no other thread can acquire, lock, and manipulate
the channel before it is completely set up.

(closes issue AST-1256)

Review: https://reviewboard.asterisk.org/r/3067/
........

Merged revisions 404204 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404210 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2013-12-18 19:28:05 +00:00
parent e23b8d19a4
commit e2630fcd51
38 changed files with 187 additions and 70 deletions

View File

@@ -73,6 +73,7 @@ AST_TEST_DEFINE(channel_blob_create)
type = stasis_message_type_create("test-type", NULL);
chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, 0, "TEST/Alice");
ast_channel_unlock(chan);
json = ast_json_pack("{s: s}",
"foo", "bar");
@@ -125,6 +126,7 @@ AST_TEST_DEFINE(null_blob)
type = stasis_message_type_create("test-type", NULL);
chan = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, 0, "TEST/Alice");
ast_channel_unlock(chan);
json = ast_json_pack("{s: s}",
"foo", "bar");
@@ -192,8 +194,11 @@ AST_TEST_DEFINE(multi_channel_blob_snapshots)
json = ast_json_pack("{s: s}",
"type", "test");
chan_alice = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, 0, "TEST/Alice");
ast_channel_unlock(chan_alice);
chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, 0, "TEST/Bob");
ast_channel_unlock(chan_bob);
chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Bob", "300", "300", "default", NULL, 0, "TEST/Charlie");
ast_channel_unlock(chan_charlie);
blob = ast_multi_channel_blob_create(json);
ast_multi_channel_blob_add_channel(blob, "Caller", ast_channel_snapshot_create(chan_alice));
@@ -251,6 +256,7 @@ AST_TEST_DEFINE(channel_snapshot_json)
ast_test_validate(test, NULL == ast_channel_snapshot_to_json(NULL, NULL));
chan = ast_channel_alloc(0, AST_STATE_DOWN, "cid_num", "cid_name", "acctcode", "exten", "context", NULL, 0, "TEST/name");
ast_channel_unlock(chan);
ast_test_validate(test, NULL != chan);
snapshot = ast_channel_snapshot_create(chan);
ast_test_validate(test, NULL != snapshot);