[asterisk-commits] tilghman: branch 1.6.2 r286527 - /branches/1.6.2/main/features.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 13 18:03:30 CDT 2010


Author: tilghman
Date: Mon Sep 13 18:03:26 2010
New Revision: 286527

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=286527
Log:
Refactor conversion to ast_poll() to fix callparking regression.

Modified:
    branches/1.6.2/main/features.c

Modified: branches/1.6.2/main/features.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.2/main/features.c?view=diff&rev=286527&r1=286526&r2=286527
==============================================================================
--- branches/1.6.2/main/features.c (original)
+++ branches/1.6.2/main/features.c Mon Sep 13 18:03:26 2010
@@ -309,7 +309,7 @@
 static struct ast_parkinglot *parkinglot_addref(struct ast_parkinglot *parkinglot);
 static void parkinglot_unref(struct ast_parkinglot *parkinglot);
 static void parkinglot_destroy(void *obj);
-int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *nfds, int *fs);
+int manage_parkinglot(struct ast_parkinglot *curlot, const struct pollfd *pfds, const int nfds, struct pollfd **new_pfds, int *new_nfds, int *fs);
 struct ast_parkinglot *find_parkinglot(const char *name);
 
 
@@ -3066,10 +3066,8 @@
 }
 
 /*! \brief Run management on parkinglots, called once per parkinglot */
-int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *nfds, int *ms)
-{
-	struct pollfd *new_fds = NULL;
-	int new_nfds = 0;
+int manage_parkinglot(struct ast_parkinglot *curlot, const struct pollfd *pfds, const int nfds, struct pollfd **new_pfds, int *new_nfds, int *ms)
+{
 	struct parkeduser *pu;
 	int res = 0;
 	char parkingslot[AST_MAX_EXTENSION];
@@ -3181,23 +3179,23 @@
 					continue;	/* nothing on this descriptor */
 				}
 
-				for (y = 0; y < *nfds; y++) {
-					if ((*pfds[y]).fd == chan->fds[x]) {
+				for (y = 0; y < nfds; y++) {
+					if (pfds[y].fd == chan->fds[x]) {
 						/* Found poll record! */
 						break;
 					}
 				}
-				if (y == *nfds) {
+				if (y == nfds) {
 					/* Not found */
 					continue;
 				}
 
-				if (!((*pfds[y]).revents & (POLLIN | POLLERR))) {
+				if (!(pfds[y].revents & (POLLIN | POLLERR))) {
 					/* Next x */
 					continue;
 				}
 
-				if ((*pfds[y]).revents & POLLERR) {
+				if (pfds[y].revents & POLLERR) {
 					ast_set_flag(chan, AST_FLAG_EXCEPTION);
 				} else {
 					ast_clear_flag(chan, AST_FLAG_EXCEPTION);
@@ -3243,15 +3241,15 @@
 			if (x >= AST_MAX_FDS) {
 std:			for (x = 0; x < AST_MAX_FDS; x++) {	/* mark fds for next round */
 					if (chan->fds[x] > -1) {
-						void *tmp = ast_realloc(new_fds, (new_nfds + 1) * sizeof(*new_fds));
+						void *tmp = ast_realloc(*new_pfds, (*new_nfds + 1) * sizeof(struct pollfd));
 						if (!tmp) {
 							continue;
 						}
-						new_fds = tmp;
-						new_fds[new_nfds].fd = chan->fds[x];
-						new_fds[new_nfds].events = POLLIN | POLLERR;
-						new_fds[new_nfds].revents = 0;
-						new_nfds++;
+						*new_pfds = tmp;
+						new_pfds[*new_nfds]->fd = chan->fds[x];
+						new_pfds[*new_nfds]->events = POLLIN | POLLERR;
+						new_pfds[*new_nfds]->revents = 0;
+						(*new_nfds)++;
 					}
 				}
 				/* Keep track of our shortest wait */
@@ -3264,9 +3262,6 @@
 	AST_LIST_TRAVERSE_SAFE_END;
 	AST_LIST_UNLOCK(&curlot->parkings);
 
-	ast_free(*pfds);
-	*pfds = new_fds;
-	*nfds = new_nfds;
 	return res;
 }
 
@@ -3280,8 +3275,8 @@
 */
 static void *do_parking_thread(void *ignore)
 {
-	struct pollfd *pfds = NULL;
-	int nfds = 0;
+	struct pollfd *pfds = NULL, *new_pfds = NULL;
+	int nfds = 0, new_nfds = 0;
 
 	for (;;) {
 		struct ao2_iterator iter;
@@ -3290,10 +3285,17 @@
 		iter = ao2_iterator_init(parkinglots, 0);
 
 		while ((curlot = ao2_iterator_next(&iter))) {
-			manage_parkinglot(curlot, &pfds, &nfds, &ms);
+			manage_parkinglot(curlot, pfds, nfds, &new_pfds, &new_nfds, &ms);
 			ao2_ref(curlot, -1);
 		}
 		ao2_iterator_destroy(&iter);
+
+		/* Recycle */
+		ast_free(pfds);
+		pfds = new_pfds;
+		nfds = new_nfds;
+		new_pfds = NULL;
+		new_nfds = 0;
 
 		/* Wait for something to happen */
 		ast_poll(pfds, nfds, ms);




More information about the asterisk-commits mailing list