Convert some more stuff to read/write lists.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@52332 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Joshua Colp 19 years ago
parent e6f894b27a
commit 820d80f5a7

@ -63,25 +63,22 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
*/ */
int ast_language_is_prefix = 1; 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) int __ast_format_register(const struct ast_format *f, struct ast_module *mod)
{ {
struct ast_format *tmp; struct ast_format *tmp;
if (AST_LIST_LOCK(&formats)) { AST_RWLIST_WRLOCK(&formats);
ast_log(LOG_WARNING, "Unable to lock format list\n"); AST_RWLIST_TRAVERSE(&formats, tmp, list) {
return -1;
}
AST_LIST_TRAVERSE(&formats, tmp, list) {
if (!strcasecmp(f->name, tmp->name)) { 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); ast_log(LOG_WARNING, "Tried to register '%s' format, already registered\n", f->name);
return -1; return -1;
} }
} }
if (!(tmp = ast_calloc(1, sizeof(*tmp)))) { if (!(tmp = ast_calloc(1, sizeof(*tmp)))) {
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
return -1; return -1;
} }
*tmp = *f; *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)); memset(&tmp->list, 0, sizeof(tmp->list));
AST_LIST_INSERT_HEAD(&formats, tmp, list); AST_RWLIST_INSERT_HEAD(&formats, tmp, list);
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
if (option_verbose > 1) if (option_verbose > 1)
ast_verbose( VERBOSE_PREFIX_2 "Registered file format %s, extension(s) %s\n", f->name, f->exts); 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; struct ast_format *tmp;
int res = -1; int res = -1;
if (AST_LIST_LOCK(&formats)) { AST_RWLIST_WRLOCK(&formats);
ast_log(LOG_WARNING, "Unable to lock format list\n"); AST_RWLIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
return -1;
}
AST_LIST_TRAVERSE_SAFE_BEGIN(&formats, tmp, list) {
if (!strcasecmp(name, tmp->name)) { if (!strcasecmp(name, tmp->name)) {
AST_LIST_REMOVE_CURRENT(&formats, list); AST_RWLIST_REMOVE_CURRENT(&formats, list);
free(tmp); free(tmp);
res = 0; res = 0;
} }
} }
AST_LIST_TRAVERSE_SAFE_END AST_RWLIST_TRAVERSE_SAFE_END
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
if (!res) { if (!res) {
if (option_verbose > 1) 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; struct ast_format *f;
int res = (action == ACTION_EXISTS) ? 0 : -1; int res = (action == ACTION_EXISTS) ? 0 : -1;
if (AST_LIST_LOCK(&formats)) { AST_RWLIST_RDLOCK(&formats);
ast_log(LOG_WARNING, "Unable to lock format list\n");
return res;
}
/* Check for a specific format */ /* Check for a specific format */
AST_LIST_TRAVERSE(&formats, f, list) { AST_RWLIST_TRAVERSE(&formats, f, list) {
char *stringp, *ext = NULL; char *stringp, *ext = NULL;
if (fmt && !exts_compare(f->exts, fmt)) 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); free(fn);
} }
} }
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
return res; return res;
} }
@ -815,12 +806,9 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
struct ast_filestream *fs = NULL; struct ast_filestream *fs = NULL;
char *fn; char *fn;
if (AST_LIST_LOCK(&formats)) { AST_RWLIST_RDLOCK(&formats);
ast_log(LOG_WARNING, "Unable to lock format list\n");
return NULL;
}
AST_LIST_TRAVERSE(&formats, f, list) { AST_RWLIST_TRAVERSE(&formats, f, list) {
fs = NULL; fs = NULL;
if (!exts_compare(f->exts, type)) if (!exts_compare(f->exts, type))
continue; continue;
@ -848,7 +836,7 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
break; break;
} }
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
if (!fs) if (!fs)
ast_log(LOG_WARNING, "No such format '%s'\n", type); 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; size_t size = 0;
int format_found = 0; int format_found = 0;
if (AST_LIST_LOCK(&formats)) { AST_RWLIST_RDLOCK(&formats);
ast_log(LOG_WARNING, "Unable to lock format list\n");
return NULL;
}
/* set the O_TRUNC flag if and only if there is no O_APPEND specified */ /* 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 */ /* 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, /* XXX need to fix this - we should just do the fopen,
* not open followed by fdopen() * not open followed by fdopen()
*/ */
AST_LIST_TRAVERSE(&formats, f, list) { AST_RWLIST_TRAVERSE(&formats, f, list) {
char *fn, *orig_fn = NULL; char *fn, *orig_fn = NULL;
if (fs) if (fs)
break; break;
@ -974,7 +959,7 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
free(fn); free(fn);
} }
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
if (!format_found) if (!format_found)
ast_log(LOG_WARNING, "No such format '%s'\n", type); ast_log(LOG_WARNING, "No such format '%s'\n", type);
@ -1139,16 +1124,12 @@ static int show_file_formats(int fd, int argc, char *argv[])
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
ast_cli(fd, FORMAT, "Format", "Name", "Extensions"); ast_cli(fd, FORMAT, "Format", "Name", "Extensions");
if (AST_LIST_LOCK(&formats)) { AST_RWLIST_RDLOCK(&formats);
ast_log(LOG_WARNING, "Unable to lock format list\n"); AST_RWLIST_TRAVERSE(&formats, f, list) {
return -1;
}
AST_LIST_TRAVERSE(&formats, f, list) {
ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts); ast_cli(fd, FORMAT2, ast_getformatname(f->format), f->name, f->exts);
count_fmt++; count_fmt++;
} }
AST_LIST_UNLOCK(&formats); AST_RWLIST_UNLOCK(&formats);
ast_cli(fd, "%d file formats registered.\n", count_fmt); ast_cli(fd, "%d file formats registered.\n", count_fmt);
return RESULT_SUCCESS; return RESULT_SUCCESS;
#undef FORMAT #undef FORMAT

