[asterisk-commits] kharwell: branch 12 r404237 - in /branches/12: addons/ apps/ channels/ funcs/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Dec 18 14:25:53 CST 2013


Author: kharwell
Date: Wed Dec 18 14:25:39 2013
New Revision: 404237

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404237
Log:
channel locking: Add locking for channel snapshot creation

Original commit message by mmichelson (asterisk 12 r403311):

"This adds channel locks around calls to create channel snapshots as well
as other functions which operate on a channel and then end up
creating a channel snapshot. Functions that expect the channel to be
locked prior to being called have had their documentation updated to
indicate such."

The above was initially committed and then reverted at r403398.  The problem
was found to be in core_local.c in the publish_local_bridge_message function.
The ast_unreal_lock_all function locks and adds a reference to the returned
channels and while they were being unlocked they were not being unreffed when
no longer needed.  Fixed by unreffing the channels.

Also in bridge.c a lock was obtained on "other->chan", but then an attempt was
made to unlock "other" and not the previously locked channel.  Fixed by
unlocking "other->chan"

(closes issue ASTERISK-22709)
Reported by: John Bigelow





Modified:
    branches/12/addons/chan_mobile.c
    branches/12/addons/chan_ooh323.c
    branches/12/apps/app_agent_pool.c
    branches/12/apps/app_confbridge.c
    branches/12/apps/app_dial.c
    branches/12/apps/app_disa.c
    branches/12/apps/app_meetme.c
    branches/12/apps/app_queue.c
    branches/12/apps/app_userevent.c
    branches/12/apps/app_voicemail.c
    branches/12/channels/chan_alsa.c
    branches/12/channels/chan_console.c
    branches/12/channels/chan_dahdi.c
    branches/12/channels/chan_gtalk.c
    branches/12/channels/chan_iax2.c
    branches/12/channels/chan_jingle.c
    branches/12/channels/chan_mgcp.c
    branches/12/channels/chan_misdn.c
    branches/12/channels/chan_motif.c
    branches/12/channels/chan_oss.c
    branches/12/channels/chan_phone.c
    branches/12/channels/chan_pjsip.c
    branches/12/channels/chan_skinny.c
    branches/12/channels/chan_unistim.c
    branches/12/channels/chan_vpb.cc
    branches/12/channels/sig_analog.c
    branches/12/channels/sig_pri.c
    branches/12/funcs/func_timeout.c
    branches/12/include/asterisk/aoc.h
    branches/12/include/asterisk/channel.h
    branches/12/include/asterisk/channelstate.h
    branches/12/include/asterisk/stasis_bridges.h
    branches/12/include/asterisk/stasis_channels.h
    branches/12/main/bridge.c
    branches/12/main/bridge_channel.c
    branches/12/main/cel.c
    branches/12/main/channel.c
    branches/12/main/core_local.c
    branches/12/main/dial.c
    branches/12/main/endpoints.c
    branches/12/main/pbx.c
    branches/12/main/pickup.c
    branches/12/main/stasis_bridges.c
    branches/12/main/stasis_channels.c
    branches/12/pbx/pbx_realtime.c
    branches/12/res/parking/parking_bridge_features.c
    branches/12/res/parking/parking_manager.c
    branches/12/res/res_agi.c
    branches/12/res/res_pjsip_refer.c
    branches/12/res/res_stasis.c
    branches/12/tests/test_cdr.c
    branches/12/tests/test_cel.c
    branches/12/tests/test_stasis_channels.c

Modified: branches/12/addons/chan_mobile.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/addons/chan_mobile.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/addons/chan_mobile.c (original)
+++ branches/12/addons/chan_mobile.c Wed Dec 18 14:25:39 2013
@@ -878,7 +878,6 @@
 	if (pvt->sco_socket != -1) {
 		ast_channel_set_fd(chn, 0, pvt->sco_socket);
 	}
-
 	ast_channel_unlock(chn);
 
 	return chn;

Modified: branches/12/addons/chan_ooh323.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/addons/chan_ooh323.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/addons/chan_ooh323.c (original)
+++ branches/12/addons/chan_ooh323.c Wed Dec 18 14:25:39 2013
@@ -2152,8 +2152,8 @@
 			}
 
 			ast_queue_control(c, AST_CONTROL_ANSWER);
-   			ast_channel_unlock(p->owner);
 			ast_publish_channel_state(c);
+			ast_channel_unlock(p->owner);
 		}
 		ast_mutex_unlock(&p->lock);
 

Modified: branches/12/apps/app_agent_pool.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_agent_pool.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_agent_pool.c (original)
+++ branches/12/apps/app_agent_pool.c Wed Dec 18 14:25:39 2013
@@ -1465,7 +1465,9 @@
 		ast_bridge_destroy(caller_bridge, AST_CAUSE_USER_BUSY);
 	}
 
+	ast_channel_lock(logged);
 	send_agent_logoff(logged, agent->username, time_logged_in);
+	ast_channel_unlock(logged);
 	ast_verb(2, "Agent '%s' logged out.  Logged in for %ld seconds.\n",
 		agent->username, time_logged_in);
 	ast_channel_unref(logged);
