[asterisk-commits] jpeeler: branch jpeeler/asterisk-sigwork-trunk r196273 - /team/jpeeler/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 22 11:54:15 CDT 2009


Author: jpeeler
Date: Fri May 22 11:54:11 2009
New Revision: 196273

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=196273
Log:
Add callbacks to increase/decrease analog_ss_thread counts from within sig_analog. This is a lot of code to do so little, but should be done this way until the analog_ss_thread in chan_dahdi completely goes away.

Modified:
    team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c
    team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c?view=diff&rev=196273&r1=196272&r2=196273
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/chan_dahdi.c Fri May 22 11:54:11 2009
@@ -1839,6 +1839,21 @@
 	ast_mutex_unlock(&p->lock);
 }
 
+static void my_increase_ss_count(void)
+{
+	ast_mutex_lock(&ss_thread_lock);
+	ss_thread_count++;
+	ast_mutex_unlock(&ss_thread_lock);
+}
+
+static void my_decrease_ss_count(void)
+{
+	ast_mutex_lock(&ss_thread_lock);
+	ss_thread_count--;
+	ast_cond_signal(&ss_thread_complete);
+	ast_mutex_unlock(&ss_thread_lock);
+}
+
 static void my_all_subchannels_hungup(void *pvt)
 {
 	struct dahdi_pvt *p = pvt;
@@ -2337,6 +2352,8 @@
 	.start_cid_detect = my_start_cid_detect,
 	.stop_cid_detect = my_stop_cid_detect,
 	.handle_notify_message = my_handle_notify_message,
+	.increase_ss_count = my_increase_ss_count,
+	.decrease_ss_count = my_decrease_ss_count,
 };
 
 struct dahdi_pvt *round_robin[32];
@@ -15736,8 +15753,8 @@
 			if (p->owner)
 				ioctl(p->subs[SUB_REAL].dfd, DAHDI_HOOK, &x); /* important to create an event for dahdi_wait_event to register so that all analog_ss_threads terminate */
 			}
-			ast_cond_wait(&ss_thread_complete, &ss_thread_lock);
-		}
+		ast_cond_wait(&ss_thread_complete, &ss_thread_lock);
+	}
 
 	/* ensure any created channels before monitor threads were stopped are hungup */
 	dahdi_softhangup_all();

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c?view=diff&rev=196273&r1=196272&r2=196273
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.c Fri May 22 11:54:11 2009
@@ -70,7 +70,6 @@
 	/* "smdi" is intentionally not supported here, as there is a much better
 	 * way to do this in the dialplan now. */
 };
-
 
 enum analog_sigtype analog_str_to_sigtype(const char *name)
 {
@@ -1218,6 +1217,24 @@
 		return -1;
 }
 
+static int analog_increase_ss_count(struct analog_pvt *p)
+{
+	if (p->calls->increase_ss_count) {
+		p->calls->increase_ss_count();
+		return 0;
+	} else
+		return -1;
+}
+
+static int analog_decrease_ss_count(struct analog_pvt *p)
+{
+	if (p->calls->decrease_ss_count) {
+		p->calls->decrease_ss_count();
+		return 0;
+	} else
+		return -1;
+}
+
 #define ANALOG_NEED_MFDETECT(p) (((p)->sig == ANALOG_SIG_FEATDMF) || ((p)->sig == ANALOG_SIG_FEATDMF_TA) || ((p)->sig == ANALOG_SIG_E911) || ((p)->sig == ANALOG_SIG_FGC_CAMA) || ((p)->sig == ANALOG_SIG_FGC_CAMAMF) || ((p)->sig == ANALOG_SIG_FEATB)) 
 
 static void *__analog_ss_thread(void *data)
@@ -1250,6 +1267,8 @@
 	int res;
 	int index;
 
+	analog_increase_ss_count(p);
+
 	ast_log(LOG_DEBUG, "%s %d\n", __FUNCTION__, p->channel);
 
 	/* in the bizarre case where the channel has become a zombie before we
@@ -1258,7 +1277,7 @@
 	if (!p) {
 		ast_log(LOG_WARNING, "Channel became a zombie before simple switch could be started (%s)\n", chan->name);
 		ast_hangup(chan);
-		return NULL;
+		goto quit;
 	}
 
 	if (option_verbose > 2) 
@@ -1267,7 +1286,7 @@
 	if (index < 0) {
 		ast_log(LOG_WARNING, "Huh?\n");
 		ast_hangup(chan);
-		return NULL;
+		goto quit;
 	}
 	analog_dsp_reset_and_flush_digits(p);
 	switch (p->sig) {
@@ -1283,7 +1302,7 @@
 	case ANALOG_SIG_SF_FEATB:
 	case ANALOG_SIG_SFWINK:
 		if (analog_wink(p, index))	
-			return NULL;
+			goto quit;
 		/* Fall through */
 	case ANALOG_SIG_EM:
 	case ANALOG_SIG_EM_E1:
