[asterisk-commits] russell: branch russell/chan_refcount r82299 - /team/russell/chan_refcount/main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 12 17:36:45 CDT 2007
Author: russell
Date: Wed Sep 12 17:36:45 2007
New Revision: 82299
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82299
Log:
Begin pulling in changes from ast_channel_refcount
Modified:
team/russell/chan_refcount/main/channel.c
Modified: team/russell/chan_refcount/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_refcount/main/channel.c?view=diff&rev=82299&r1=82298&r2=82299
==============================================================================
--- team/russell/chan_refcount/main/channel.c (original)
+++ team/russell/chan_refcount/main/channel.c Wed Sep 12 17:36:45 2007
@@ -66,6 +66,7 @@
#include "asterisk/threadstorage.h"
#include "asterisk/slinfactory.h"
#include "asterisk/audiohook.h"
+#include "asterisk/astobj2.h"
#ifdef HAVE_EPOLL
#include <sys/epoll.h>
@@ -110,11 +111,16 @@
};
/*! \brief the list of registered channel types */
-static AST_LIST_HEAD_NOLOCK_STATIC(backends, chanlist);
-
-/*! \brief the list of channels we have. Note that the lock for this list is used for
- both the channels list and the backends list. */
-static AST_RWLIST_HEAD_STATIC(channels, ast_channel);
+static AST_LIST_HEAD_STATIC(backends, chanlist);
+
+#ifdef LOW_MEMORY
+#define MAX_CHANNEL_BUCKETS 61
+#else
+#define MAX_CHANNEL_BUCKETS 1567
+#endif
+
+/*! \brief All active channels on the system */
+static struct ao2_container *channels;
/*! \brief map AST_CAUSE's to readable string representations
*
@@ -175,6 +181,8 @@
{
struct chanlist *cl;
struct ast_variable *var=NULL, *prev = NULL;
+
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE(&backends, cl, list) {
if (prev) {
if ((prev->next = ast_variable_new(cl->tech->type, cl->tech->description, "")))
@@ -184,6 +192,8 @@
prev = var;
}
}
+ AST_LIST_UNLOCK(&backends);
+
return var;
}
@@ -196,10 +206,8 @@
ast_cli(fd, FORMAT, "Type", "Description", "Devicestate", "Indications", "Transfer");
ast_cli(fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------");
- if (AST_RWLIST_RDLOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return -1;
- }
+
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE(&backends, cl, list) {
ast_cli(fd, FORMAT, cl->tech->type, cl->tech->description,
(cl->tech->devicestate) ? "yes" : "no",
@@ -207,8 +215,10 @@
(cl->tech->transfer) ? "yes" : "no");
count_chan++;
}
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
+
ast_cli(fd, "----------\n%d channel drivers registered.\n", count_chan);
+
return RESULT_SUCCESS;
#undef FORMAT
@@ -223,21 +233,16 @@
if (argc != 4)
return RESULT_SHOWUSAGE;
- if (AST_RWLIST_RDLOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return RESULT_FAILURE;
- }
-
+ AST_LIST_TRAVERSE(&backends);
AST_LIST_TRAVERSE(&backends, cl, list) {
if (!strncasecmp(cl->tech->type, argv[3], strlen(cl->tech->type))) {
break;
}
}
-
if (!cl) {
ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[3]);
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
return RESULT_FAILURE;
}
@@ -265,7 +270,8 @@
);
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
+
return RESULT_SUCCESS;
}
@@ -281,13 +287,15 @@
wordlen = strlen(word);
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE(&backends, cl, list) {
if (!strncasecmp(word, cl->tech->type, wordlen) && ++which > state) {
ret = ast_strdup(cl->tech->type);
break;
}
}
-
+ AST_LIST_UNLOCK(&backends);
+
return ret;
}
@@ -404,12 +412,11 @@
{
struct chanlist *chan;
- AST_RWLIST_WRLOCK(&channels);
-
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE(&backends, chan, list) {
if (!strcasecmp(tech->type, chan->tech->type)) {
ast_log(LOG_WARNING, "Already have a handler for type '%s'\n", tech->type);
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
return -1;
}
}
@@ -425,7 +432,8 @@
ast_verb(2, "Registered channel type '%s' (%s)\n", chan->tech->type, chan->tech->description);
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
+
return 0;
}
@@ -436,8 +444,7 @@
ast_debug(1, "Unregistering channel type '%s'\n", tech->type);
- AST_RWLIST_WRLOCK(&channels);
-
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
if (chan->tech == tech) {
AST_LIST_REMOVE_CURRENT(&backends, list);
@@ -447,8 +454,7 @@
}
}
AST_LIST_TRAVERSE_SAFE_END
-
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
}
/*! \brief Get handle to channel driver based on name */
@@ -457,19 +463,14 @@
struct chanlist *chanls;
const struct ast_channel_tech *ret = NULL;
- if (AST_RWLIST_RDLOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel tech list\n");
- return NULL;
- }
-
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE(&backends, chanls, list) {
if (!strcasecmp(name, chanls->tech->type)) {
ret = chanls->tech;
break;
}
}
-
- AST_RWLIST_UNLOCK(&channels);
+ AST_LIST_UNLOCK(&backends);
return ret;
}
@@ -3133,11 +3134,7 @@
cause = &foo;
*cause = AST_CAUSE_NOTDEFINED;
- if (AST_RWLIST_RDLOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return NULL;
- }
-
+ AST_LIST_LOCK(&backends);
AST_LIST_TRAVERSE(&backends, chan, list) {
if (strcasecmp(type, chan->tech->type))
continue;
@@ -3161,10 +3158,10 @@
/* no need to generate a Newchannel event here; it is done in the channel_alloc call */
return c;
}
+ AST_LIST_UNLOCK(&backends);
ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
*cause = AST_CAUSE_NOSUCHDRIVER;
- AST_RWLIST_UNLOCK(&channels);
return NULL;
}
More information about the asterisk-commits
mailing list