aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/file.c67
-rw-r--r--main/image.c29
2 files changed, 40 insertions, 56 deletions
diff --git a/main/file.c b/main/file.c
index ee0436bd3..a5a558c35 100644
--- a/main/file.c
+++ b/main/file.c
@@ -63,25 +63,22 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
*/
int ast_language_is_prefix = 1;
-static AST_LIST_HEAD_STATIC(formats, ast_format);
+static AST_RWLIST_HEAD_STATIC(formats, ast_format);
int __ast_format_register(const struct ast_format *f, struct ast_module *mod)
{
struct ast_format *tmp;
- if (AST_LIST_LOCK(&formats)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return -1;
- }
- AST_LIST_TRAVERSE(&formats, tmp, list) {
+ AST_RWLIST_WRLOCK(&formats);
+ AST_RWLIST_TRAVERSE(&formats, tmp, list) {
if (!strcasecmp(f->name, tmp->name)) {
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_UNLOCK(&formats);
ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
return -1;
}
}
if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_UNLOCK(&formats);
return -1;
}
*tmp = *f;
@@ -98,8 +95,8 @@ int __ast_format_register(const struct ast_format *f, struct ast_module *mod)
memset(&tmp->list, 0, sizeof(tmp->list));
- AST_LIST_INSERT_HEAD(&formats, tmp, list);
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
+ AST_RWLIST_UNLOCK(&formats);
if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Registered file format %s, extension(s) %s\n", f->name, f->exts);
@@ -111,19 +108,16 @@ int ast_format_unregister(const char *name)
struct ast_format *tmp;
int res = -1;
- if (AST_LIST_LOCK(&formats)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return -1;
- }
- AST_LIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
+ AST_RWLIST_WRLOCK(&formats);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
if (!strcasecmp(name, tmp->name)) {
- AST_LIST_REMOVE_CURRENT(&formats, list);
+ AST_RWLIST_REMOVE_CURRENT(&formats, list);
free(tmp);
res = 0;
}
}
- AST_LIST_TRAVERSE_SAFE_END
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&formats);
if (!res) {
if (option_verbose > 1)
@@ -352,12 +346,9 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm
struct ast_format *f;
int res = (action == ACTION_EXISTS) ? 0 : -1;
- if (AST_LIST_LOCK(&formats)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return res;
- }
+ AST_RWLIST_RDLOCK(&formats);
/* Check for a specific format */
- AST_LIST_TRAVERSE(&formats, f, list) {
+ AST_RWLIST_TRAVERSE(&formats, f, list) {
char *stringp, *ext = NULL;
if (fmt && !exts_compare(f->exts, fmt))
@@ -456,7 +447,7 @@ static int ast_filehelper(const char *filename, const void *arg2, const char *fm
free(fn);
}
}
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_UNLOCK(&formats);
return res;
}
@@ -815,12 +806,9 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
struct ast_filestream *fs = NULL;
char *fn;
- if (AST_LIST_LOCK(&formats)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return NULL;
- }
+ AST_RWLIST_RDLOCK(&formats);
- AST_LIST_TRAVERSE(&formats, f, list) {
+ AST_RWLIST_TRAVERSE(&formats, f, list) {
fs = NULL;
if (!exts_compare(f->exts, type))
continue;
@@ -848,7 +836,7 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
break;
}
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_UNLOCK(&formats);
if (!fs)
ast_log(LOG_WARNING, "No such format '%s'\n", type);
@@ -866,10 +854,7 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
size_t size = 0;
int format_found = 0;
- if (AST_LIST_LOCK(&formats)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return NULL;
- }
+ AST_RWLIST_RDLOCK(&formats);
/* set the O_TRUNC flag if and only if there is no O_APPEND specified */
/* We really can't use O_APPEND as it will break WAV header updates */
@@ -884,7 +869,7 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
/* XXX need to fix this - we should just do the fopen,
* not open followed by fdopen()
*/
- AST_LIST_TRAVERSE(&formats, f, list) {
+ AST_RWLIST_TRAVERSE(&formats, f, list) {
char *fn, *orig_fn = NULL;
if (fs)
break;
@@ -974,7 +959,7 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
free(fn);
}
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_UNLOCK(&formats);
if (!format_found)
ast_log(LOG_WARNING, "No such format '%s'\n", type);
@@ -1138,17 +1123,13 @@ static int show_file_formats(int fd, int argc, char *argv[])
if (argc != 3)
return RESULT_SHOWUSAGE;
ast_cli(fd, FORMAT, "Format", "Name", "Extensions");
-
- if (AST_LIST_LOCK(&formats)) {
- ast_log(LOG_WARNING, "Unable to lock format list\n");
- return -1;
- }
- AST_LIST_TRAVERSE(&formats, f, list) {
+ AST_RWLIST_RDLOCK(&formats);
+ AST_RWLIST_TRAVERSE(&formats, f, list) {
ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts);
count_fmt++;
}
- AST_LIST_UNLOCK(&formats);
+ AST_RWLIST_UNLOCK(&formats);
ast_cli(fd, "%d file formats registered.\n", count_fmt);
return RESULT_SUCCESS;
#undef FORMAT
diff --git a/main/image.c b/main/image.c
index 3a25f5c33..a0a410048 100644
--- a/main/image.c
+++ b/main/image.c
@@ -47,15 +47,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h"
/* XXX Why don't we just use the formats struct for this? */
-static AST_LIST_HEAD_STATIC(imagers, ast_imager);
+static AST_RWLIST_HEAD_STATIC(imagers, ast_imager);
int ast_image_register(struct ast_imager *img)
{
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
- AST_LIST_LOCK(&imagers);
- AST_LIST_INSERT_HEAD(&imagers, img, list);
- AST_LIST_UNLOCK(&imagers);
+ AST_RWLIST_WRLOCK(&imagers);
+ AST_RWLIST_INSERT_HEAD(&imagers, img, list);
+ AST_RWLIST_UNLOCK(&imagers);
return 0;
}
@@ -63,15 +63,15 @@ void ast_image_unregister(struct ast_imager *img)
{
struct ast_imager *i;
- AST_LIST_LOCK(&imagers);
- AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {
+ AST_RWLIST_WRLOCK(&imagers);
+ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {
if (i == img) {
- AST_LIST_REMOVE_CURRENT(&imagers, list);
+ AST_RWLIST_REMOVE_CURRENT(&imagers, list);
break;
}
}
- AST_LIST_TRAVERSE_SAFE_END
- AST_LIST_UNLOCK(&imagers);
+ AST_RWLIST_TRAVERSE_SAFE_END
+ AST_RWLIST_UNLOCK(&imagers);
if (i && (option_verbose > 1))
ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
}
@@ -121,8 +121,8 @@ struct ast_frame *ast_read_image(char *filename, const char *preflang, int forma
int len=0;
struct ast_frame *f = NULL;
- AST_LIST_LOCK(&imagers);
- AST_LIST_TRAVERSE(&imagers, i, list) {
+ AST_RWLIST_RDLOCK(&imagers);
+ AST_RWLIST_TRAVERSE(&imagers, i, list) {
if (i->format & format) {
char *stringp=NULL;
ast_copy_string(tmp, i->exts, sizeof(tmp));
@@ -161,7 +161,7 @@ struct ast_frame *ast_read_image(char *filename, const char *preflang, int forma
} else
ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
- AST_LIST_UNLOCK(&imagers);
+ AST_RWLIST_UNLOCK(&imagers);
return f;
}
@@ -188,8 +188,11 @@ static int show_image_formats(int fd, int argc, char *argv[])
if (argc != 4)
return RESULT_SHOWUSAGE;
ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
- AST_LIST_TRAVERSE(&imagers, i, list)
+ AST_RWLIST_RDLOCK(&imagers);
+ AST_RWLIST_TRAVERSE(&imagers, i, list) {
ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
+ }
+ AST_RWLIST_UNLOCK(&imagers);
return RESULT_SUCCESS;
}