[svn-commits] branch 1.2 r30546 - /branches/1.2/apps/app_queue.c
svn-commits at lists.digium.com
svn-commits at lists.digium.com
Fri May 26 10:09:52 MST 2006
Author: bweschke
Date: Fri May 26 12:09:51 2006
New Revision: 30546
URL: http://svn.digium.com/view/asterisk?rev=30546&view=rev
Log:
A new way to try and deal with deadlocks that occur in app_queue at present. Using this approach, we only manipulate the main queue mutexes when we get a dev state change on a device that is actually a member of a queue. Backported from /trunk for the "bug fix".
Modified:
branches/1.2/apps/app_queue.c
Modified: branches/1.2/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_queue.c?rev=30546&r1=30545&r2=30546&view=diff
==============================================================================
--- branches/1.2/apps/app_queue.c (original)
+++ branches/1.2/apps/app_queue.c Fri May 26 12:09:51 2006
@@ -303,6 +303,13 @@
struct member *next; /*!< Next member */
};
+struct ast_member_interfaces {
+ char interface[80];
+ AST_LIST_ENTRY(ast_member_interfaces) list; /*!< Next call queue */
+};
+
+static AST_LIST_HEAD_STATIC(interfaces, ast_member_interfaces);
+
/* values used in multi-bit flags in ast_call_queue */
#define QUEUE_EMPTY_NORMAL 1
#define QUEUE_EMPTY_STRICT 2
@@ -458,6 +465,7 @@
struct ast_call_queue *q;
struct statechange *sc = data;
struct member *cur;
+ struct ast_member_interfaces *curint;
char *loc;
char *technology;
@@ -470,36 +478,50 @@
free(sc);
return NULL;
}
- if (option_debug)
- ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state));
- ast_mutex_lock(&qlock);
- for (q = queues; q; q = q->next) {
- ast_mutex_lock(&q->lock);
- cur = q->members;
- while(cur) {
- if (!strcasecmp(sc->dev, cur->interface)) {
- if (cur->status != sc->state) {
- cur->status = sc->state;
- if (!q->maskmemberstatus) {
- manager_event(EVENT_FLAG_AGENT, "QueueMemberStatus",
- "Queue: %s\r\n"
- "Location: %s\r\n"
- "Membership: %s\r\n"
- "Penalty: %d\r\n"
- "CallsTaken: %d\r\n"
- "LastCall: %d\r\n"
- "Status: %d\r\n"
- "Paused: %d\r\n",
- q->name, cur->interface, cur->dynamic ? "dynamic" : "static",
- cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
+
+ AST_LIST_LOCK(&interfaces);
+ AST_LIST_TRAVERSE(&interfaces, curint, list) {
+ if (!strcasecmp(curint->interface, sc->dev))
+ break;
+ }
+ AST_LIST_UNLOCK(&interfaces);
+
+ if (curint) {
+
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s)\n", technology, loc, sc->state, devstate2str(sc->state));
+ ast_mutex_lock(&qlock);
+ for (q = queues; q; q = q->next) {
+ ast_mutex_lock(&q->lock);
+ cur = q->members;
+ while(cur) {
+ if (!strcasecmp(sc->dev, cur->interface)) {
+ if (cur->status != sc->state) {
+ cur->status = sc->state;
+ if (!q->maskmemberstatus) {
+ manager_event(EVENT_FLAG_AGENT, "QueueMemberStatus",
+ "Queue: %s\r\n"
+ "Location: %s\r\n"
+ "Membership: %s\r\n"
+ "Penalty: %d\r\n"
+ "CallsTaken: %d\r\n"
+ "LastCall: %d\r\n"
+ "Status: %d\r\n"
+ "Paused: %d\r\n",
+ q->name, cur->interface, cur->dynamic ? "dynamic" : "static",
+ cur->penalty, cur->calls, (int)cur->lastcall, cur->status, cur->paused);
+ }
}
}
- }
- cur = cur->next;
- }
- ast_mutex_unlock(&q->lock);
- }
- ast_mutex_unlock(&qlock);
+ cur = cur->next;
+ }
+ ast_mutex_unlock(&q->lock);
+ }
+ ast_mutex_unlock(&qlock);
+ } else {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Device '%s/%s' changed to state '%d' (%s) but we don't care because they're not a member of any queue.\n", technology, loc, sc->state, devstate2str(sc->state));
+ }
free(sc);
return NULL;
}
@@ -594,6 +616,89 @@
q->callsabandoned = 0;
q->callscompletedinsl = 0;
q->wrapuptime = 0;
+}
+
+static int add_to_interfaces(char *interface)
+{
+ struct ast_member_interfaces *curint, *newint;
+
+ AST_LIST_LOCK(&interfaces);
+ AST_LIST_TRAVERSE(&interfaces, curint, list) {
+ if (!strcasecmp(curint->interface, interface))
+ break;
+ }
+
+ if (!curint) {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Adding %s to the list of interfaces that make up all of our queue members.\n", interface);
+
+ if ((newint = malloc(sizeof(*newint)))) {
+ memset(newint, 0, sizeof(*newint));
+ ast_copy_string(newint->interface, interface, sizeof(newint->interface));
+ AST_LIST_INSERT_HEAD(&interfaces, newint, list);
+ }
+ }
+ AST_LIST_UNLOCK(&interfaces);
+
+ return 0;
+}
+
+static int interface_exists_global(char *interface)
+{
+ struct ast_call_queue *q;
+ struct member *mem;
+ int ret = 0;
+
+ ast_mutex_lock(&qlock);
+ for (q = queues; q && !ret; q = q->next) {
+ ast_mutex_lock(&q->lock);
+ mem = q->members;
+ while(mem) {
+ if (!strcasecmp(interface, mem->interface)) {
+ ret = 1;
+ break;
+ }
+ }
+ ast_mutex_unlock(&q->lock);
+ }
+ ast_mutex_unlock(&qlock);
+
+ return ret;
+}
+
+
+static int remove_from_interfaces(char *interface)
+{
+ struct ast_member_interfaces *curint;
+
+ AST_LIST_LOCK(&interfaces);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&interfaces, curint, list) {
+ if (!strcasecmp(curint->interface, interface) && !interface_exists_global(interface)) {
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Removing %s from the list of interfaces that make up all of our queue members.\n", interface);
+ AST_LIST_REMOVE_CURRENT(&interfaces, list);
+ free(curint);
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ AST_LIST_UNLOCK(&interfaces);
+
+ return 0;
+}
+
+static void clear_and_free_interfaces(void)
+{
+ struct ast_member_interfaces *curint;
+
+ AST_LIST_LOCK(&interfaces);
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&interfaces, curint, list) {
+ AST_LIST_REMOVE_CURRENT(&interfaces, list);
+ free(curint);
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ AST_LIST_UNLOCK(&interfaces);
+
+ return;
}
/*! \brief Configure a queue parameter.
@@ -746,6 +851,7 @@
m = create_queue_member(interface, penalty, 0);
if (m) {
m->dead = 0;
+ add_to_interfaces(interface);
if (prev_m) {
prev_m->next = m;
} else {
@@ -770,6 +876,7 @@
prev->next = next;
else
q->members = next;
+ remove_from_interfaces(curm->interface);
free(curm);
} else
prev = curm;
@@ -917,6 +1024,7 @@
} else {
q->members = next_m;
}
+ remove_from_interfaces(m->interface);
free(m);
} else {
prev_m = m;
@@ -1033,9 +1141,9 @@
qe->chan->cid.cid_num ? qe->chan->cid.cid_num : "unknown",
qe->chan->cid.cid_name ? qe->chan->cid.cid_name : "unknown",
q->name, qe->pos, q->count );
-#if 0
-ast_log(LOG_NOTICE, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos );
-#endif
+
+ if (option_debug)
+ ast_log(LOG_DEBUG, "Queue '%s' Join, Channel '%s', Position '%d'\n", q->name, qe->chan->name, qe->pos );
}
ast_mutex_unlock(&q->lock);
ast_mutex_unlock(&qlock);
@@ -2421,6 +2529,8 @@
}
ast_mutex_unlock(&q->lock);
}
+ if (res == RES_OKAY)
+ remove_from_interfaces(interface);
ast_mutex_unlock(&qlock);
return res;
}
@@ -2440,6 +2550,9 @@
if (q) {
ast_mutex_lock(&q->lock);
if (interface_exists(q, interface) == NULL) {
+
+ add_to_interfaces(interface);
+
new_member = create_queue_member(interface, penalty, paused);
if (new_member != NULL) {
@@ -3251,6 +3364,8 @@
}
free(cur);
} else {
+ /* Add them to the master int list if necessary */
+ add_to_interfaces(interface);
newm->next = q->members;
q->members = newm;
}
@@ -3275,6 +3390,7 @@
q->members = cur->next;
newm = cur;
}
+ remove_from_interfaces(cur->interface);
}
}
if (!new)
@@ -3827,6 +3943,7 @@
{
int res;
+ clear_and_free_interfaces();
res = ast_cli_unregister(&cli_show_queue);
res |= ast_cli_unregister(&cli_show_queues);
res |= ast_cli_unregister(&cli_add_queue_member);
More information about the svn-commits
mailing list