[asterisk-commits] rmudgett: branch rmudgett/call_waiting r261865 - in /team/rmudgett/call_waiti...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 6 20:38:06 CDT 2010


Author: rmudgett
Date: Thu May  6 20:38:03 2010
New Revision: 261865

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=261865
Log:
Merged revisions 261825 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/team/group/CCSS

................
  r261825 | root | 2010-05-06 19:17:49 -0500 (Thu, 06 May 2010) | 18 lines
  
  Merged revisions 261822 via svnmerge from 
  file:///srv/subversion/repos/asterisk/trunk
  
  ........
    r261822 | rmudgett | 2010-05-06 18:41:22 -0500 (Thu, 06 May 2010) | 11 lines
    
    Some code optimizations.
    
    * Made more places use pri_queue_control() instead of pri_queue_frame()
    and a local frame variable.
    
    * Made pri_queue_frame() use sig_pri_lock_owner().  pri_queue_frame() no
    longer releases the libpri access lock unless it is required.
    
    * Made the pri_queue_frame() and pri_queue_control() parameter list
    similar to sig_pri_lock_owner().
  ........
................

Modified:
    team/rmudgett/call_waiting/   (props changed)
    team/rmudgett/call_waiting/channels/sig_pri.c

Propchange: team/rmudgett/call_waiting/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/rmudgett/call_waiting/
------------------------------------------------------------------------------
--- call_waiting-integrated (original)
+++ call_waiting-integrated Thu May  6 20:38:03 2010
@@ -1,1 +1,1 @@
-/team/group/CCSS:1-261795
+/team/group/CCSS:1-261864

Propchange: team/rmudgett/call_waiting/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu May  6 20:38:03 2010
@@ -1,1 +1,1 @@
-/trunk:1-261742
+/trunk:1-261824

Modified: team/rmudgett/call_waiting/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/call_waiting/channels/sig_pri.c?view=diff&rev=261865&r1=261864&r2=261865
==============================================================================
--- team/rmudgett/call_waiting/channels/sig_pri.c (original)
+++ team/rmudgett/call_waiting/channels/sig_pri.c Thu May  6 20:38:03 2010
@@ -915,37 +915,85 @@
 	return 0;
 }
 
-static void pri_queue_frame(struct sig_pri_chan *p, struct ast_frame *f, struct sig_pri_pri *pri)
-{
-	/* We must unlock the PRI to avoid the possibility of a deadlock */
-	if (pri)
+/*!
+ * \internal
+ * \brief Obtain the sig_pri owner channel lock if the owner exists.
+ * \since 1.8
+ *
+ * \param pri sig_pri PRI control structure.
+ * \param chanpos Channel position in the span.
+ *
+ * \note Assumes the pri->lock is already obtained.
+ * \note Assumes the sig_pri_lock_private(pri->pvts[chanpos]) is already obtained.
+ *
+ * \return Nothing
+ */
+static void sig_pri_lock_owner(struct sig_pri_pri *pri, int chanpos)
+{
+	for (;;) {
+		if (!pri->pvts[chanpos]->owner) {
+			/* There is no owner lock to get. */
+			break;
+		}
+		if (!ast_channel_trylock(pri->pvts[chanpos]->owner)) {
+			/* We got the lock */
+			break;
+		}
+		/* We must unlock the PRI to avoid the possibility of a deadlock */
 		ast_mutex_unlock(&pri->lock);
-	for (;;) {
-		if (p->owner) {
-			if (ast_channel_trylock(p->owner)) {
-				PRI_DEADLOCK_AVOIDANCE(p);
-			} else {
-				ast_queue_frame(p->owner, f);
-				ast_channel_unlock(p->owner);
-				break;
-			}
-		} else
-			break;
-	}
-	if (pri)
+		PRI_DEADLOCK_AVOIDANCE(pri->pvts[chanpos]);
 		ast_mutex_lock(&pri->lock);
-}
-
-static void pri_queue_control(struct sig_pri_chan *p, int subclass, struct sig_pri_pri *pri)
+	}
+}
+
+/*!
+ * \internal
+ * \brief Queue the given frame onto the owner channel.
+ * \since 1.8
+ *
+ * \param pri sig_pri PRI control structure.
+ * \param chanpos Channel position in the span.
+ * \param frame Frame to queue onto the owner channel.
+ *
+ * \note Assumes the pri->lock is already obtained.
+ * \note Assumes the sig_pri_lock_private(pri->pvts[chanpos]) is already obtained.
+ *
+ * \return Nothing
+ */
+static void pri_queue_frame(struct sig_pri_pri *pri, int chanpos, struct ast_frame *frame)
+{
+	sig_pri_lock_owner(pri, chanpos);
+	if (pri->pvts[chanpos]->owner) {
+		ast_queue_frame(pri->pvts[chanpos]->owner, frame);
+		ast_channel_unlock(pri->pvts[chanpos]->owner);
+	}
+}
+
+/*!
+ * \internal
+ * \brief Queue a control frame of the specified subclass onto the owner channel.
+ * \since 1.8
+ *
+ * \param pri sig_pri PRI control structure.
+ * \param chanpos Channel position in the span.
+ * \param subclass Control frame subclass to queue onto the owner channel.
+ *
+ * \note Assumes the pri->lock is already obtained.
+ * \note Assumes the sig_pri_lock_private(pri->pvts[chanpos]) is already obtained.
+ *
+ * \return Nothing
+ */
+static void pri_queue_control(struct sig_pri_pri *pri, int chanpos, int subclass)
 {
 	struct ast_frame f = {AST_FRAME_CONTROL, };
+	struct sig_pri_chan *p = pri->pvts[chanpos];
 
 	if (p->calls->queue_control) {
 		p->calls->queue_control(p->chan_pvt, subclass);
 	}
 
 	f.subclass.integer = subclass;
-	pri_queue_frame(p, &f, pri);
+	pri_queue_frame(pri, chanpos, &f);
 }
 
 static int pri_find_principle(struct sig_pri_pri *pri, int channel, q931_call *call)
