aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-09-13 23:03:26 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-09-13 23:03:26 +0000
commit29645ac80d581c37dfbaa9a32879a5d5f4d17e1e (patch)
tree51dfeda040421e49205e9fb238b50fdda58916e1
parentc50499eb8875d64d1b93b6d80d7f0b974262fc56 (diff)
Refactor conversion to ast_poll() to fix callparking regression.
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@286527 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/features.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/main/features.c b/main/features.c
index 8ebd44bbf..b1ab5a022 100644
--- a/main/features.c
+++ b/main/features.c
@@ -309,7 +309,7 @@ static void *dial_features_duplicate(void *data)
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 @@ static char *callback_dialoptions(struct ast_flags *features_callee, struct ast_
}
/*! \brief Run management on parkinglots, called once per parkinglot */
-int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *nfds, int *ms)
+int manage_parkinglot(struct ast_parkinglot *curlot, const struct pollfd *pfds, const int nfds, struct pollfd **new_pfds, int *new_nfds, int *ms)
{
- struct pollfd *new_fds = NULL;
- int new_nfds = 0;
struct parkeduser *pu;
int res = 0;
char parkingslot[AST_MAX_EXTENSION];
@@ -3181,23 +3179,23 @@ int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *
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 @@ int manage_parkinglot(struct ast_parkinglot *curlot, struct pollfd **pfds, int *
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 @@ std: for (x = 0; x < AST_MAX_FDS; x++) { /* mark fds for next round */
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 @@ std: for (x = 0; x < AST_MAX_FDS; x++) { /* mark fds for next round */
*/
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,11 +3285,18 @@ static void *do_parking_thread(void *ignore)
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);
pthread_testcancel();