@@ -2046,7 +2048,9 @@
 	ast_verb(2, "Agent '%s' logged in (format %s/%s)\n", agent->username,
 		ast_getformatname(ast_channel_readformat(chan)),
 		ast_getformatname(ast_channel_writeformat(chan)));
+	ast_channel_lock(chan);
 	send_agent_login(chan, agent->username);
+	ast_channel_unlock(chan);
 
 	agent_run(agent, chan);
 	return -1;

Modified: branches/12/apps/app_confbridge.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_confbridge.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_confbridge.c (original)
+++ branches/12/apps/app_confbridge.c Wed Dec 18 14:25:39 2013
@@ -1365,7 +1365,9 @@
 	}
 
 	/* To make sure playback_chan has the same language of that profile */
+	ast_channel_lock(conference->playback_chan);
 	ast_channel_language_set(conference->playback_chan, conference->b_profile.language);
+	ast_channel_unlock(conference->playback_chan);
 
 	ast_debug(1, "Created announcer channel '%s' to conference bridge '%s'\n",
 		ast_channel_name(conference->playback_chan), conference->name);

Modified: branches/12/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_dial.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_dial.c (original)
+++ branches/12/apps/app_dial.c Wed Dec 18 14:25:39 2013
@@ -2098,6 +2098,7 @@
 	struct ast_party_caller caller;
 
 	/* Reset all DIAL variables back to blank, to prevent confusion (in case we don't reset all of them). */
+	ast_channel_lock(chan);
 	ast_channel_stage_snapshot(chan);
 	pbx_builtin_setvar_helper(chan, "DIALSTATUS", "");
 	pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", "");
@@ -2105,6 +2106,7 @@
 	pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", "");
 	pbx_builtin_setvar_helper(chan, "DIALEDTIME", "");
 	ast_channel_stage_snapshot_done(chan);
+	ast_channel_unlock(chan);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "Dial requires an argument (technology/resource)\n");
@@ -2436,15 +2438,17 @@
 			continue;
 		}
 
+		ast_channel_lock(tc);
 		ast_channel_stage_snapshot(tc);
+		ast_channel_unlock(tc);
 
 		ast_channel_get_device_name(tc, device_name, sizeof(device_name));
 		if (!ignore_cc) {
 			ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name);
 		}
+
+		ast_channel_lock_both(tc, chan);
 		pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number);
-
-		ast_channel_lock_both(tc, chan);
 
 		/* Setup outgoing SDP to match incoming one */
 		if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) {
@@ -2717,8 +2721,10 @@
 			number = ast_strdupa(number);
 		}
 		ast_channel_unlock(peer);
+		ast_channel_lock(chan);
 		pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number);
 		ast_channel_stage_snapshot_done(chan);
+		ast_channel_unlock(chan);
 
 		if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) {
 			ast_debug(1, "app_dial: sendurl=%s.\n", args.url);
@@ -2804,16 +2810,18 @@
 			/* chan and peer are going into the PBX; as such neither are considered
 			 * outgoing channels any longer */
 			ast_clear_flag(ast_channel_flags(chan), AST_FLAG_OUTGOING);
-			ast_channel_stage_snapshot(peer);
-			ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
 
 			ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]);
 			ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]);
 			/* peer goes to the same context and extension as chan, so just copy info from chan*/
+			ast_channel_lock(peer);
+			ast_channel_stage_snapshot(peer);
+			ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING);
 			ast_channel_context_set(peer, ast_channel_context(chan));
 			ast_channel_exten_set(peer, ast_channel_exten(chan));
 			ast_channel_priority_set(peer, ast_channel_priority(chan) + 2);
 			ast_channel_stage_snapshot_done(peer);
+			ast_channel_unlock(peer);
 			if (ast_pbx_start(peer)) {
 				ast_autoservice_chan_hangup_peer(chan, peer);
 			}
@@ -2963,7 +2971,9 @@
 		if (!res) {
 			if (!ast_tvzero(calldurationlimit)) {
 				struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit);
+				ast_channel_lock(peer);
 				ast_channel_whentohangup_set(peer, &whentohangup);
+				ast_channel_unlock(peer);
 			}
 			if (!ast_strlen_zero(dtmfcalled)) {
 				ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled);

Modified: branches/12/apps/app_disa.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_disa.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_disa.c (original)
+++ branches/12/apps/app_disa.c Wed Dec 18 14:25:39 2013
@@ -381,8 +381,11 @@
 				ast_set_callerid(chan, ourcidnum, ourcidname, ourcidnum);
 			}
 
-			if (!ast_strlen_zero(acctcode))
+			if (!ast_strlen_zero(acctcode)) {
+				ast_channel_lock(chan);
 				ast_channel_accountcode_set(chan, acctcode);
+				ast_channel_unlock(chan);
+			}
 
 			if (special_noanswer) {
 				ast_clear_flag(&cdr_flags, AST_CDR_FLAG_DISABLE);

Modified: branches/12/apps/app_meetme.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_meetme.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_meetme.c (original)
+++ branches/12/apps/app_meetme.c Wed Dec 18 14:25:39 2013
@@ -1384,7 +1384,9 @@
 		}
 	}
 