@@ -1578,37 +1626,6 @@
 	return 0;
 }
 
-/*!
- * \internal
- * \brief Obtain the sig_pri owner channel lock if the owner exists.
- * \since 1.8
- *
- * \param pri sig_pri PRI control structure.
- * \param chanpos Channel position in the span.
- *
- * \note Assumes the pri->lock is already obtained.
- * \note Assumes the sig_pri_lock_private(pri->pvts[chanpos]) is already obtained.
- *
- * \return Nothing
- */
-static void sig_pri_lock_owner(struct sig_pri_pri *pri, int chanpos)
-{
-	for (;;) {
-		if (!pri->pvts[chanpos]->owner) {
-			/* There is no owner lock to get. */
-			break;
-		}
-		if (!ast_channel_trylock(pri->pvts[chanpos]->owner)) {
-			/* We got the lock */
-			break;
-		}
-		/* We must unlock the PRI to avoid the possibility of a deadlock */
-		ast_mutex_unlock(&pri->lock);
-		PRI_DEADLOCK_AVOIDANCE(pri->pvts[chanpos]);
-		ast_mutex_lock(&pri->lock);
-	}
-}
-
 #if defined(HAVE_PRI_CCSS)
 /*!
  * \internal
@@ -2590,8 +2607,13 @@
 	} else {
 		struct ast_frame f = { AST_FRAME_CONTROL, };
 
+		/*
+		 * Things are in an odd state here so we cannot use pri_queue_control().
+		 * However, we already have the owner lock so we can simply queue the frame.
+		 */
 		f.subclass.integer = AST_CONTROL_HOLD;
 		ast_queue_frame(owner, &f);
+
 		sig_pri_span_devstate_changed(pri);
 		retval = 0;
 	}
@@ -2659,12 +2681,7 @@
 	sig_pri_lock_private(pri->pvts[chanpos]);
 	sig_pri_handle_subcmds(pri, chanpos, ev->e, ev->retrieve.channel,
 		ev->retrieve.subcmds, ev->retrieve.call);
-	{
-		struct ast_frame f = { AST_FRAME_CONTROL, };
-
-		f.subclass.integer = AST_CONTROL_UNHOLD;
-		pri_queue_frame(pri->pvts[chanpos], &f, pri);
-	}
+	pri_queue_control(pri, chanpos, AST_CONTROL_UNHOLD);
 	sig_pri_unlock_private(pri->pvts[chanpos]);
 	sig_pri_span_devstate_changed(pri);
 	pri_retrieve_ack(pri->pri, ev->retrieve.call,
@@ -3010,7 +3027,7 @@
 							for (i = 0; i < digitlen; i++) {
 								struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = e->digit.digits[i], };
 
-								pri_queue_frame(pri->pvts[chanpos], &f, pri);
+								pri_queue_frame(pri, chanpos, &f);
 							}
 						}
 						sig_pri_unlock_private(pri->pvts[chanpos]);
