[asterisk-commits] jpeeler: branch jpeeler/dahdi-restart r134311 - /team/jpeeler/dahdi-restart/c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 29 17:41:59 CDT 2008


Author: jpeeler
Date: Tue Jul 29 17:41:58 2008
New Revision: 134311

URL: http://svn.digium.com/view/asterisk?view=rev&rev=134311
Log:
added support for restarting PRI channels, changed analog restart handling to be more efficient and stable

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=134311&r1=134310&r2=134311
==============================================================================
--- team/jpeeler/dahdi-restart/channels/chan_dahdi.c (original)
+++ team/jpeeler/dahdi-restart/channels/chan_dahdi.c Tue Jul 29 17:41:58 2008
@@ -3298,7 +3298,8 @@
 			p->pri = NULL;
 		}
 #endif
-		restart_monitor();
+		if (restart_pending != 1)
+			restart_monitor();
 	}
 
 	p->callwaitingrepeat = 0;
@@ -11930,7 +11931,51 @@
 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");
+
+	p = iflist;
+    while (p) {
+        if (p->owner)
+            ast_softhangup(p->owner, AST_SOFTHANGUP_EXPLICIT);
+        p = p->next;
+    }
+
+	#if defined(HAVE_PRI)
+    for (i = 0; i < NUM_SPANS; i++) {
+		if (pris[i].master && (pris[i].master != AST_PTHREADT_NULL)) {
+			cancel_code = pthread_cancel(pris[i].master);
+			pthread_kill(pris[i].master, SIGURG);
+			ast_log(LOG_WARNING, "Waiting to join thread of span %d with pid=%p cancel_code=%d\n", i, (void *) pris[i].master, cancel_code);
+            pthread_join(pris[i].master, NULL);
+			ast_log(LOG_WARNING, "Joined thread of span %d\n", i);
+		}
+		for (j = 0; j < pris[i].numchans - 1; j++) {
+			struct dahdi_pvt *p = pris[i].pvts[j];
+			if (p) {
+				if (p->call) {
+					if (p->pri && p->pri->pri) {
+						pri_hangup(p->pri->pri, p->call, -1);
+						pri_destroycall(p->pri->pri, p->call);
+						p->call = NULL;
+					}
+					if (p->realcall) {
+						pri_hangup_all(p->realcall, &pris[i]);
+					} else if (p->owner)
+						p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
+				}
+			}
+		}
+/*
+		for (j = 0; j < NUM_DCHANS; j++) {
+        	dahdi_close(pris[i].fds[j]);
+		}
+*/
+    }
+	#endif /* HAVE_PRI */
+
+	restart_pending = 1;
 
     ast_mutex_lock(&monlock);
     if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) {
@@ -11939,7 +11984,7 @@
         retval = pthread_kill(monitor_thread, SIGURG);
         retval = pthread_join(monitor_thread, NULL);
     }
-	monitor_thread = AST_PTHREADT_NULL; /* restart thread */
+	monitor_thread = AST_PTHREADT_NULL; /* restart thread once appropriate */
 
 	ast_mutex_lock(&mwi_thread_lock);
 	while (mwi_thread_count > 0) {
@@ -11947,10 +11992,24 @@
 		ast_cond_wait(&mwi_thread_complete, &mwi_thread_lock);
 	}
 	ast_mutex_unlock(&mwi_thread_lock);
-	restart_pending = 1;
+
+	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;
+			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) {
-		int x = DAHDI_FLASH;
-		ioctl(iflist->subs[SUB_REAL].zfd, DAHDI_HOOK, &x); /* important to create an event for dahdi_wait_event to register so that all ss_threads terminate */		
 		ast_debug(1, "Destroying DAHDI channel no. %d\n", iflist->channel);
 		/* Also updates iflist: */
 		destroy_channel(NULL, iflist, 1);
@@ -11959,19 +12018,44 @@
 
     ast_mutex_unlock(&monlock);
 
-	ast_mutex_lock(&ss_thread_lock);
-	while (ss_thread_count > 0) {
-		ast_debug(2, "Waiting on ss_thread to finish\n");
-		ast_cond_wait(&ss_thread_complete, &ss_thread_lock);
-	}
+	#ifdef HAVE_PRI
+	for (i = 0; i < NUM_SPANS; i++) {
+		for (j = 0; j < NUM_DCHANS; j++)
+        	dahdi_close(pris[i].fds[j]);
+	}
+
+	memset(pris, 0, sizeof(pris));
+	for (i = 0; i < NUM_SPANS; i++) {
+		ast_mutex_init(&pris[i].lock);
+		pris[i].offset = -1;
+		pris[i].master = AST_PTHREADT_NULL;
+		for (j = 0; j < NUM_DCHANS; j++)
+			pris[i].fds[j] = -1;
+	}
+	pri_set_error(dahdi_pri_error);
+	pri_set_message(dahdi_pri_message);
+	#endif
+	#ifdef HAVE_SS7
+	memset(linksets, 0, sizeof(linksets));
+	for (i = 0; i < NUM_SPANS; i++) {
+		ast_mutex_init(&linksets[i].lock);
+		linksets[i].master = AST_PTHREADT_NULL;
+		for (j = 0; j < NUM_DCHANS; j++)
+			linksets[i].fds[j] = -1;
+	}
+	ss7_set_error(dahdi_ss7_error);
+	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;
+		//restart_pending = 0;
 		return 1;
 	}
 	ast_mutex_unlock(&ss_thread_lock);
-	restart_pending = 0;
+	//restart_pending = 0;
 	return 0;
 }
 
@@ -14464,7 +14548,7 @@
 	/* It's a little silly to lock it, but we mind as well just to be sure */
 	ast_mutex_lock(&iflock);
 #ifdef HAVE_PRI
-	if (!reload) {
+	if (reload != 1) {
 		/* Process trunkgroups first */
 		v = ast_variable_browse(cfg, "trunkgroups");
 		while (v) {
@@ -14594,7 +14678,7 @@
 	ast_mutex_unlock(&iflock);
 
 #ifdef HAVE_PRI
-	if (!reload) {
+	if (reload != 1) {
 		int x;
 		for (x = 0; x < NUM_SPANS; x++) {
 			if (pris[x].pvts[0]) {
@@ -14608,7 +14692,7 @@
 	}
 #endif
 #ifdef HAVE_SS7
-	if (!reload) {
+	if (reload != 1) {
 		int x;
 		for (x = 0; x < NUM_SPANS; x++) {
 			if (linksets[x].ss7) {




More information about the asterisk-commits mailing list