Few more rwlist conversions... why not.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@69705 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2007-06-18 16:37:14 +00:00
parent 43658278ff
commit 55c6ce92ce
3 changed files with 77 additions and 80 deletions

View File

@@ -188,10 +188,10 @@ struct console {
struct ast_atexit {
void (*func)(void);
AST_LIST_ENTRY(ast_atexit) list;
AST_RWLIST_ENTRY(ast_atexit) list;
};
static AST_LIST_HEAD_STATIC(atexits, ast_atexit);
static AST_RWLIST_HEAD_STATIC(atexits, ast_atexit);
time_t ast_startuptime;
time_t ast_lastreloadtime;
@@ -252,12 +252,12 @@ static struct {
#if !defined(LOW_MEMORY)
struct file_version {
AST_LIST_ENTRY(file_version) list;
AST_RWLIST_ENTRY(file_version) list;
const char *file;
char *version;
};
static AST_LIST_HEAD_STATIC(file_versions, file_version);
static AST_RWLIST_HEAD_STATIC(file_versions, file_version);
void ast_register_file_version(const char *file, const char *version)
{
@@ -275,36 +275,36 @@ void ast_register_file_version(const char *file, const char *version)
new->file = file;
new->version = (char *) new + sizeof(*new);
memcpy(new->version, work, version_length);
AST_LIST_LOCK(&file_versions);
AST_LIST_INSERT_HEAD(&file_versions, new, list);
AST_LIST_UNLOCK(&file_versions);
AST_RWLIST_WRLOCK(&file_versions);
AST_RWLIST_INSERT_HEAD(&file_versions, new, list);
AST_RWLIST_UNLOCK(&file_versions);
}
void ast_unregister_file_version(const char *file)
{
struct file_version *find;
AST_LIST_LOCK(&file_versions);
AST_LIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
AST_RWLIST_WRLOCK(&file_versions);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&file_versions, find, list) {
if (!strcasecmp(find->file, file)) {
AST_LIST_REMOVE_CURRENT(&file_versions, list);
AST_RWLIST_REMOVE_CURRENT(&file_versions, list);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&file_versions);
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&file_versions);
if (find)
ast_free(find);
}
struct thread_list_t {
AST_LIST_ENTRY(thread_list_t) list;
AST_RWLIST_ENTRY(thread_list_t) list;
char *name;
pthread_t id;
};
static AST_LIST_HEAD_STATIC(thread_list, thread_list_t);
static AST_RWLIST_HEAD_STATIC(thread_list, thread_list_t);
static const char show_threads_help[] =
"Usage: core show threads\n"
@@ -318,24 +318,24 @@ void ast_register_thread(char *name)
return;
new->id = pthread_self();
new->name = name; /* steal the allocated memory for the thread name */
AST_LIST_LOCK(&thread_list);
AST_LIST_INSERT_HEAD(&thread_list, new, list);
AST_LIST_UNLOCK(&thread_list);
AST_RWLIST_WRLOCK(&thread_list);
AST_RWLIST_INSERT_HEAD(&thread_list, new, list);
AST_RWLIST_UNLOCK(&thread_list);
}
void ast_unregister_thread(void *id)
{
struct thread_list_t *x;
AST_LIST_LOCK(&thread_list);
AST_LIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
AST_RWLIST_WRLOCK(&thread_list);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&thread_list, x, list) {
if ((void *) x->id == id) {
AST_LIST_REMOVE_CURRENT(&thread_list, list);
AST_RWLIST_REMOVE_CURRENT(&thread_list, list);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&thread_list);
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&thread_list);
if (x) {
ast_free(x->name);
ast_free(x);
@@ -408,12 +408,12 @@ static int handle_show_threads(int fd, int argc, char *argv[])
int count = 0;
struct thread_list_t *cur;
AST_LIST_LOCK(&thread_list);
AST_LIST_TRAVERSE(&thread_list, cur, list) {
AST_RWLIST_RDLOCK(&thread_list);
AST_RWLIST_TRAVERSE(&thread_list, cur, list) {
ast_cli(fd, "%p %s\n", (void *)cur->id, cur->name);
count++;
}
AST_LIST_UNLOCK(&thread_list);
AST_RWLIST_UNLOCK(&thread_list);
ast_cli(fd, "%d threads listed.\n", count);
return 0;
}
@@ -623,8 +623,8 @@ static int handle_show_version_files(int fd, int argc, char *argv[])
ast_cli(fd, FORMAT, "File", "Revision");
ast_cli(fd, FORMAT, "----", "--------");
AST_LIST_LOCK(&file_versions);
AST_LIST_TRAVERSE(&file_versions, iterator, list) {
AST_RWLIST_RDLOCK(&file_versions);
AST_RWLIST_TRAVERSE(&file_versions, iterator, list) {
if (havename && strcasecmp(iterator->file, argv[4]))
continue;
@@ -636,7 +636,7 @@ static int handle_show_version_files(int fd, int argc, char *argv[])
if (havename)
break;
}
AST_LIST_UNLOCK(&file_versions);
AST_RWLIST_UNLOCK(&file_versions);
if (!havename) {
ast_cli(fd, "%d files listed.\n", count_files);
}
@@ -658,14 +658,14 @@ static char *complete_show_version_files(const char *line, const char *word, int
if (pos != 3)
return NULL;
AST_LIST_LOCK(&file_versions);
AST_LIST_TRAVERSE(&file_versions, find, list) {
AST_RWLIST_RDLOCK(&file_versions);
AST_RWLIST_TRAVERSE(&file_versions, find, list) {
if (!strncasecmp(word, find->file, matchlen) && ++which > state) {
ret = ast_strdup(find->file);
break;
}
}
AST_LIST_UNLOCK(&file_versions);
AST_RWLIST_UNLOCK(&file_versions);
return ret;
}
@@ -676,28 +676,28 @@ int ast_register_atexit(void (*func)(void))
int res = -1;
struct ast_atexit *ae;
ast_unregister_atexit(func);
AST_LIST_LOCK(&atexits);
AST_RWLIST_WRLOCK(&atexits);
if ((ae = ast_calloc(1, sizeof(*ae)))) {
AST_LIST_INSERT_HEAD(&atexits, ae, list);
AST_RWLIST_INSERT_HEAD(&atexits, ae, list);
ae->func = func;
res = 0;
}
AST_LIST_UNLOCK(&atexits);
AST_RWLIST_UNLOCK(&atexits);
return res;
}
void ast_unregister_atexit(void (*func)(void))
{
struct ast_atexit *ae;
AST_LIST_LOCK(&atexits);
AST_LIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
AST_RWLIST_WRLOCK(&atexits);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&atexits, ae, list) {
if (ae->func == func) {
AST_LIST_REMOVE_CURRENT(&atexits, list);
AST_RWLIST_REMOVE_CURRENT(&atexits, list);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END
AST_LIST_UNLOCK(&atexits);
AST_RWLIST_TRAVERSE_SAFE_END
AST_RWLIST_UNLOCK(&atexits);
}
static int fdprint(int fd, const char *s)
@@ -1192,12 +1192,12 @@ int ast_set_priority(int pri)
static void ast_run_atexits(void)
{
struct ast_atexit *ae;
AST_LIST_LOCK(&atexits);
AST_LIST_TRAVERSE(&atexits, ae, list) {
AST_RWLIST_RDLOCK(&atexits);
AST_RWLIST_TRAVERSE(&atexits, ae, list) {
if (ae->func)
ae->func();
}
AST_LIST_UNLOCK(&atexits);
AST_RWLIST_UNLOCK(&atexits);
}
static void quit_handler(int num, int nice, int safeshutdown, int restart)

View File

@@ -63,10 +63,10 @@ struct ast_cdr_beitem {
char name[20];
char desc[80];
ast_cdrbe be;
AST_LIST_ENTRY(ast_cdr_beitem) list;
AST_RWLIST_ENTRY(ast_cdr_beitem) list;
};
static AST_LIST_HEAD_STATIC(be_list, ast_cdr_beitem);
static AST_RWLIST_HEAD_STATIC(be_list, ast_cdr_beitem);
struct ast_cdr_batch_item {
struct ast_cdr *cdr;
@@ -111,25 +111,23 @@ int check_cdr_enabled()
*/
int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
{
struct ast_cdr_beitem *i;
struct ast_cdr_beitem *i = NULL;
if (!name)
return -1;
if (!be) {
ast_log(LOG_WARNING, "CDR engine '%s' lacks backend\n", name);
return -1;
}
AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE(&be_list, i, list) {
if (!strcasecmp(name, i->name))
break;
}
AST_LIST_UNLOCK(&be_list);
if (i) {
ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
return -1;
AST_RWLIST_WRLOCK(&be_list);
AST_RWLIST_TRAVERSE(&be_list, i, list) {
if (!strcasecmp(name, i->name)) {
ast_log(LOG_WARNING, "Already have a CDR backend called '%s'\n", name);
AST_RWLIST_UNLOCK(&be_list);
return -1;
}
}
if (!(i = ast_calloc(1, sizeof(*i))))
@@ -139,9 +137,8 @@ int ast_cdr_register(const char *name, const char *desc, ast_cdrbe be)
ast_copy_string(i->name, name, sizeof(i->name));
ast_copy_string(i->desc, desc, sizeof(i->desc));
AST_LIST_LOCK(&be_list);
AST_LIST_INSERT_HEAD(&be_list, i, list);
AST_LIST_UNLOCK(&be_list);
AST_RWLIST_INSERT_HEAD(&be_list, i, list);
AST_RWLIST_UNLOCK(&be_list);
return 0;
}
@@ -151,18 +148,18 @@ void ast_cdr_unregister(const char *name)
{
struct ast_cdr_beitem *i = NULL;
AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
AST_RWLIST_WRLOCK(&be_list);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&be_list, i, list) {
if (!strcasecmp(name, i->name)) {
AST_LIST_REMOVE_CURRENT(&be_list, list);
AST_RWLIST_REMOVE_CURRENT(&be_list, list);
if (option_verbose > 1)
ast_verbose(VERBOSE_PREFIX_2 "Unregistered '%s' CDR backend\n", name);
ast_free(i);
break;
}
}
AST_LIST_TRAVERSE_SAFE_END;
AST_LIST_UNLOCK(&be_list);
AST_RWLIST_TRAVERSE_SAFE_END;
AST_RWLIST_UNLOCK(&be_list);
}
/*! Duplicate a CDR record
@@ -933,11 +930,11 @@ static void post_cdr(struct ast_cdr *cdr)
ast_set_flag(cdr, AST_CDR_FLAG_POSTED);
if (ast_test_flag(cdr, AST_CDR_FLAG_POST_DISABLED))
continue;
AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE(&be_list, i, list) {
AST_RWLIST_RDLOCK(&be_list);
AST_RWLIST_TRAVERSE(&be_list, i, list) {
i->be(cdr);
}
AST_LIST_UNLOCK(&be_list);
AST_RWLIST_UNLOCK(&be_list);
}
}
@@ -1188,11 +1185,11 @@ static int handle_cli_status(int fd, int argc, char *argv[])
ast_cli(fd, "CDR maximum batch time: %d second%s\n", batchtime, ESS(batchtime));
ast_cli(fd, "CDR next scheduled batch processing time: %ld second%s\n", nextbatchtime, ESS(nextbatchtime));
}
AST_LIST_LOCK(&be_list);
AST_LIST_TRAVERSE(&be_list, beitem, list) {
AST_RWLIST_RDLOCK(&be_list);
AST_RWLIST_TRAVERSE(&be_list, beitem, list) {
ast_cli(fd, "CDR registered backend: %s\n", beitem->name);
}
AST_LIST_UNLOCK(&be_list);
AST_RWLIST_UNLOCK(&be_list);
}
return 0;

View File

@@ -60,12 +60,12 @@ struct ast_dnsmgr_entry {
/*! Set to 1 if the entry changes */
int changed:1;
ast_mutex_t lock;
AST_LIST_ENTRY(ast_dnsmgr_entry) list;
AST_RWLIST_ENTRY(ast_dnsmgr_entry) list;
/*! just 1 here, but we use calloc to allocate the correct size */
char name[1];
};
static AST_LIST_HEAD_STATIC(entry_list, ast_dnsmgr_entry);
static AST_RWLIST_HEAD_STATIC(entry_list, ast_dnsmgr_entry);
AST_MUTEX_DEFINE_STATIC(refresh_lock);
@@ -97,9 +97,9 @@ struct ast_dnsmgr_entry *ast_dnsmgr_get(const char *name, struct in_addr *result
ast_mutex_init(&entry->lock);
strcpy(entry->name, name);
AST_LIST_LOCK(&entry_list);
AST_LIST_INSERT_HEAD(&entry_list, entry, list);
AST_LIST_UNLOCK(&entry_list);
AST_RWLIST_WRLOCK(&entry_list);
AST_RWLIST_INSERT_HEAD(&entry_list, entry, list);
AST_RWLIST_UNLOCK(&entry_list);
return entry;
}
@@ -109,9 +109,9 @@ void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
if (!entry)
return;
AST_LIST_LOCK(&entry_list);
AST_LIST_REMOVE(&entry_list, entry, list);
AST_LIST_UNLOCK(&entry_list);
AST_RWLIST_WRLOCK(&entry_list);
AST_RWLIST_REMOVE(&entry_list, entry, list);
AST_RWLIST_UNLOCK(&entry_list);
if (option_verbose > 3)
ast_verbose(VERBOSE_PREFIX_4 "removing dns manager for '%s'\n", entry->name);
@@ -302,10 +302,10 @@ static int handle_cli_status(int fd, int argc, char *argv[])
ast_cli(fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled");
ast_cli(fd, "Refresh Interval: %d seconds\n", refresh_interval);
AST_LIST_LOCK(&entry_list);
AST_LIST_TRAVERSE(&entry_list, entry, list)
AST_RWLIST_RDLOCK(&entry_list);
AST_RWLIST_TRAVERSE(&entry_list, entry, list)
count++;
AST_LIST_UNLOCK(&entry_list);
AST_RWLIST_UNLOCK(&entry_list);
ast_cli(fd, "Number of entries: %d\n", count);
return 0;