[asterisk-commits] file: branch file/chanlist r51218 -
/team/file/chanlist/main/channel.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Jan 17 22:45:02 MST 2007
Author: file
Date: Wed Jan 17 23:45:01 2007
New Revision: 51218
URL: http://svn.digium.com/view/asterisk?view=rev&rev=51218
Log:
Change channel list to use read/write locks.
Modified:
team/file/chanlist/main/channel.c
Modified: team/file/chanlist/main/channel.c
URL: http://svn.digium.com/view/asterisk/team/file/chanlist/main/channel.c?view=diff&rev=51218&r1=51217&r2=51218
==============================================================================
--- team/file/chanlist/main/channel.c (original)
+++ team/file/chanlist/main/channel.c Wed Jan 17 23:45:01 2007
@@ -117,7 +117,7 @@
/*! 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_LIST_HEAD_STATIC(channels, ast_channel);
+static AST_RWLIST_HEAD_STATIC(channels, ast_channel);
/*! map AST_CAUSE's to readable string representations */
const struct ast_cause {
@@ -195,19 +195,19 @@
ast_cli(fd, FORMAT, "Type", "Description", "Devicestate", "Indications", "Transfer");
ast_cli(fd, FORMAT, "----------", "-----------", "-----------", "-----------", "--------");
- if (AST_LIST_LOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return -1;
- }
- AST_LIST_TRAVERSE(&backends, cl, list) {
+
+ AST_RWLIST_RDLOCK(&channels);
+ AST_RWLIST_TRAVERSE(&backends, cl, list) {
ast_cli(fd, FORMAT, cl->tech->type, cl->tech->description,
(cl->tech->devicestate) ? "yes" : "no",
(cl->tech->indicate) ? "yes" : "no",
(cl->tech->transfer) ? "yes" : "no");
count_chan++;
}
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
+
ast_cli(fd, "----------\n%d channel drivers registered.\n", count_chan);
+
return RESULT_SUCCESS;
#undef FORMAT
@@ -220,22 +220,18 @@
if (argc != 3)
return RESULT_SHOWUSAGE;
-
- if (AST_LIST_LOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return RESULT_FAILURE;
- }
-
- AST_LIST_TRAVERSE(&backends, cl, list) {
+
+ AST_RWLIST_RDLOCK(&channels);
+
+ AST_RWLIST_TRAVERSE(&backends, cl, list) {
if (!strncasecmp(cl->tech->type, argv[2], strlen(cl->tech->type))) {
break;
}
}
-
if (!cl) {
ast_cli(fd, "\n%s is not a registered channel driver.\n", argv[2]);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return RESULT_FAILURE;
}
@@ -263,7 +259,7 @@
);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return RESULT_SUCCESS;
}
@@ -337,10 +333,10 @@
struct ast_channel *c;
shutting_down = 1;
if (hangup) {
- AST_LIST_LOCK(&channels);
- AST_LIST_TRAVERSE(&channels, c, chan_list)
+ AST_RWLIST_RDLOCK(&channels);
+ AST_RWLIST_TRAVERSE(&channels, c, chan_list)
ast_softhangup(c, AST_SOFTHANGUP_SHUTDOWN);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
}
}
@@ -349,10 +345,10 @@
{
struct ast_channel *c;
int cnt = 0;
- AST_LIST_LOCK(&channels);
- AST_LIST_TRAVERSE(&channels, c, chan_list)
+ AST_RWLIST_RDLOCK(&channels);
+ AST_RWLIST_TRAVERSE(&channels, c, chan_list)
cnt++;
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return cnt;
}
@@ -403,22 +399,22 @@
{
struct chanlist *chan;
- AST_LIST_LOCK(&channels);
-
- AST_LIST_TRAVERSE(&backends, chan, list) {
+ AST_RWLIST_WRLOCK(&channels);
+
+ AST_RWLIST_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_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return -1;
}
}
if (!(chan = ast_calloc(1, sizeof(*chan)))) {
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return -1;
}
chan->tech = tech;
- AST_LIST_INSERT_HEAD(&backends, chan, list);
+ AST_RWLIST_INSERT_HEAD(&backends, chan, list);
if (option_debug)
ast_log(LOG_DEBUG, "Registered handler for '%s' (%s)\n", chan->tech->type, chan->tech->description);
@@ -427,7 +423,7 @@
ast_verbose(VERBOSE_PREFIX_2 "Registered channel type '%s' (%s)\n", chan->tech->type,
chan->tech->description);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return 0;
}
@@ -438,20 +434,20 @@
if (option_debug)
ast_log(LOG_DEBUG, "Unregistering channel type '%s'\n", tech->type);
- AST_LIST_LOCK(&channels);
-
- AST_LIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
+ AST_RWLIST_WRLOCK(&channels);
+
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&backends, chan, list) {
if (chan->tech == tech) {
- AST_LIST_REMOVE_CURRENT(&backends, list);
+ AST_RWLIST_REMOVE_CURRENT(&backends, list);
free(chan);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Unregistered channel type '%s'\n", tech->type);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
-
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_TRAVERSE_SAFE_END
+
+ AST_RWLIST_UNLOCK(&channels);
}
const struct ast_channel_tech *ast_get_channel_tech(const char *name)
@@ -459,19 +455,16 @@
struct chanlist *chanls;
const struct ast_channel_tech *ret = NULL;
- if (AST_LIST_LOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel tech list\n");
- return NULL;
- }
-
- AST_LIST_TRAVERSE(&backends, chanls, list) {
+ AST_RWLIST_RDLOCK(&channels);
+
+ AST_RWLIST_TRAVERSE(&backends, chanls, list) {
if (!strcasecmp(name, chanls->tech->type)) {
ret = chanls->tech;
break;
}
}
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return ret;
}
@@ -740,9 +733,9 @@
tmp->tech = &null_tech;
- AST_LIST_LOCK(&channels);
- AST_LIST_INSERT_HEAD(&channels, tmp, chan_list);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_WRLOCK(&channels);
+ AST_RWLIST_INSERT_HEAD(&channels, tmp, chan_list);
+ AST_RWLIST_UNLOCK(&channels);
return tmp;
}
@@ -891,13 +884,13 @@
for (retries = 0; retries < 10; retries++) {
int done;
- AST_LIST_LOCK(&channels);
- AST_LIST_TRAVERSE(&channels, c, chan_list) {
+ AST_RWLIST_RDLOCK(&channels);
+ AST_RWLIST_TRAVERSE(&channels, c, chan_list) {
if (prev) { /* look for next item */
if (c != prev) /* not this one */
continue;
/* found, prepare to return c->next */
- c = AST_LIST_NEXT(c, chan_list);
+ c = AST_RWLIST_NEXT(c, chan_list);
}
if (name) { /* want match by name */
if ((!namelen && strcasecmp(c->name, name)) ||
@@ -921,7 +914,7 @@
if (option_debug)
ast_log(LOG_DEBUG, "Avoiding %s for channel '%p'\n", msg, c);
}
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
if (done)
return c;
usleep(1); /* give other threads a chance before retrying */
@@ -1029,8 +1022,8 @@
headp=&chan->varshead;
- AST_LIST_LOCK(&channels);
- AST_LIST_REMOVE(&channels, chan, chan_list);
+ AST_RWLIST_WRLOCK(&channels);
+ AST_RWLIST_REMOVE(&channels, chan, chan_list);
/* Lock and unlock the channel just to be sure nobody
has it locked still */
ast_channel_lock(chan);
@@ -1093,7 +1086,7 @@
ast_string_field_free_pools(chan);
free(chan);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
ast_device_state_changed_literal(name);
}
@@ -2889,12 +2882,9 @@
cause = &foo;
*cause = AST_CAUSE_NOTDEFINED;
- if (AST_LIST_LOCK(&channels)) {
- ast_log(LOG_WARNING, "Unable to lock channel list\n");
- return NULL;
- }
-
- AST_LIST_TRAVERSE(&backends, chan, list) {
+ AST_RWLIST_RDLOCK(&channels);
+
+ AST_RWLIST_TRAVERSE(&backends, chan, list) {
if (strcasecmp(type, chan->tech->type))
continue;
@@ -2903,10 +2893,10 @@
res = ast_translator_best_choice(&fmt, &capabilities);
if (res < 0) {
ast_log(LOG_WARNING, "No translator path exists for channel type %s (native %d) to %d\n", type, chan->tech->capabilities, format);
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return NULL;
}
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
if (!chan->tech->requester)
return NULL;
@@ -2919,7 +2909,7 @@
ast_log(LOG_WARNING, "No channel type registered for '%s'\n", type);
*cause = AST_CAUSE_NOSUCHDRIVER;
- AST_LIST_UNLOCK(&channels);
+ AST_RWLIST_UNLOCK(&channels);
return NULL;
}
More information about the asterisk-commits
mailing list