[asterisk-commits] moy: branch moy/mfcr2-1.4 r235811 - /team/moy/mfcr2-1.4/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 20 21:42:45 CST 2009


Author: moy
Date: Sun Dec 20 21:42:43 2009
New Revision: 235811

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=235811
Log:
better fix to polling bug

Modified:
    team/moy/mfcr2-1.4/channels/chan_dahdi.c

Modified: team/moy/mfcr2-1.4/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/moy/mfcr2-1.4/channels/chan_dahdi.c?view=diff&rev=235811&r1=235810&r2=235811
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_dahdi.c Sun Dec 20 21:42:43 2009
@@ -9475,10 +9475,10 @@
 	   I think do_monitor() could be leaking, since it
 	   could be cancelled at any time and is not
 	   using thread keys, why?, */
-	struct pollfd pollers[sizeof(mfcr2->pvts)];
+	struct pollfd pollers[mfcr2->numchans];
 	int maxsleep = 20;
 	int res = 0;
-	int i = 0, j = 0;
+	int i = 0;
 	int pollsize = 0;
 	int oldstate = 0;
 	int was_idle = 0;
@@ -9487,6 +9487,7 @@
 	   get current line state */
 	for (i = 0; i < mfcr2->numchans; i++) {
 		p = mfcr2->pvts[i];
+		pollers[i].fd = mfcr2->pvts[i]->subs[SUB_REAL].dfd;
 		if (openr2_chan_set_idle(p->r2chan)) {
 			ast_log(LOG_ERROR, "Failed to set channel %d in IDLE\n", p->channel);
 		} else {
@@ -9502,6 +9503,8 @@
 		   the module is loaded */
 		pollsize = 0;
 		for (i = 0; i < mfcr2->numchans; i++) {
+			pollers[i].events = 0;
+			pollers[i].revents = 0;
 			if (mfcr2->pvts[i]->owner) {
 				continue;
 			}
@@ -9511,9 +9514,7 @@
 				break;
 			}
 			openr2_chan_enable_read(mfcr2->pvts[i]->r2chan);
-			pollers[pollsize].events = POLLIN | POLLPRI;
-			pollers[pollsize].revents = 0;
-			pollers[pollsize].fd = mfcr2->pvts[i]->subs[SUB_REAL].dfd;
+			pollers[i].events = POLLIN | POLLPRI;
 			pollsize++;
 		}
 		if (quit_loop) {
@@ -9533,7 +9534,7 @@
 		/* probably poll() is a valid cancel point, lets just be on the safe side
 		   by calling pthread_testcancel */
 		pthread_testcancel();
-		res = poll(pollers, pollsize, maxsleep);
+		res = poll(pollers, mfcr2->numchans, maxsleep);
 		pthread_testcancel();
 		if ((res < 0) && (errno != EINTR)) {
 			ast_log(LOG_ERROR, "going out, poll failed: %s\n", strerror(errno));
@@ -9541,17 +9542,9 @@
 		} 
 		/* do we want to allow to cancel while processing events? */
 		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
-		for (i = 0; i < pollsize; i++) {
-			if (!(pollers[i].revents & POLLPRI) && !(pollers[i].revents & POLLIN)) {
-				continue;
-			}
-			/* search the channel for this fd */
-			for (j = 0; j < mfcr2->numchans; j++) {
-				if (mfcr2->pvts[j]->subs[SUB_REAL].dfd != pollers[i].fd) {
-					continue;
-				}
-				openr2_chan_process_event(mfcr2->pvts[j]->r2chan);
-				break;
+		for (i = 0; i < mfcr2->numchans; i++) {
+			if ((pollers[i].revents & POLLPRI) || (pollers[i].revents & POLLIN)) {
+				openr2_chan_process_event(mfcr2->pvts[i]->r2chan);
 			}
 		}
 		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);




More information about the asterisk-commits mailing list