[asterisk-commits] jpeeler: branch jpeeler/bug12269 r156455 - /team/jpeeler/bug12269/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 12 17:53:26 CST 2008


Author: jpeeler
Date: Wed Nov 12 17:53:26 2008
New Revision: 156455

URL: http://svn.digium.com/view/asterisk?view=rev&rev=156455
Log:
Remove unnecessary locking and correctly mimick old trylock behavior.


Modified:
    team/jpeeler/bug12269/channels/chan_agent.c

Modified: team/jpeeler/bug12269/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/bug12269/channels/chan_agent.c?view=diff&rev=156455&r1=156454&r2=156455
==============================================================================
--- team/jpeeler/bug12269/channels/chan_agent.c (original)
+++ team/jpeeler/bug12269/channels/chan_agent.c Wed Nov 12 17:53:26 2008
@@ -430,10 +430,8 @@
 	chan->tech_pvt = NULL;
 	p->app_sleep_cond = 1;
 	/* Release ownership of the agent to other threads (presumably running the login app). */
-	ast_mutex_lock(&p->app_lock);
 	p->app_lock_flag = 0;
 	ast_cond_signal(&p->app_complete_cond);
-	ast_mutex_unlock(&p->app_lock);
 	if (chan)
 		ast_channel_free(chan);
 	if (p->dead) {
@@ -947,10 +945,8 @@
 		}
 		/* Release ownership of the agent to other threads (presumably running the login app). */
 		if (ast_strlen_zero(p->loginchan)) {
-			ast_mutex_lock(&p->app_lock);
 			p->app_lock_flag = 0;
 			ast_cond_signal(&p->app_complete_cond);
-			ast_mutex_unlock(&p->app_lock);
 		}
 	}
 	return 0;
@@ -1039,6 +1035,7 @@
 static struct ast_channel *agent_new(struct agent_pvt *p, int state)
 {
 	struct ast_channel *tmp;
+	int alreadylocked;
 #if 0
 	if (!p->chan) {
 		ast_log(LOG_WARNING, "No channel? :(\n");
@@ -1089,9 +1086,12 @@
 	 * implemented in the kernel for this.
 	 */
 	p->app_sleep_cond = 0;
+
+	alreadylocked = p->app_lock_flag;
+	ast_log(LOG_WARNING, "jpeeler alreadylocked: %d\n", alreadylocked);
 	p->app_lock_flag = 1;
 
-	if(ast_strlen_zero(p->loginchan) && !p->app_lock_flag) {
+	if(ast_strlen_zero(p->loginchan) && alreadylocked) {
 		if (p->chan) {
 			ast_queue_frame(p->chan, &ast_null_frame);
 			ast_mutex_unlock(&p->lock);	/* For other thread to read the condition. */
@@ -1104,10 +1104,8 @@
 			p->app_sleep_cond = 1;
 			ast_channel_free( tmp );
 			ast_mutex_unlock(&p->lock);	/* For other thread to read the condition. */
-			ast_mutex_lock(&p->app_lock);
 			p->app_lock_flag = 0;
 			ast_cond_signal(&p->app_complete_cond);
-			ast_mutex_unlock(&p->app_lock);
 			return NULL;
 		}
 	} else if (!ast_strlen_zero(p->loginchan)) {
@@ -2276,7 +2274,6 @@
 							ast_mutex_lock(&p->app_lock);
 //ast_log(LOG_NOTICE, "jpeeler: app_lock obtained by thread %p\n", (void *) pthread_self());
 							if (p->app_lock_flag == 1) {
-								p->app_lock_flag = 0;
 								ast_cond_wait(&p->app_complete_cond, &p->app_lock);
 							}
 							ast_mutex_unlock(&p->app_lock);




More information about the asterisk-commits mailing list