[svn-commits] jpeeler: branch jpeeler/dahdi-restart r136848 - /team/jpeeler/dahdi-restart/c...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 8 14:26:06 CDT 2008


Author: jpeeler
Date: Fri Aug  8 14:26:05 2008
New Revision: 136848

URL: http://svn.digium.com/view/asterisk?view=rev&rev=136848
Log:
cleanup some unneeded code

Modified:
    team/jpeeler/dahdi-restart/channels/chan_dahdi.c

Modified: team/jpeeler/dahdi-restart/channels/chan_dahdi.c
URL: http://svn.digium.com/view/asterisk/team/jpeeler/dahdi-restart/channels/chan_dahdi.c?view=diff&rev=136848&r1=136847&r2=136848
==============================================================================
--- team/jpeeler/dahdi-restart/channels/chan_dahdi.c (original)
+++ team/jpeeler/dahdi-restart/channels/chan_dahdi.c Fri Aug  8 14:26:05 2008
@@ -282,7 +282,6 @@
 static ast_mutex_t ss_thread_lock;
 static int mwi_thread_count = 0;
 static int ss_thread_count = 0;
-static int restart_pending = 0;
 static int num_restart_pending = 0;
 
 static int restart_monitor(void);
@@ -2878,13 +2877,9 @@
 	}
 
 	ast_mutex_lock(&iflock);
-ast_log(LOG_WARNING, "Num of channels = %d\n", ast_active_channels());
 	/* Destroy all the interfaces and free their memory */
 	p = iflist;
 	while (p) {
-		//while(p->owner)
-		//	;
-
 /*
 if (p->owner) {
 	for (x = 0; x < 10; x++) {
@@ -2901,8 +2896,6 @@
 		/* Close the DAHDI thingy */
 		if (p->subs[SUB_REAL].zfd > -1)
 			dahdi_close(p->subs[SUB_REAL].zfd);
-		if (!p)
-			printf("Very bad\n");
 		pl = p;
 		p = p->next;
 		x = pl->channel;
@@ -3371,7 +3364,7 @@
 			p->pri = NULL;
 		}
 #endif
-		if (restart_pending != 1)
+		if (num_restart_pending == 0)
 			restart_monitor();
 	}
 
@@ -5296,9 +5289,6 @@
 	void *readbuf;
 	struct ast_frame *f;
 
-	if (restart_pending == 1)
-		return NULL;
-
 	while (ast_mutex_trylock(&p->lock)) {
 		CHANNEL_DEADLOCK_AVOIDANCE(ast);
 	}
@@ -5619,9 +5609,6 @@
 	struct dahdi_pvt *p = ast->tech_pvt;
 	int res;
 	int index;
-
-	if (restart_pending == 1)
-		return -1;
 
 	index = dahdi_get_index(ast, p, 0);
 	if (index < 0) {
@@ -12010,27 +11997,22 @@
 	return ( RESULT_SUCCESS == ret ) ? CLI_SUCCESS : CLI_FAILURE;
 }
 
-static int setup_dahdi(int reload);
-static int dahdi_restart(void)
-{
-	int i, j, cancel_code;
+static void dahdi_softhangup_all(void)
+{
 	struct dahdi_pvt *p;
-	ast_verb(1, "Destroying channels and reloading DAHDI configuration.\n");
-
-#if 1
-retry1:
+retry:
 	ast_mutex_lock(&iflock);
     for (p = iflist; p; p = p->next) {
 		ast_mutex_lock(&p->lock);
         if (p->owner && !p->restartpending) {
 			if (ast_channel_trylock(p->owner)) {
-			ast_log(LOG_WARNING, "Avoiding deadlock\n");
+				ast_debug(3, "Avoiding deadlock\n");
 				/* Avoid deadlock since you're not supposed to lock iflock or pvt before a channel */
 				ast_mutex_unlock(&p->lock);
 				ast_mutex_unlock(&iflock);
-				goto retry1;
-			}
-			ast_log(LOG_WARNING, "1: Softhanging up on %s\n", p->owner->name);
+				goto retry;
+			}
+			ast_debug(3, "Softhanging up on %s\n", p->owner->name);
 			ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_EXPLICIT);
 			p->restartpending = 1;
 			num_restart_pending++;
@@ -12039,8 +12021,17 @@
 		ast_mutex_unlock(&p->lock);
     }
 	ast_mutex_unlock(&iflock);
-	ast_verb(1, "Initial softhangup of all DAHDI channels complete.\n");
-#endif
+}
+
+static int setup_dahdi(int reload);
+static int dahdi_restart(void)
+{
+	int i, j, cancel_code;
+	struct dahdi_pvt *p;
+
+	ast_verb(1, "Destroying channels and reloading DAHDI configuration.\n");
+	dahdi_softhangup_all();
+	ast_verb(2, "Initial softhangup of all DAHDI channels complete.\n");
 
 	#if defined(HAVE_PRI)
     for (i = 0; i < NUM_SPANS; i++) {
@@ -12111,8 +12102,6 @@
 	}
 	#endif /* HAVE_SS7 */
 
-	restart_pending = 1;
-
     ast_mutex_lock(&monlock);
     if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
 		int retval;
@@ -12120,7 +12109,7 @@
         retval = pthread_kill(monitor_thread, SIGURG);
         retval = pthread_join(monitor_thread, NULL);
     }
