Skip to content
Snippets Groups Projects
Commit b3c0e124 authored by Joshua Colp's avatar Joshua Colp
Browse files

I'm crazy so I think I'll change the musiconhold classes linked list to read/write as well!

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@53691 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent cd1973e4
Branches
Tags
Loading
...@@ -159,7 +159,7 @@ struct mohdata { ...@@ -159,7 +159,7 @@ struct mohdata {
AST_LIST_ENTRY(mohdata) list; AST_LIST_ENTRY(mohdata) list;
}; };
AST_LIST_HEAD_STATIC(mohclasses, mohclass); AST_RWLIST_HEAD_STATIC(mohclasses, mohclass);
#define LOCAL_MPG_123 "/usr/local/bin/mpg123" #define LOCAL_MPG_123 "/usr/local/bin/mpg123"
#define MPG_123 "/usr/bin/mpg123" #define MPG_123 "/usr/bin/mpg123"
...@@ -556,15 +556,15 @@ static void *monmp3thread(void *data) ...@@ -556,15 +556,15 @@ static void *monmp3thread(void *data)
continue; continue;
} }
pthread_testcancel(); pthread_testcancel();
AST_LIST_LOCK(&mohclasses); AST_RWLIST_RDLOCK(&mohclasses);
AST_LIST_TRAVERSE(&class->members, moh, list) { AST_RWLIST_TRAVERSE(&class->members, moh, list) {
/* Write data */ /* Write data */
if ((res = write(moh->pipe[1], sbuf, res2)) != res2) { if ((res = write(moh->pipe[1], sbuf, res2)) != res2) {
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2); ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2);
} }
} }
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
} }
return NULL; return NULL;
} }
...@@ -629,7 +629,7 @@ static struct mohclass *get_mohbyname(const char *name) ...@@ -629,7 +629,7 @@ static struct mohclass *get_mohbyname(const char *name)
{ {
struct mohclass *moh = NULL; struct mohclass *moh = NULL;
AST_LIST_TRAVERSE(&mohclasses, moh, list) { AST_RWLIST_TRAVERSE(&mohclasses, moh, list) {
if (!strcasecmp(name, moh->name)) if (!strcasecmp(name, moh->name))
break; break;
} }
...@@ -672,9 +672,9 @@ static void moh_release(struct ast_channel *chan, void *data) ...@@ -672,9 +672,9 @@ static void moh_release(struct ast_channel *chan, void *data)
struct mohdata *moh = data; struct mohdata *moh = data;
int oldwfmt; int oldwfmt;
AST_LIST_LOCK(&mohclasses); AST_RWLIST_WRLOCK(&mohclasses);
AST_LIST_REMOVE(&moh->parent->members, moh, list); AST_RWLIST_REMOVE(&moh->parent->members, moh, list);
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
close(moh->pipe[0]); close(moh->pipe[0]);
close(moh->pipe[1]); close(moh->pipe[1]);
...@@ -838,7 +838,7 @@ static int moh_register(struct mohclass *moh, int reload) ...@@ -838,7 +838,7 @@ static int moh_register(struct mohclass *moh, int reload)
#ifdef HAVE_ZAPTEL #ifdef HAVE_ZAPTEL
int x; int x;
#endif #endif
AST_LIST_LOCK(&mohclasses); AST_RWLIST_WRLOCK(&mohclasses);
if (get_mohbyname(moh->name)) { if (get_mohbyname(moh->name)) {
if (reload) { if (reload) {
if (option_debug) if (option_debug)
...@@ -847,10 +847,10 @@ static int moh_register(struct mohclass *moh, int reload) ...@@ -847,10 +847,10 @@ static int moh_register(struct mohclass *moh, int reload)
ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name); ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
} }
free(moh); free(moh);
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
return -1; return -1;
} }
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
time(&moh->start); time(&moh->start);
moh->start -= respawn_time; moh->start -= respawn_time;
...@@ -900,9 +900,9 @@ static int moh_register(struct mohclass *moh, int reload) ...@@ -900,9 +900,9 @@ static int moh_register(struct mohclass *moh, int reload)
return -1; return -1;
} }
AST_LIST_LOCK(&mohclasses); AST_RWLIST_WRLOCK(&mohclasses);
AST_LIST_INSERT_HEAD(&mohclasses, moh, list); AST_RWLIST_INSERT_HEAD(&mohclasses, moh, list);
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
return 0; return 0;
} }
...@@ -940,9 +940,9 @@ static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, con ...@@ -940,9 +940,9 @@ static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, con
else else
class = "default"; class = "default";
AST_LIST_LOCK(&mohclasses); AST_RWLIST_RDLOCK(&mohclasses);
mohclass = get_mohbyname(class); mohclass = get_mohbyname(class);
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
if (!mohclass) { if (!mohclass) {
ast_log(LOG_WARNING, "No class: %s\n", class); ast_log(LOG_WARNING, "No class: %s\n", class);
...@@ -1061,8 +1061,8 @@ static void ast_moh_destroy(void) ...@@ -1061,8 +1061,8 @@ static void ast_moh_destroy(void)
if (option_verbose > 1) if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Destroying musiconhold processes\n"); ast_verbose(VERBOSE_PREFIX_2 "Destroying musiconhold processes\n");
AST_LIST_LOCK(&mohclasses); AST_RWLIST_WRLOCK(&mohclasses);
while ((moh = AST_LIST_REMOVE_HEAD(&mohclasses, list))) { while ((moh = AST_RWLIST_REMOVE_HEAD(&mohclasses, list))) {
if (moh->pid > 1) { if (moh->pid > 1) {
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "killing %d!\n", moh->pid); ast_log(LOG_DEBUG, "killing %d!\n", moh->pid);
...@@ -1085,7 +1085,7 @@ static void ast_moh_destroy(void) ...@@ -1085,7 +1085,7 @@ static void ast_moh_destroy(void)
} }
ast_moh_free_class(&moh); ast_moh_free_class(&moh);
} }
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
} }
static void moh_on_off(int on) static void moh_on_off(int on)
...@@ -1120,8 +1120,8 @@ static int cli_files_show(int fd, int argc, char *argv[]) ...@@ -1120,8 +1120,8 @@ static int cli_files_show(int fd, int argc, char *argv[])
int i; int i;
struct mohclass *class; struct mohclass *class;
AST_LIST_LOCK(&mohclasses); AST_RWLIST_RDLOCK(&mohclasses);
AST_LIST_TRAVERSE(&mohclasses, class, list) { AST_RWLIST_TRAVERSE(&mohclasses, class, list) {
if (!class->total_files) if (!class->total_files)
continue; continue;
...@@ -1129,7 +1129,7 @@ static int cli_files_show(int fd, int argc, char *argv[]) ...@@ -1129,7 +1129,7 @@ static int cli_files_show(int fd, int argc, char *argv[])
for (i = 0; i < class->total_files; i++) for (i = 0; i < class->total_files; i++)
ast_cli(fd, "\tFile: %s\n", class->filearray[i]); ast_cli(fd, "\tFile: %s\n", class->filearray[i]);
} }
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
return 0; return 0;
} }
...@@ -1138,8 +1138,8 @@ static int moh_classes_show(int fd, int argc, char *argv[]) ...@@ -1138,8 +1138,8 @@ static int moh_classes_show(int fd, int argc, char *argv[])
{ {
struct mohclass *class; struct mohclass *class;
AST_LIST_LOCK(&mohclasses); AST_RWLIST_RDLOCK(&mohclasses);
AST_LIST_TRAVERSE(&mohclasses, class, list) { AST_RWLIST_TRAVERSE(&mohclasses, class, list) {
ast_cli(fd, "Class: %s\n", class->name); ast_cli(fd, "Class: %s\n", class->name);
ast_cli(fd, "\tMode: %s\n", S_OR(class->mode, "<none>")); ast_cli(fd, "\tMode: %s\n", S_OR(class->mode, "<none>"));
ast_cli(fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>")); ast_cli(fd, "\tDirectory: %s\n", S_OR(class->dir, "<none>"));
...@@ -1148,7 +1148,7 @@ static int moh_classes_show(int fd, int argc, char *argv[]) ...@@ -1148,7 +1148,7 @@ static int moh_classes_show(int fd, int argc, char *argv[])
if (strcasecmp(class->mode, "files")) if (strcasecmp(class->mode, "files"))
ast_cli(fd, "\tFormat: %s\n", ast_getformatname(class->format)); ast_cli(fd, "\tFormat: %s\n", ast_getformatname(class->format));
} }
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
return 0; return 0;
} }
...@@ -1174,12 +1174,12 @@ static int init_classes(int reload) ...@@ -1174,12 +1174,12 @@ static int init_classes(int reload)
if (!load_moh_classes(reload)) /* Load classes from config */ if (!load_moh_classes(reload)) /* Load classes from config */
return 0; /* Return if nothing is found */ return 0; /* Return if nothing is found */
AST_LIST_LOCK(&mohclasses); AST_RWLIST_WRLOCK(&mohclasses);
AST_LIST_TRAVERSE(&mohclasses, moh, list) { AST_RWLIST_TRAVERSE(&mohclasses, moh, list) {
if (moh->total_files) if (moh->total_files)
moh_scan_files(moh); moh_scan_files(moh);
} }
AST_LIST_UNLOCK(&mohclasses); AST_RWLIST_UNLOCK(&mohclasses);
return 1; return 1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment