aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-11 16:54:51 +0000
committerrussell <russell@f38db490-d61c-443f-a65b-d21fe96a405b>2008-12-11 16:54:51 +0000
commiteea662de8a2ab9f1b8e467485de03cfa2ee001bc (patch)
treefe08521f0e5fa61f916aedb0825550ebb4b40f4e
parent19a1dd945dc4099dfc4d4fa01ee3cf78e568b386 (diff)
Fix an issue that made it so you could only have a single caller executing
a custom feature at a time. This was especially problematic when custom features ran for any appreciable amount of time. The fix turned out to be quite simple. The dynamic features are now stored in a read/write list instead of a list using a mutex. (closes issue #13478) Reported by: neutrino88 Fix suggested by file git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@163092 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--res/res_features.c61
1 files changed, 33 insertions, 28 deletions
diff --git a/res/res_features.c b/res/res_features.c
index 72865f988..be9fab630 100644
--- a/res/res_features.c
+++ b/res/res_features.c
@@ -1008,7 +1008,7 @@ static struct ast_call_feature builtin_features[] =
};
-static AST_LIST_HEAD_STATIC(feature_list,ast_call_feature);
+static AST_RWLIST_HEAD_STATIC(feature_list, ast_call_feature);
/*! \brief register new feature into feature_list*/
void ast_register_feature(struct ast_call_feature *feature)
@@ -1018,12 +1018,13 @@ void ast_register_feature(struct ast_call_feature *feature)
return;
}
- AST_LIST_LOCK(&feature_list);
- AST_LIST_INSERT_HEAD(&feature_list,feature,feature_entry);
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_WRLOCK(&feature_list);
+ AST_RWLIST_INSERT_HEAD(&feature_list, feature, feature_entry);
+ AST_RWLIST_UNLOCK(&feature_list);
- if (option_verbose >= 2)
+ if (option_verbose >= 2) {
ast_verbose(VERBOSE_PREFIX_2 "Registered Feature '%s'\n",feature->sname);
+ }
}
/*! \brief unregister feature from feature_list */
@@ -1032,9 +1033,10 @@ void ast_unregister_feature(struct ast_call_feature *feature)
if (!feature)
return;
- AST_LIST_LOCK(&feature_list);
- AST_LIST_REMOVE(&feature_list,feature,feature_entry);
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_WRLOCK(&feature_list);
+ AST_RWLIST_REMOVE(&feature_list, feature, feature_entry);
+ AST_RWLIST_UNLOCK(&feature_list);
+
free(feature);
}
@@ -1043,10 +1045,11 @@ static void ast_unregister_features(void)
{
struct ast_call_feature *feature;
- AST_LIST_LOCK(&feature_list);
- while ((feature = AST_LIST_REMOVE_HEAD(&feature_list,feature_entry)))
+ AST_RWLIST_WRLOCK(&feature_list);
+ while ((feature = AST_LIST_REMOVE_HEAD(&feature_list, feature_entry))) {
free(feature);
- AST_LIST_UNLOCK(&feature_list);
+ }
+ AST_RWLIST_UNLOCK(&feature_list);
}
/*! \brief find a feature by name */
@@ -1054,9 +1057,10 @@ static struct ast_call_feature *find_dynamic_feature(const char *name)
{
struct ast_call_feature *tmp;
- AST_LIST_TRAVERSE(&feature_list, tmp, feature_entry) {
- if (!strcasecmp(tmp->sname, name))
+ AST_RWLIST_TRAVERSE(&feature_list, tmp, feature_entry) {
+ if (!strcasecmp(tmp->sname, name)) {
break;
+ }
}
return tmp;
@@ -1201,9 +1205,9 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
tmp = ast_strdupa(dynamic_features);
while ((tok = strsep(&tmp, "#"))) {
- AST_LIST_LOCK(&feature_list);
+ AST_RWLIST_RDLOCK(&feature_list);
if (!(feature = find_dynamic_feature(tok))) {
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_UNLOCK(&feature_list);
continue;
}
@@ -1213,14 +1217,14 @@ static int ast_feature_interpret(struct ast_channel *chan, struct ast_channel *p
ast_verbose(VERBOSE_PREFIX_3 " Feature Found: %s exten: %s\n",feature->sname, tok);
res = feature->operation(chan, peer, config, code, sense, feature);
if (res != FEATURE_RETURN_KEEPTRYING) {
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_UNLOCK(&feature_list);
break;
}
res = FEATURE_RETURN_PASSDIGITS;
} else if (!strncmp(feature->exten, code, strlen(code)))
res = FEATURE_RETURN_STOREDIGITS;
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_UNLOCK(&feature_list);
}
return res;
@@ -1255,14 +1259,14 @@ static void set_config_flags(struct ast_channel *chan, struct ast_channel *peer,
/* while we have a feature */
while ((tok = strsep(&tmp, "#"))) {
- AST_LIST_LOCK(&feature_list);
+ AST_RWLIST_RDLOCK(&feature_list);
if ((feature = find_dynamic_feature(tok)) && ast_test_flag(feature, AST_FEATURE_FLAG_NEEDSDTMF)) {
if (ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLER))
ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0);
if (ast_test_flag(feature, AST_FEATURE_FLAG_BYCALLEE))
ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1);
}
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_UNLOCK(&feature_list);
}
}
}
@@ -2286,13 +2290,14 @@ static int handle_showfeatures(int fd, int argc, char *argv[])
ast_cli(fd, "\n");
ast_cli(fd, format, "Dynamic Feature", "Default", "Current");
ast_cli(fd, format, "---------------", "-------", "-------");
- if (AST_LIST_EMPTY(&feature_list))
+ if (AST_RWLIST_EMPTY(&feature_list)) {
ast_cli(fd, "(none)\n");
- else {
- AST_LIST_LOCK(&feature_list);
- AST_LIST_TRAVERSE(&feature_list, feature, feature_entry)
- ast_cli(fd, format, feature->sname, "no def", feature->exten);
- AST_LIST_UNLOCK(&feature_list);
+ } else {
+ AST_RWLIST_RDLOCK(&feature_list);
+ AST_RWLIST_TRAVERSE(&feature_list, feature, feature_entry) {
+ ast_cli(fd, format, feature->sname, "no def", feature->exten);
+ }
+ AST_RWLIST_UNLOCK(&feature_list);
}
ast_cli(fd, "\nCall parking\n");
ast_cli(fd, "------------\n");
@@ -2646,13 +2651,13 @@ static int load_config(void)
continue;
}
- AST_LIST_LOCK(&feature_list);
+ AST_RWLIST_RDLOCK(&feature_list);
if ((feature = find_dynamic_feature(var->name))) {
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_UNLOCK(&feature_list);
ast_log(LOG_WARNING, "Dynamic Feature '%s' specified more than once!\n", var->name);
continue;
}
- AST_LIST_UNLOCK(&feature_list);
+ AST_RWLIST_UNLOCK(&feature_list);
if (!(feature = ast_calloc(1, sizeof(*feature))))
continue;