-	monitor_thread = AST_PTHREADT_NULL; /* restart thread once appropriate */
+	monitor_thread = AST_PTHREADT_NULL; /* prepare to restart thread in setup_dahdi once channels are reconfigured */
 
 	ast_mutex_lock(&mwi_thread_lock);
 	while (mwi_thread_count > 0) {
@@ -12131,65 +12120,23 @@
 
 	ast_mutex_lock(&ss_thread_lock);
 	while (ss_thread_count > 0) { /* let ss_threads finish and run dahdi_hangup before dahvi_pvts are destroyed */
-		ast_debug(2, "Waiting on ss_thread to finish\n");
-
-		p = iflist;
-    	while (p) {
-			int x = DAHDI_FLASH;
+		int x = DAHDI_FLASH;
+		ast_debug(3, "Waiting on ss_thread to finish\n");
+
+		for (p = iflist; p; p = p->next) {
 			if (p->owner)
 				ioctl(p->subs[SUB_REAL].zfd, DAHDI_HOOK, &x); /* important to create an event for dahdi_wait_event to register so that all ss_threads terminate */		
-        	p = p->next;
     	}
-
 		ast_cond_wait(&ss_thread_complete, &ss_thread_lock);
 	}
 
-	//restart_pending = 1;
-	/*
-	while (iflist) {
-		ast_debug(1, "Destroying DAHDI channel no. %d\n", iflist->channel);
-		// Also updates iflist: 
-		destroy_channel(NULL, iflist, 1);
-	}
-	*/
-
-#if 1
 	/* ensure any created channels before monitor threads were stopped are hungup */
-retry:
-	ast_mutex_lock(&iflock);
-    for (p = iflist; p; p = p->next) {
-		ast_mutex_lock(&p->lock);
-        if (p->owner && !p->restartpending) {
-			if (ast_channel_trylock(p->owner)) {
-				/* Avoid deadlock since you're not supposed to lock iflock or pvt before a channel */
-			ast_log(LOG_WARNING, "Avoiding deadlock\n");
-				ast_mutex_unlock(&p->lock);
-				ast_mutex_unlock(&iflock);
-				goto retry;
-			}
-			ast_log(LOG_WARNING, "2: Softhanging up on %s\n", p->owner->name);
-			ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_EXPLICIT);
-			p->restartpending = 1;
-			num_restart_pending++;
-			ast_channel_unlock(p->owner);
-		}
-		ast_mutex_unlock(&p->lock);
-    }
-	ast_mutex_unlock(&iflock);
-	ast_verb(1, "Final softhangup of all DAHDI channels complete.\n");
-#endif
-
-
+	dahdi_softhangup_all();
+	ast_verb(2, "Final softhangup of all DAHDI channels complete.\n");
 	destroy_all_channels();
-ast_log(LOG_WARNING, "After destruction: Num of channels = %d\n", ast_active_channels());
-	ast_debug(1, "Channels destroyed. Now re-reading config.\n");
-//while (ast_active_channels())
-//	ast_log(LOG_DEBUG, "Kept on waiting\n");
+	ast_debug(1, "Channels destroyed. Now re-reading config. %d active channels remaining.\n", ast_active_channels());
 
     ast_mutex_unlock(&monlock);
-
-	//while (ast_active_channels())
-	//	ast_log(LOG_WARNING, "Num of channels = %d\n", ast_active_channels());
 
 	#ifdef HAVE_PRI
 	for (i = 0; i < NUM_SPANS; i++) {
@@ -12225,16 +12172,12 @@
 	ss7_set_message(dahdi_ss7_message);
 	#endif /* HAVE_SS7 */
 
-	restart_pending = 0;
 	if (setup_dahdi(2) != 0) {
 		ast_log(LOG_WARNING, "Reload channels from dahdi config failed!\n");
 		ast_mutex_unlock(&ss_thread_lock);
-		//restart_pending = 0;
 		return 1;
 	}
 	ast_mutex_unlock(&ss_thread_lock);
-	//restart_pending = 0;
-ast_log(LOG_WARNING, "End: Num of channels = %d\n", ast_active_channels());
 	return 0;
 }
 
@@ -13662,6 +13605,7 @@
 	monitor_thread = AST_PTHREADT_STOP;
 	ast_mutex_unlock(&monlock);
 
+	/* jpeeler TODO: remember that num_restart_pending is set in dahdi_softhangup_all */
 	destroy_all_channels();
 #if defined(HAVE_PRI)
 	for (i = 0; i < NUM_SPANS; i++) {




More information about the svn-commits mailing list