@@ -1321,7 +1340,7 @@
 				res = analog_my_getsigstr(chan, dtmfbuf + 1, "#", 3000);
 				if (res < 1)
 					analog_dsp_reset_and_flush_digits(p);
-				if (analog_wink(p, index)) return NULL;
+				if (analog_wink(p, index)) goto quit;
 				dtmfbuf[0] = 0;
 				/* Wait for the first digit (up to 5 seconds). */
 				res = ast_waitfordigit(chan, 5000);
@@ -1336,7 +1355,7 @@
 				/* if international caca, do it again to get real ANO */
 				if ((p->sig == ANALOG_SIG_FEATDMF) && (dtmfbuf[1] != '0') && (strlen(dtmfbuf) != 14))
 				{
-					if (analog_wink(p, index)) return NULL;
+					if (analog_wink(p, index)) goto quit;
 					dtmfbuf[0] = 0;
 					/* Wait for the first digit (up to 5 seconds). */
 					res = ast_waitfordigit(chan, 5000);
@@ -1386,7 +1405,7 @@
 					if (res < 0) {
 						ast_debug(1, "waitfordigit returned < 0...\n");
 						ast_hangup(chan);
-						return NULL;
+						goto quit;
 					} else if (res) {
 						dtmfbuf[len++] = res;
 						dtmfbuf[len] = '\0';
@@ -1400,11 +1419,11 @@
 		if (res == -1) {
 			ast_log(LOG_WARNING, "getdtmf on channel %d: %s\n", p->channel, strerror(errno));
 			ast_hangup(chan);
-			return NULL;
+			goto quit;
 		} else if (res < 0) {
 			ast_debug(1, "Got hung up before digits finished\n");
 			ast_hangup(chan);
-			return NULL;
+			goto quit;
 		}
 
 		if (p->sig == ANALOG_SIG_FGC_CAMA) {
@@ -1412,7 +1431,7 @@
 
 			if (ast_safe_sleep(chan,1000) == -1) {
 	                        ast_hangup(chan);
-	                        return NULL;
+	                        goto quit;
 			}
 			analog_off_hook(p);
 			analog_dsp_set_digitmode(p, ANALOG_DIGITMODE_MF);
@@ -1501,7 +1520,7 @@
 			/* some switches require a minimum guard time between
 			the last FGD wink and something that answers
 			immediately. This ensures it */
-			if (ast_safe_sleep(chan,100)) return NULL;
+			if (ast_safe_sleep(chan,100)) goto quit;
 		}
 		analog_set_echocanceller(p, 1);
 
@@ -1515,7 +1534,7 @@
 				ast_log(LOG_WARNING, "PBX exited non-zero\n");
 				res = analog_play_tone(p, index, ANALOG_TONE_CONGESTION);
 			}
-			return NULL;
+			goto quit;
 		} else {
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_2 "Unknown extension '%s' in context '%s' requested\n", exten, chan->context);
@@ -1530,7 +1549,7 @@
 				ast_waitstream(chan, "");
 			res = analog_play_tone(p, index, ANALOG_TONE_CONGESTION);
 			ast_hangup(chan);
-			return NULL;
+			goto quit;
 		}
 		break;
 	case ANALOG_SIG_FXOLS:
@@ -1554,7 +1573,7 @@
 				ast_debug(1, "waitfordigit returned < 0...\n");
 				res = analog_play_tone(p, index, -1);
 				ast_hangup(chan);
-				return NULL;
+				goto quit;
 			} else if (res)  {
 				exten[len++]=res;
 				exten[len] = '\0';
@@ -1600,7 +1619,7 @@
 							ast_log(LOG_WARNING, "PBX exited non-zero\n");
 							res = analog_play_tone(p, index, ANALOG_TONE_CONGESTION);
 						}