@ -47,15 +47,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h" #include "asterisk/lock.h"
/* XXX Why don't we just use the formats struct for this? */ /* 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) int ast_image_register(struct ast_imager *img)
{ {
if (option_verbose > 1) if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc); ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
AST_LIST_LOCK(&imagers); AST_RWLIST_WRLOCK(&imagers);
AST_LIST_INSERT_HEAD(&imagers, img, list); AST_RWLIST_INSERT_HEAD(&imagers, img, list);
AST_LIST_UNLOCK(&imagers); AST_RWLIST_UNLOCK(&imagers);
return 0; return 0;
} }
@ -63,15 +63,15 @@ void ast_image_unregister(struct ast_imager *img)
{ {
struct ast_imager *i; struct ast_imager *i;
AST_LIST_LOCK(&imagers); AST_RWLIST_WRLOCK(&imagers);
AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) { AST_RWLIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {
if (i == img) { if (i == img) {
AST_LIST_REMOVE_CURRENT(&imagers, list); AST_RWLIST_REMOVE_CURRENT(&imagers, list);
break; break;
} }
} }
AST_LIST_TRAVERSE_SAFE_END AST_RWLIST_TRAVERSE_SAFE_END
AST_LIST_UNLOCK(&imagers); AST_RWLIST_UNLOCK(&imagers);
if (i && (option_verbose > 1)) if (i && (option_verbose > 1))
ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc); 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; int len=0;
struct ast_frame *f = NULL; struct ast_frame *f = NULL;
AST_LIST_LOCK(&imagers); AST_RWLIST_RDLOCK(&imagers);
AST_LIST_TRAVERSE(&imagers, i, list) { AST_RWLIST_TRAVERSE(&imagers, i, list) {
if (i->format & format) { if (i->format & format) {
char *stringp=NULL; char *stringp=NULL;
ast_copy_string(tmp, i->exts, sizeof(tmp)); 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 } else
ast_log(LOG_WARNING, "Image file '%s' not found\n", filename); ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
AST_LIST_UNLOCK(&imagers); AST_RWLIST_UNLOCK(&imagers);
return f; return f;
} }
@ -188,8 +188,11 @@ static int show_image_formats(int fd, int argc, char *argv[])
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format"); 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_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
}
AST_RWLIST_UNLOCK(&imagers);
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }

Loading…
Cancel
Save