+	ast_channel_lock(chan);
 	msg = ast_channel_blob_create(chan, message_type, json_object);
+	ast_channel_unlock(chan);
 
 	if (!msg) {
 		return;

Modified: branches/12/apps/app_queue.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_queue.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_queue.c (original)
+++ branches/12/apps/app_queue.c Wed Dec 18 14:25:39 2013
@@ -2040,8 +2040,12 @@
 	RAII_VAR(struct ast_channel_snapshot *, caller_snapshot, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_channel_snapshot *, agent_snapshot, NULL, ao2_cleanup);
 
+	ast_channel_lock(caller);
 	caller_snapshot = ast_channel_snapshot_create(caller);
+	ast_channel_unlock(caller);
+	ast_channel_lock(agent);
 	agent_snapshot = ast_channel_snapshot_create(agent);
+	ast_channel_unlock(agent);
 
 	if (!caller_snapshot || !agent_snapshot) {
 		return;
@@ -3452,7 +3456,9 @@
 				     "Queue", q->name,
 				     "Position", qe->pos,
 				     "Count", q->count);
+		ast_channel_lock(qe->chan);
 		ast_channel_publish_blob(qe->chan, queue_caller_join_type(), blob);
+		ast_channel_unlock(qe->chan);
 		ast_debug(1, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, ast_channel_name(qe->chan), qe->pos );
 	}
 	ao2_unlock(q);
@@ -3731,7 +3737,9 @@
 					     "Queue", q->name,
 					     "Position", qe->pos,
 					     "Count", q->count);
+			ast_channel_lock(qe->chan);
 			ast_channel_publish_blob(qe->chan, queue_caller_leave_type(), blob);
+			ast_channel_unlock(qe->chan);
 			ast_debug(1, "Queue '%s' Leave, Channel '%s'\n", q->name, ast_channel_name(qe->chan));
 			/* Take us out of the queue */
 			if (prev) {
@@ -4329,10 +4337,13 @@
 			     "Position", qe->pos,
 			     "OriginalPosition", qe->opos,
 			     "HoldTime", (int)(time(NULL) - qe->start));
-	ast_channel_publish_blob(qe->chan, queue_caller_abandon_type(), blob);
 
 	qe->parent->callsabandoned++;
 	ao2_unlock(qe->parent);
+
+	ast_channel_lock(qe->chan);
+	ast_channel_publish_blob(qe->chan, queue_caller_abandon_type(), blob);
+	ast_channel_unlock(qe->chan);
 }
 
 /*! \brief RNA == Ring No Answer. Common code that is executed when we try a queue member and they don't answer. */

Modified: branches/12/apps/app_userevent.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_userevent.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_userevent.c (original)
+++ branches/12/apps/app_userevent.c Wed Dec 18 14:25:39 2013
@@ -114,7 +114,9 @@
 		}
 	}
 
+	ast_channel_lock(chan);
 	ast_channel_publish_blob(chan, ast_channel_user_event_type(), blob);
+	ast_channel_unlock(chan);
 	return 0;
 }
 

Modified: branches/12/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/apps/app_voicemail.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/apps/app_voicemail.c (original)
+++ branches/12/apps/app_voicemail.c Wed Dec 18 14:25:39 2013
@@ -10958,8 +10958,11 @@
 #endif
 
 	/* Set language from config to override channel language */
-	if (!ast_strlen_zero(vmu->language))
+	if (!ast_strlen_zero(vmu->language)) {
+		ast_channel_lock(chan);
 		ast_channel_language_set(chan, vmu->language);
+		ast_channel_unlock(chan);
+	}
 
 	/* Retrieve urgent, old and new message counts */
 	ast_debug(1, "Before open_mailbox\n");

Modified: branches/12/channels/chan_alsa.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_alsa.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_alsa.c (original)
+++ branches/12/channels/chan_alsa.c Wed Dec 18 14:25:39 2013
@@ -601,7 +601,6 @@
 	ast_jb_configure(tmp, &global_jbconf);
 
 	ast_channel_stage_snapshot_done(tmp);
