[asterisk-commits] rmudgett: trunk r367227 - /trunk/main/channel.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon May 21 17:45:44 CDT 2012


Author: rmudgett
Date: Mon May 21 17:45:41 2012
New Revision: 367227

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=367227
Log:
Made ast_queue_hangup() and ast_queue_hangup_with_cause() lock instead of trylock.

It made no sense to trylock the channel and then unconditionally lock the
channel right after.

Modified:
    trunk/main/channel.c

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=367227&r1=367226&r2=367227
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Mon May 21 17:45:41 2012
@@ -1313,44 +1313,51 @@
 int ast_queue_hangup(struct ast_channel *chan)
 {
 	struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
+	int res;
+
 	/* Yeah, let's not change a lock-critical value without locking */
-	if (!ast_channel_trylock(chan)) {
-		ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
-		manager_event(EVENT_FLAG_CALL, "HangupRequest",
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan));
-		ast_channel_unlock(chan);
-	}
-	return ast_queue_frame(chan, &f);
+	ast_channel_lock(chan);
+	ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
+
+	manager_event(EVENT_FLAG_CALL, "HangupRequest",
+		"Channel: %s\r\n"
+		"Uniqueid: %s\r\n",
+		ast_channel_name(chan),
+		ast_channel_uniqueid(chan));
+
+	res = ast_queue_frame(chan, &f);
+	ast_channel_unlock(chan);
+	return res;
 }
 
 /*! \brief Queue a hangup frame for channel */
 int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
 {
 	struct ast_frame f = { AST_FRAME_CONTROL, .subclass.integer = AST_CONTROL_HANGUP };
-
-	if (cause >= 0)
+	int res;
+
+	if (cause >= 0) {
 		f.data.uint32 = cause;
+	}
 
 	/* Yeah, let's not change a lock-critical value without locking */
-	if (!ast_channel_trylock(chan)) {
-		ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
-		if (cause < 0)
-			f.data.uint32 = ast_channel_hangupcause(chan);
-
-		manager_event(EVENT_FLAG_CALL, "HangupRequest",
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"Cause: %d\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan),
-			cause);
-		ast_channel_unlock(chan);
-	}
-
-	return ast_queue_frame(chan, &f);
+	ast_channel_lock(chan);
+	ast_channel_softhangup_internal_flag_add(chan, AST_SOFTHANGUP_DEV);
+	if (cause < 0) {
+		f.data.uint32 = ast_channel_hangupcause(chan);
+	}
+
+	manager_event(EVENT_FLAG_CALL, "HangupRequest",
+		"Channel: %s\r\n"
+		"Uniqueid: %s\r\n"
+		"Cause: %d\r\n",
+		ast_channel_name(chan),
+		ast_channel_uniqueid(chan),
+		cause);
+
+	res = ast_queue_frame(chan, &f);
+	ast_channel_unlock(chan);
+	return res;
 }
 
 /*! \brief Queue a control frame */




More information about the asterisk-commits mailing list