-						return NULL;
+						goto quit;
 					}
 				} else {
 					/* It's a match, but they just typed a digit, and there is an ambiguous match,
@@ -1612,7 +1631,7 @@
 				res = analog_play_tone(p, index, ANALOG_TONE_CONGESTION);
 				analog_wait_event(p);
 				ast_hangup(chan);
-				return NULL;
+				goto quit;
 			} else if (p->callwaiting && !strcmp(exten, "*70")) {
 				if (option_verbose > 2) 
 					ast_verbose(VERBOSE_PREFIX_3 "Disabling call waiting on %s\n", chan->name);
@@ -1648,11 +1667,11 @@
 						analog_wait_event(p);
 					}
 					ast_hangup(chan);
-					return NULL;
+					goto quit;
 				} else {
 					ast_log(LOG_WARNING, "Huh?  Got *8# on call not on real\n");
 					ast_hangup(chan);
-					return NULL;
+					goto quit;
 				}
 				
 			} else if (!p->hidecallerid && !strcmp(exten, "*67")) {
@@ -1787,7 +1806,7 @@
 					if (ast_bridged_channel(p->subs[ANALOG_SUB_REAL].owner))
 						ast_queue_control(p->subs[ANALOG_SUB_REAL].owner, AST_CONTROL_UNHOLD);
 					ast_hangup(chan);
-					return NULL;
+					goto quit;
 				} else {
 					analog_play_tone(p, index, ANALOG_TONE_CONGESTION);
 					analog_wait_event(p);
@@ -1796,7 +1815,7 @@
 					analog_unalloc_sub(p, ANALOG_SUB_THREEWAY);
 					p->owner = p->subs[ANALOG_SUB_REAL].owner;
 					ast_hangup(chan);
-					return NULL;
+					goto quit;
 				}					
 #endif
 			} else if (!ast_canmatch_extension(chan, chan->context, exten, 1, chan->cid.cid_num) &&
@@ -1835,7 +1854,7 @@
 						ast_log(LOG_WARNING, "DTMFCID timed out waiting for ring. "
 							"Exiting simple switch\n");
 						ast_hangup(chan);
-						return NULL;
+						goto quit;
 					} 
 					f = ast_read(chan);
 					if (!f)
@@ -1883,7 +1902,7 @@
 							ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
 							callerid_free(cs);
 							ast_hangup(chan);
-							return NULL;
+							goto quit;
 						}
 						if (i & DAHDI_IOMUX_SIGEVENT) {
 							res = dahdi_get_event(p->subs[index].dfd);
@@ -1907,7 +1926,7 @@
 									ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
 									callerid_free(cs);
 									ast_hangup(chan);
-									return NULL;
+									goto quit;
 								}
 								break;
 							}
@@ -1950,12 +1969,12 @@
 							ast_log(LOG_WARNING, "CID timed out waiting for ring. "
 								"Exiting simple switch\n");
 							ast_hangup(chan);
-							return NULL;
+							goto quit;
 						} 
 						if (!(f = ast_read(chan))) {
 							ast_log(LOG_WARNING, "Hangup received waiting for ring. Exiting simple switch\n");
 							ast_hangup(chan);
-							return NULL;
+							goto quit;
 						}
 						ast_frfree(f);
 						if (chan->_state == AST_STATE_RING ||
@@ -1978,7 +1997,7 @@
 					"restarted by the actual ring.\n", 
 					chan->name);
 				ast_hangup(chan);
-				return NULL;
+				goto quit;
 			}
 		} else if (p->use_callerid && p->cid_start == ANALOG_CID_START_RING) {
 			int timeout = 10000;  /* Ten seconds */
@@ -2001,7 +2020,7 @@
 							ast_debug(1, "Hanging up due to polarity reversal on channel %d while detecting callerid\n", p->channel);
 							p->polarity = POLARITY_IDLE;
 							ast_hangup(chan);
-							return NULL;
+							goto quit;
 						} else if (ev != ANALOG_EVENT_NONE) {
 							break;
 						}
@@ -2049,7 +2068,7 @@
 						ast_log(LOG_WARNING, "I/O MUX failed: %s\n", strerror(errno));
 						callerid_free(cs);
 						ast_hangup(chan);
-						return NULL;
+						goto quit;
 					}
 					if (i & DAHDI_IOMUX_SIGEVENT) {
 						res = dahdi_get_event(p->subs[index].dfd);
@@ -2060,7 +2079,7 @@
 							p->polarity = POLARITY_IDLE;
 							callerid_free(cs);
 							ast_hangup(chan);
-							return NULL;
+							goto quit;
 						}
 						res = 0;
 						/* Let us detect callerid when the telco uses distinctive ring */
@@ -2080,7 +2099,7 @@
 								ast_log(LOG_WARNING, "read returned error: %s\n", strerror(errno));
 								callerid_free(cs);
 								ast_hangup(chan);
-								return NULL;
+								goto quit;
 							}
 							break;
 						}
@@ -2141,7 +2160,7 @@
 			ast_hangup(chan);
 			ast_log(LOG_WARNING, "PBX exited non-zero\n");
 		}
-		return NULL;
+		goto quit;
 	default:
 		ast_log(LOG_WARNING, "Don't know how to handle simple switch with signalling %s on channel %d\n", analog_sigtype_to_str(p->sig), p->channel);
 		res = analog_play_tone(p, index, ANALOG_TONE_CONGESTION);
@@ -2152,6 +2171,8 @@
 	if (res < 0)
 			ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", p->channel);
 	ast_hangup(chan);
+quit:
+	analog_decrease_ss_count(p);
 	return NULL;
 }
 

Modified: team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h
URL: http://svn.asterisk.org/svn-view/asterisk/team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h?view=diff&rev=196273&r1=196272&r2=196273
==============================================================================
--- team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h (original)
+++ team/jpeeler/asterisk-sigwork-trunk/channels/sig_analog.h Fri May 22 11:54:11 2009
@@ -165,6 +165,9 @@
 	int (* const check_for_conference)(void *pvt);
 	void (* const handle_notify_message)(struct ast_channel *chan, void *pvt, int cid_flags, int neon_mwievent);
 
+	/* callbacks for increasing and decreasing ss_thread_count, will handle locking and condition signal */
+	void (* const increase_ss_count)(void);
+	void (* const decrease_ss_count)(void);
 };
 
 




More information about the asterisk-commits mailing list