-
 	ast_channel_unlock(tmp);
 
 	if (state != AST_STATE_DOWN) {

Modified: branches/12/channels/chan_console.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_console.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_console.c (original)
+++ branches/12/channels/chan_console.c Wed Dec 18 14:25:39 2013
@@ -444,7 +444,6 @@
 	ast_jb_configure(chan, &global_jbconf);
 
 	ast_channel_stage_snapshot_done(chan);
-
 	ast_channel_unlock(chan);
 
 	if (state != AST_STATE_DOWN) {

Modified: branches/12/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_dahdi.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_dahdi.c (original)
+++ branches/12/channels/chan_dahdi.c Wed Dec 18 14:25:39 2013
@@ -1667,7 +1667,9 @@
 		return;
 	}
 
+	ast_channel_lock(chan);
 	ast_channel_publish_blob(chan, dahdichannel_type(), blob);
+	ast_channel_unlock(chan);
 }
 
 /*!
@@ -9607,6 +9609,7 @@
 						getforward = 0;
 					} else {
 						res = tone_zone_play_tone(p->subs[idx].dfd, -1);
+						ast_channel_lock(chan);
 						ast_channel_exten_set(chan, exten);
 						if (!ast_strlen_zero(p->cid_num)) {
 							if (!p->hidecallerid)
@@ -9619,6 +9622,7 @@
 								ast_set_callerid(chan, NULL, p->cid_name, NULL);
 						}
 						ast_setstate(chan, AST_STATE_RING);
+						ast_channel_unlock(chan);
 						dahdi_ec_enable(p);
 						res = ast_pbx_run(chan);
 						if (res) {
@@ -10382,8 +10386,10 @@
 
 		my_handle_notify_message(chan, p, flags, -1);
 
+		ast_channel_lock(chan);
 		ast_setstate(chan, AST_STATE_RING);
 		ast_channel_rings_set(chan, 1);
+		ast_channel_unlock(chan);
 		p->ringt = p->ringt_base;
 		res = ast_pbx_run(chan);
 		if (res) {

Modified: branches/12/channels/chan_gtalk.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_gtalk.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_gtalk.c (original)
+++ branches/12/channels/chan_gtalk.c Wed Dec 18 14:25:39 2013
@@ -1226,7 +1226,6 @@
 		ast_jb_configure(tmp, &global_jbconf);
 
 	ast_channel_stage_snapshot_done(tmp);
-
 	ast_channel_unlock(tmp);
 
 	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
@@ -1421,7 +1420,9 @@
 	ast_format_cap_joint_copy(p->cap, p->peercap, p->jointcap);
 	ast_mutex_unlock(&p->lock);
 
+	ast_channel_lock(chan);
 	ast_setstate(chan, AST_STATE_RING);
+	ast_channel_unlock(chan);
 	if (ast_format_cap_is_empty(p->jointcap)) {
 		ast_log(LOG_WARNING, "Capabilities don't match : us - %s, peer - %s, combined - %s \n", ast_getformatname_multiple(s1, BUFSIZ, p->cap),
 			ast_getformatname_multiple(s2, BUFSIZ, p->peercap),

Modified: branches/12/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_iax2.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_iax2.c (original)
+++ branches/12/channels/chan_iax2.c Wed Dec 18 14:25:39 2013
@@ -5804,7 +5804,6 @@
 	}
 
 	ast_channel_stage_snapshot_done(tmp);
-
 	ast_channel_unlock(tmp);
 
 	if (state != AST_STATE_DOWN) {
@@ -12237,7 +12236,9 @@
 	if (c) {
 		struct ast_format_cap *joint;
 		if (callid) {
+			ast_channel_lock(c);
 			ast_channel_callid_set(c, callid);
+			ast_channel_unlock(c);
 		}
 
 		/* Choose a format we can live with */

Modified: branches/12/channels/chan_jingle.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_jingle.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_jingle.c (original)
+++ branches/12/channels/chan_jingle.c Wed Dec 18 14:25:39 2013
@@ -941,7 +941,6 @@
 		ast_jb_configure(tmp, &global_jbconf);
 
 	ast_channel_stage_snapshot_done(tmp);
-
 	ast_channel_unlock(tmp);
 
 	if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
@@ -1117,7 +1116,9 @@
 	}
 
 	ast_mutex_unlock(&p->lock);
+	ast_channel_lock(chan);
 	ast_setstate(chan, AST_STATE_RING);
+	ast_channel_unlock(chan);
 	res = ast_pbx_start(chan);
 	
 	switch (res) {

Modified: branches/12/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_mgcp.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_mgcp.c (original)
+++ branches/12/channels/chan_mgcp.c Wed Dec 18 14:25:39 2013
@@ -1570,7 +1570,6 @@
 		}
 
 		ast_channel_stage_snapshot_done(tmp);
-
 		ast_channel_unlock(tmp);
 
 		if (state != AST_STATE_DOWN) {
@@ -3048,6 +3047,7 @@
 				} else {
 					/*res = tone_zone_play_tone(p->subs[index].zfd, -1);*/
 					ast_indicate(chan, -1);
+					ast_channel_lock(chan);
 					ast_channel_exten_set(chan, p->dtmf_buf);
 					ast_channel_dialed(chan)->number.str = ast_strdup(p->dtmf_buf);
 					memset(p->dtmf_buf, 0, sizeof(p->dtmf_buf));
@@ -3056,6 +3056,7 @@
 						p->hidecallerid ? "" : p->cid_name,
 						ast_channel_caller(chan)->ani.number.valid ? NULL : p->cid_num);
 					ast_setstate(chan, AST_STATE_RING);