@@ -3045,7 +3062,7 @@
 							for (i = 0; i < digitlen; i++) {
 								struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = e->ring.callednum[i], };
 
-								pri_queue_frame(pri->pvts[chanpos], &f, pri);
+								pri_queue_frame(pri, chanpos, &f);
 							}
 						}
 						sig_pri_unlock_private(pri->pvts[chanpos]);
@@ -3510,7 +3527,7 @@
 							e->ringing.subcmds, e->ringing.call);
 						sig_pri_cc_generic_check(pri, chanpos, AST_CC_CCNR);
 						sig_pri_set_echocanceller(pri->pvts[chanpos], 1);
-						pri_queue_control(pri->pvts[chanpos], AST_CONTROL_RINGING, pri);
+						pri_queue_control(pri, chanpos, AST_CONTROL_RINGING);
 						pri->pvts[chanpos]->alerting = 1;
 
 #ifdef SUPPORT_USERUSER
@@ -3539,8 +3556,6 @@
 				}
 				chanpos = pri_find_principle(pri, e->proceeding.channel, e->proceeding.call);
 				if (chanpos > -1) {
-					struct ast_frame f = { AST_FRAME_CONTROL, };
-
 					sig_pri_lock_private(pri->pvts[chanpos]);
 					sig_pri_handle_subcmds(pri, chanpos, e->e, e->proceeding.channel,
 						e->proceeding.subcmds, e->proceeding.call);
@@ -3554,8 +3569,7 @@
 								ast_verb(3, "PROGRESS with 'user busy' received, signaling AST_CONTROL_BUSY instead of AST_CONTROL_PROGRESS\n");
 
 								pri->pvts[chanpos]->owner->hangupcause = e->proceeding.cause;
-								f.subclass.integer = AST_CONTROL_BUSY;
-								pri_queue_frame(pri->pvts[chanpos], &f, pri);
+								pri_queue_control(pri, chanpos, AST_CONTROL_BUSY);
 							}
 						}
 					}
@@ -3571,8 +3585,7 @@
 						/* Bring voice path up */
 						ast_debug(1, "Queuing frame from PRI_EVENT_PROGRESS on channel %d/%d span %d\n",
 							pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
-						f.subclass.integer = AST_CONTROL_PROGRESS;
-						pri_queue_frame(pri->pvts[chanpos], &f, pri);
+						pri_queue_control(pri, chanpos, AST_CONTROL_PROGRESS);
 						pri->pvts[chanpos]->progress = 1;
 						sig_pri_set_dialing(pri->pvts[chanpos], 0);
 					}