+					ast_channel_unlock(chan);
 					if (p->dtmfmode & MGCP_DTMF_HYBRID) {
 						p->dtmfmode |= MGCP_DTMF_INBAND;
 						ast_indicate(chan, -1);

Modified: branches/12/channels/chan_misdn.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_misdn.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_misdn.c (original)
+++ branches/12/channels/chan_misdn.c Wed Dec 18 14:25:39 2013
@@ -5954,7 +5954,9 @@
 	chan_misdn_log(1, port, "read_config: Getting Config\n");
 
 	misdn_cfg_get(port, MISDN_CFG_LANGUAGE, lang, sizeof(lang));
+	ast_channel_lock(ast);
 	ast_channel_language_set(ast, lang);
+	ast_channel_unlock(ast);
 
 	misdn_cfg_get(port, MISDN_CFG_MUSICCLASS, ch->mohinterpret, sizeof(ch->mohinterpret));
 
@@ -6000,7 +6002,9 @@
 
 	misdn_cfg_get(bc->port, MISDN_CFG_CONTEXT, ch->context, sizeof(ch->context));
 
+	ast_channel_lock(ast);
 	ast_channel_context_set(ast, ch->context);
+	ast_channel_unlock(ast);
 
 #ifdef MISDN_1_2
 	update_pipeline_config(bc);
@@ -6017,8 +6021,10 @@
 	misdn_cfg_get(port, MISDN_CFG_PICKUPGROUP, &pg, sizeof(pg));
 	misdn_cfg_get(port, MISDN_CFG_CALLGROUP, &cg, sizeof(cg));
 	chan_misdn_log(5, port, " --> * CallGrp:%s PickupGrp:%s\n", ast_print_group(buf, sizeof(buf), cg), ast_print_group(buf2, sizeof(buf2), pg));
+	ast_channel_lock(ast);
 	ast_channel_pickupgroup_set(ast, pg);
 	ast_channel_callgroup_set(ast, cg);
+	ast_channel_unlock(ast);
 
 	misdn_cfg_get(port, MISDN_CFG_NAMEDPICKUPGROUP, &npg, sizeof(npg));
 	misdn_cfg_get(port, MISDN_CFG_NAMEDCALLGROUP, &ncg, sizeof(ncg));
@@ -6031,8 +6037,10 @@
 		ast_free(tmp_str);
 	}
 
+	ast_channel_lock(ast);
 	ast_channel_named_pickupgroups_set(ast, npg);
 	ast_channel_named_callgroups_set(ast, ncg);
+	ast_channel_unlock(ast);
 
 	if (ch->originator == ORG_AST) {
 		char callerid[BUFFERSIZE + 1];
@@ -6086,7 +6094,9 @@
 		/* Add configured prefix to dialed.number */
 		misdn_add_number_prefix(bc->port, bc->dialed.number_type, bc->dialed.number, sizeof(bc->dialed.number));
 
+		ast_channel_lock(ast);
 		ast_channel_exten_set(ast, bc->dialed.number);
+		ast_channel_unlock(ast);
 
 		misdn_cfg_get(bc->port, MISDN_CFG_OVERLAP_DIAL, &ch->overlap_dial, sizeof(ch->overlap_dial));
 		ast_mutex_init(&ch->overlap_tv_lock);
@@ -10232,8 +10242,10 @@
 
 		export_ch(chan, bc, ch);
 
+		ast_channel_lock(ch->ast);
 		ast_channel_rings_set(ch->ast, 1);
 		ast_setstate(ch->ast, AST_STATE_RINGING);
+		ast_channel_unlock(ch->ast);
 
 		/* Update asterisk channel caller information */
 		chan_misdn_log(2, bc->port, " --> TON: %s(%d)\n", misdn_to_str_ton(bc->caller.number_type), bc->caller.number_type);
@@ -10532,7 +10544,9 @@
 		}
 
 		ast_queue_control(ch->ast, AST_CONTROL_RINGING);
+		ast_channel_lock(ch->ast);
 		ast_setstate(ch->ast, AST_STATE_RINGING);
+		ast_channel_unlock(ch->ast);
 
 		cb_log(7, bc->port, " --> Set State Ringing\n");
 

Modified: branches/12/channels/chan_motif.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_motif.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_motif.c (original)
+++ branches/12/channels/chan_motif.c Wed Dec 18 14:25:39 2013
@@ -852,7 +852,6 @@
 	ao2_unlock(endpoint);
 
 	ast_channel_stage_snapshot_done(chan);
-
 	ast_channel_unlock(chan);
 
 	return chan;
@@ -2414,7 +2413,9 @@
 
 	ao2_link(endpoint->state->sessions, session);
 
+	ast_channel_lock(chan);
 	ast_setstate(chan, AST_STATE_RING);
+	ast_channel_unlock(chan);
 	res = ast_pbx_start(chan);
 
 	switch (res) {

Modified: branches/12/channels/chan_oss.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_oss.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_oss.c (original)
+++ branches/12/channels/chan_oss.c Wed Dec 18 14:25:39 2013
@@ -799,6 +799,7 @@
 	c = ast_channel_alloc(1, state, o->cid_num, o->cid_name, "", ext, ctx, linkedid, 0, "Console/%s", o->device + 5);
 	if (c == NULL)
 		return NULL;
+	ast_channel_lock(c);
 	ast_channel_tech_set(c, &oss_tech);
 	if (o->sounddev < 0)
 		setformat(o, O_RDWR);

Modified: branches/12/channels/chan_phone.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_phone.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_phone.c (original)
+++ branches/12/channels/chan_phone.c Wed Dec 18 14:25:39 2013
@@ -862,6 +862,7 @@
 	struct ast_format tmpfmt;
 	tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, "", i->ext, i->context, linkedid, 0, "Phone/%s", i->dev + 5);
 	if (tmp) {
+		ast_channel_lock(tmp);
 		ast_channel_tech_set(tmp, cur_tech);
 		ast_channel_set_fd(tmp, 0, i->fd);
 		/* XXX Switching formats silently causes kernel panics XXX */

Modified: branches/12/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_pjsip.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_pjsip.c (original)
+++ branches/12/channels/chan_pjsip.c Wed Dec 18 14:25:39 2013
@@ -363,6 +363,7 @@
 		ast_hangup(chan);
 		return NULL;
 	}
+
 
 	ast_channel_stage_snapshot(chan);
 
@@ -1835,9 +1836,11 @@
 	switch (status.code) {
 	case 180:
 		ast_queue_control(session->channel, AST_CONTROL_RINGING);
+		ast_channel_lock(session->channel);
 		if (ast_channel_state(session->channel) != AST_STATE_UP) {
 			ast_setstate(session->channel, AST_STATE_RINGING);
 		}
+		ast_channel_unlock(session->channel);
 		break;
 	case 183:
 		ast_queue_control(session->channel, AST_CONTROL_PROGRESS);

Modified: branches/12/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_skinny.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_skinny.c (original)
+++ branches/12/channels/chan_skinny.c Wed Dec 18 14:25:39 2013
@@ -4845,6 +4845,7 @@
 	struct skinny_device *d = l->device;
 	int res = 0;
 
+	ast_channel_lock(c);
 	ast_set_callerid(c,
 		l->hidecallerid ? "" : l->cid_num,
 		l->hidecallerid ? "" : l->cid_name,
@@ -4858,6 +4859,7 @@
 	ast_party_name_init(&ast_channel_connected(c)->id.name);
 #endif
 	ast_setstate(c, AST_STATE_RING);
+	ast_channel_unlock(c);
 	if (!sub->rtp) {
 		start_rtp(sub);
 	}
@@ -5501,7 +5503,6 @@
 			pbx_builtin_setvar_helper(tmp, v->name, v->value);
 
 		ast_channel_stage_snapshot_done(tmp);
-
 		ast_channel_unlock(tmp);
 
 		if (state != AST_STATE_DOWN) {

Modified: branches/12/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_unistim.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_unistim.c (original)
+++ branches/12/channels/chan_unistim.c Wed Dec 18 14:25:39 2013
@@ -2517,10 +2517,12 @@
 	int res;
 
 	ast_verb(3, "Starting switch on '%s@%s-%d' to %s\n", l->name, l->parent->name, sub->softkey, s->device->phone_number);
+	ast_channel_lock(chan);
 	ast_channel_exten_set(chan, s->device->phone_number);
+	ast_setstate(chan, AST_STATE_RING);
+	ast_channel_unlock(chan);
 	ast_copy_string(s->device->redial_number, s->device->phone_number,
 					sizeof(s->device->redial_number));
-	ast_setstate(chan, AST_STATE_RING);
 	res = ast_pbx_run(chan);
 	if (res) {
 		ast_log(LOG_WARNING, "PBX exited non-zero\n");
@@ -5627,7 +5629,6 @@
 	ast_channel_priority_set(tmp, 1);
 
 	ast_channel_stage_snapshot_done(tmp);
-
 	ast_channel_unlock(tmp);
 
 	if (state != AST_STATE_DOWN) {

Modified: branches/12/channels/chan_vpb.cc
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_vpb.cc?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/chan_vpb.cc (original)
+++ branches/12/channels/chan_vpb.cc Wed Dec 18 14:25:39 2013
@@ -2471,7 +2471,6 @@
 			ast_channel_exten_set(tmp, "s");
 		if (!ast_strlen_zero(me->language))
 			ast_channel_language_set(tmp, me->language);
-
 		ast_channel_unlock(tmp);
 
 		me->owner = tmp;

Modified: branches/12/channels/sig_analog.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/sig_analog.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/sig_analog.c (original)
+++ branches/12/channels/sig_analog.c Wed Dec 18 14:25:39 2013
@@ -2120,6 +2120,7 @@
 						getforward = 0;
 					} else {
 						res = analog_play_tone(p, idx, -1);
+						ast_channel_lock(chan);
 						ast_channel_exten_set(chan, exten);
 						if (!ast_strlen_zero(p->cid_num)) {
 							if (!p->hidecallerid) {
@@ -2134,6 +2135,7 @@
 							}
 						}
 						ast_setstate(chan, AST_STATE_RING);
+						ast_channel_unlock(chan);
 						analog_set_echocanceller(p, 1);
 						res = ast_pbx_run(chan);
 						if (res) {
@@ -2615,8 +2617,10 @@
 
 		analog_handle_notify_message(chan, p, flags, -1);
 
+		ast_channel_lock(chan);
 		ast_setstate(chan, AST_STATE_RING);
 		ast_channel_rings_set(chan, 1);
+		ast_channel_unlock(chan);
 		analog_set_ringtimeout(p, p->ringt_base);
 		res = ast_pbx_run(chan);
 		if (res) {

Modified: branches/12/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/sig_pri.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/channels/sig_pri.c (original)
+++ branches/12/channels/sig_pri.c Wed Dec 18 14:25:39 2013
@@ -2160,7 +2160,9 @@
 #endif	/* defined(ISSUE_16789) */
 
 		sig_pri_set_echocanceller(p, 1);
+		ast_channel_lock(chan);
 		ast_setstate(chan, AST_STATE_RING);
+		ast_channel_unlock(chan);
 		res = ast_pbx_run(chan);
 		if (res) {
 			ast_log(LOG_WARNING, "PBX exited non-zero!\n");

Modified: branches/12/funcs/func_timeout.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/funcs/func_timeout.c?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/funcs/func_timeout.c (original)
+++ branches/12/funcs/func_timeout.c Wed Dec 18 14:25:39 2013
@@ -155,7 +155,9 @@
 	switch (*data) {
 	case 'a':
 	case 'A':
+		ast_channel_lock(chan);
 		ast_channel_setwhentohangup_tv(chan, when);
+		ast_channel_unlock(chan);
 		if (!ast_tvzero(*ast_channel_whentohangup(chan))) {
 			when = ast_tvadd(when, ast_tvnow());
 			ast_strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S.%3q %Z",

Modified: branches/12/include/asterisk/aoc.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/aoc.h?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/include/asterisk/aoc.h (original)
+++ branches/12/include/asterisk/aoc.h Wed Dec 18 14:25:39 2013
@@ -497,7 +497,10 @@
  */
 int ast_aoc_decoded2str(const struct ast_aoc_decoded *decoded, struct ast_str **msg);
 
-/*! \brief generate AOC manager event for an AOC-S, AOC-D, or AOC-E msg */
+/*!
+ * \brief generate AOC manager event for an AOC-S, AOC-D, or AOC-E msg
+ * \pre chan is locked
+ */
 int ast_aoc_manager_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan);
 
 /*! \brief get the message type, AOC-D, AOC-E, or AOC Request */

Modified: branches/12/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/channel.h?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/include/asterisk/channel.h (original)
+++ branches/12/include/asterisk/channel.h Wed Dec 18 14:25:39 2013
@@ -1538,8 +1538,7 @@
  * \details
  * This function sets the absolute time out on a channel (when to hang up).
  *
- * \note This function does not require that the channel is locked before
- *       calling it.
+ * \pre chan is locked
  *
  * \return Nothing
  * \sa ast_channel_setwhentohangup_tv()
@@ -1555,8 +1554,7 @@
  *
  * This function sets the absolute time out on a channel (when to hang up).
  *
- * \note This function does not require that the channel is locked before
- * calling it.
+ * \pre chan is locked
  *
  * \return Nothing
  * \since 1.6.1
@@ -2339,6 +2337,8 @@
  * \brief adds a list of channel variables to a channel
  * \param chan the channel
  * \param vars a linked list of variables
+ *
+ * \pre chan is locked
  *
  * \details
  * Variable names can be for a regular channel variable or a dialplan function
@@ -3806,6 +3806,15 @@
 	void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) __attribute__((format(printf, 2, 0))); \
 	void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) __attribute__((format(printf, 2, 3)))
 
+/*!
+ * The following string fields result in channel snapshot creation and
+ * should have the channel locked when called:
+ *
+ * \li language
+ * \li accountcode
+ * \li peeracccount
+ * \li linkedid
+ */
 DECLARE_STRINGFIELD_SETTERS_FOR(name);
 DECLARE_STRINGFIELD_SETTERS_FOR(language);
 DECLARE_STRINGFIELD_SETTERS_FOR(musicclass);
@@ -3857,6 +3866,10 @@
 struct timeval ast_channel_sending_dtmf_tv(const struct ast_channel *chan);
 void ast_channel_sending_dtmf_tv_set(struct ast_channel *chan, struct timeval value);
 enum ama_flags ast_channel_amaflags(const struct ast_channel *chan);
+
+/*!
+ * \pre chan is locked
+ */
 void ast_channel_amaflags_set(struct ast_channel *chan, enum ama_flags value);
 int ast_channel_epfd(const struct ast_channel *chan);
 void ast_channel_epfd_set(struct ast_channel *chan, int value);
@@ -3940,6 +3953,10 @@
 void ast_channel_adsicpe_set(struct ast_channel *chan, enum ast_channel_adsicpe value);
 enum ast_channel_state ast_channel_state(const struct ast_channel *chan);
 struct ast_callid *ast_channel_callid(const struct ast_channel *chan);
+
+/*!
+ * \pre chan is locked
+ */
 void ast_channel_callid_set(struct ast_channel *chan, struct ast_callid *value);
 
 /* XXX Internal use only, make sure to move later */
@@ -3980,6 +3997,10 @@
 void ast_channel_dialed_set(struct ast_channel *chan, struct ast_party_dialed *value);
 void ast_channel_redirecting_set(struct ast_channel *chan, struct ast_party_redirecting *value);
 void ast_channel_dtmf_tv_set(struct ast_channel *chan, struct timeval *value);
+
+/*!
+ * \pre chan is locked
+ */
 void ast_channel_whentohangup_set(struct ast_channel *chan, struct timeval *value);
 void ast_channel_varshead_set(struct ast_channel *chan, struct varshead *value);
 struct timeval ast_channel_creationtime(struct ast_channel *chan);
@@ -3995,8 +4016,14 @@
 
 /* Typedef accessors */
 ast_group_t ast_channel_callgroup(const struct ast_channel *chan);
+/*!
+ * \pre chan is locked
+ */
 void ast_channel_callgroup_set(struct ast_channel *chan, ast_group_t value);
 ast_group_t ast_channel_pickupgroup(const struct ast_channel *chan);
+/*!
+ * \pre chan is locked
+ */
 void ast_channel_pickupgroup_set(struct ast_channel *chan, ast_group_t value);
 struct ast_namedgroups *ast_channel_named_callgroups(const struct ast_channel *chan);
 void ast_channel_named_callgroups_set(struct ast_channel *chan, struct ast_namedgroups *value);
@@ -4043,6 +4070,9 @@
 void ast_channel_timingfunc_set(struct ast_channel *chan, ast_timing_func_t value);
 
 struct ast_bridge *ast_channel_internal_bridge(const struct ast_channel *chan);
+/*!
+ * \pre chan is locked
+ */
 void ast_channel_internal_bridge_set(struct ast_channel *chan, struct ast_bridge *value);
 
 struct ast_bridge_channel *ast_channel_internal_bridge_channel(const struct ast_channel *chan);

Modified: branches/12/include/asterisk/channelstate.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/channelstate.h?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/include/asterisk/channelstate.h (original)
+++ branches/12/include/asterisk/channelstate.h Wed Dec 18 14:25:39 2013
@@ -47,7 +47,10 @@
 	AST_STATE_MUTE = (1 << 16),	/*!< Do not transmit voice data */
 };
 
-/*! \brief Change the state of a channel */
+/*!
+ * \brief Change the state of a channel
+ * \pre chan is locked
+ */
 int ast_setstate(struct ast_channel *chan, enum ast_channel_state);
 
 #endif /* __AST_CHANNELSTATE_H__ */

Modified: branches/12/include/asterisk/stasis_bridges.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/stasis_bridges.h?view=diff&rev=404237&r1=404236&r2=404237
==============================================================================
--- branches/12/include/asterisk/stasis_bridges.h (original)
+++ branches/12/include/asterisk/stasis_bridges.h Wed Dec 18 14:25:39 2013
@@ -203,6 +203,9 @@
  * should also be treated as immutable and not modified after it is put into the
  * message.
  *
+ * \pre bridge is locked.
+ * \pre No channels are locked.
+ *
  * \param bridge Channel blob is associated with, or NULL for global/all bridges.
  * \param blob JSON object representing the data.
  * \return \ref ast_bridge_blob message.
@@ -217,6 +220,9 @@
  * \since 12
  * \brief Publish a bridge channel enter event
  *
+ * \pre bridge is locked.
+ * \pre No channels are locked.
+ *
  * \param bridge The bridge a channel entered
  * \param chan The channel that entered the bridge
  * \param swap The channel being swapped out of the bridge
@@ -228,6 +234,9 @@
  * \since 12
  * \brief Publish a bridge channel leave event
  *
+ * \pre bridge is locked.
+ * \pre No channels are locked.
+ *
  * \param bridge The bridge a channel left
  * \param chan The channel that left the bridge
  */
@@ -271,6 +280,8 @@
 
 /*!
  * \brief Publish a blind transfer event
+ *
+ * \pre No channels or bridges are locked
  *
  * \param is_external Whether the blind transfer was initiated externally (e.g. via AMI or native protocol)
  * \param result The success or failure of the transfer
@@ -335,6 +346,8 @@
  * Publish an \ref ast_attended_transfer_message with the dest_type set to
  * \c AST_ATTENDED_TRANSFER_DEST_FAIL.
  *
+ * \pre No channels or bridges are locked
+ *
  * \param is_external Indicates if the transfer was initiated externally
  * \param result The result of the transfer. Will always be a type of failure.
  * \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
@@ -355,6 +368,8 @@
  * \li Moving a channel from one bridge to the other, thus emptying a bridge
  *
  * In either case, two bridges enter, one leaves.
+ *
+ * \pre No channels or bridges are locked
  *
  * \param is_external Indicates if the transfer was initiated externally
  * \param result The result of the transfer.
@@ -375,6 +390,8 @@
  * this results from merging two bridges together. The difference is that a
  * transferer channel survives the bridge merge
  *
+ * \pre No channels or bridges are locked
+ *
  * \param is_external Indicates if the transfer was initiated externally
  * \param result The result of the transfer.
  * \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
@@ -396,6 +413,8 @@
  * \li A transferee channel leaving a bridge to run an app
  * \li A bridge of transferees running an app (via a local channel)
  *
+ * \pre No channels or bridges are locked
+ *
  * \param is_external Indicates if the transfer was initiated externally
  * \param result The result of the transfer.
  * \param transferee The bridge between the transferer and transferees as well as the transferer channel from that bridge
@@ -419,6 +438,8 @@
  * When this type of transfer occurs, the two bridges continue to exist after the
  * transfer and a local channel is used to link the two bridges together.
  *
+ * \pre No channels or bridges are locked
+ *

[... 1019 lines stripped ...]



More information about the asterisk-commits mailing list