@@ -3587,16 +3600,13 @@
 				}
 				chanpos = pri_find_principle(pri, e->proceeding.channel, e->proceeding.call);
 				if (chanpos > -1) {
-					struct ast_frame f = { AST_FRAME_CONTROL, };
-
 					sig_pri_lock_private(pri->pvts[chanpos]);
 					sig_pri_handle_subcmds(pri, chanpos, e->e, e->proceeding.channel,
 						e->proceeding.subcmds, e->proceeding.call);
 					if (!pri->pvts[chanpos]->proceeding) {
 						ast_debug(1, "Queuing frame from PRI_EVENT_PROCEEDING on channel %d/%d span %d\n",
 							pri->pvts[chanpos]->logicalspan, pri->pvts[chanpos]->prioffset,pri->span);
-						f.subclass.integer = AST_CONTROL_PROCEEDING;
-						pri_queue_frame(pri->pvts[chanpos], &f, pri);
+						pri_queue_control(pri, chanpos, AST_CONTROL_PROCEEDING);
 						pri->pvts[chanpos]->proceeding = 1;
 					}
 					if (!pri->pvts[chanpos]->progress
@@ -3608,8 +3618,7 @@
 #endif
 						) {
 						/* Bring voice path up */
-						f.subclass.integer = AST_CONTROL_PROGRESS;
-						pri_queue_frame(pri->pvts[chanpos], &f, pri);
+						pri_queue_control(pri, chanpos, AST_CONTROL_PROGRESS);
 						pri->pvts[chanpos]->progress = 1;
 						sig_pri_set_dialing(pri->pvts[chanpos], 0);
 					}
@@ -3691,7 +3700,7 @@
 									ast_softhangup_nolock(pri->pvts[chanpos]->owner, AST_SOFTHANGUP_DEV);
 									break;
 								default:
-									pri_queue_control(pri->pvts[chanpos], AST_CONTROL_CONGESTION, pri);
+									pri_queue_control(pri, chanpos, AST_CONTROL_CONGESTION);
 									break;
 								}
 							} else {
@@ -3729,7 +3738,7 @@
 				sig_pri_handle_subcmds(pri, chanpos, e->e, e->answer.channel,
 					e->answer.subcmds, e->answer.call);
 				sig_pri_open_media(pri->pvts[chanpos]);
-				pri_queue_control(pri->pvts[chanpos], AST_CONTROL_ANSWER, pri);
+				pri_queue_control(pri, chanpos, AST_CONTROL_ANSWER);
 				/* Enable echo cancellation if it's not on already */
 				sig_pri_set_dialing(pri->pvts[chanpos], 0);
 				sig_pri_set_echocanceller(pri->pvts[chanpos], 1);
@@ -3820,7 +3829,7 @@
 								default:
 									switch (e->hangup.cause) {
 									case PRI_CAUSE_USER_BUSY:
-										pri_queue_control(pri->pvts[chanpos], AST_CONTROL_BUSY, pri);
+										pri_queue_control(pri, chanpos, AST_CONTROL_BUSY);
 										break;
 									case PRI_CAUSE_CALL_REJECTED:
 									case PRI_CAUSE_NETWORK_OUT_OF_ORDER:
@@ -3828,7 +3837,7 @@
 									case PRI_CAUSE_SWITCH_CONGESTION:
 									case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
 									case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
-										pri_queue_control(pri->pvts[chanpos], AST_CONTROL_CONGESTION, pri);
+										pri_queue_control(pri, chanpos, AST_CONTROL_CONGESTION);
 										break;
 									default:
 										ast_softhangup_nolock(pri->pvts[chanpos]->owner, AST_SOFTHANGUP_DEV);
@@ -3921,7 +3930,7 @@
 							default:
 								switch (e->hangup.cause) {
 								case PRI_CAUSE_USER_BUSY:
-									pri_queue_control(pri->pvts[chanpos], AST_CONTROL_BUSY, pri);
+									pri_queue_control(pri, chanpos, AST_CONTROL_BUSY);
 									break;
 								case PRI_CAUSE_CALL_REJECTED:
 								case PRI_CAUSE_NETWORK_OUT_OF_ORDER:
@@ -3929,7 +3938,7 @@
 								case PRI_CAUSE_SWITCH_CONGESTION:
 								case PRI_CAUSE_DESTINATION_OUT_OF_ORDER:
 								case PRI_CAUSE_NORMAL_TEMPORARY_FAILURE:
-									pri_queue_control(pri->pvts[chanpos], AST_CONTROL_CONGESTION, pri);
+									pri_queue_control(pri, chanpos, AST_CONTROL_CONGESTION);
 									break;
 								default:
 									ast_softhangup_nolock(pri->pvts[chanpos]->owner, AST_SOFTHANGUP_DEV);
@@ -4118,18 +4127,12 @@
 					switch (e->notify.info) {
 					case PRI_NOTIFY_REMOTE_HOLD:
 						if (!pri->discardremoteholdretrieval) {
-							struct ast_frame f = { AST_FRAME_CONTROL, };
-
-							f.subclass.integer = AST_CONTROL_HOLD;
-							pri_queue_frame(pri->pvts[chanpos], &f, pri);
+							pri_queue_control(pri, chanpos, AST_CONTROL_HOLD);
 						}
 						break;
 					case PRI_NOTIFY_REMOTE_RETRIEVAL:
 						if (!pri->discardremoteholdretrieval) {
-							struct ast_frame f = { AST_FRAME_CONTROL, };
-
-							f.subclass.integer = AST_CONTROL_UNHOLD;
-							pri_queue_frame(pri->pvts[chanpos], &f, pri);
+							pri_queue_control(pri, chanpos, AST_CONTROL_UNHOLD);
 						}
 						break;
 					}




More information about the asterisk-commits mailing list