diff options
author | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-06-13 18:23:12 +0000 |
---|---|---|
committer | file <file@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-06-13 18:23:12 +0000 |
commit | 479087578ce7dc2f76cf0dc2d31ce8923063e6b2 (patch) | |
tree | 58936ee18424560b11ef9150cc96f8f1d9bfb515 /main/app.c | |
parent | 89eb1c59764c788fa92b9c281fdf41381a7757c3 (diff) |
Use read/write lock based lists for group counting.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@69130 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/app.c')
-rw-r--r-- | main/app.c | 55 |
1 files changed, 30 insertions, 25 deletions
diff --git a/main/app.c b/main/app.c index defc0081f..a81831385 100644 --- a/main/app.c +++ b/main/app.c @@ -53,7 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #define MAX_OTHER_FORMATS 10 -static AST_LIST_HEAD_STATIC(groups, ast_group_info); +static AST_RWLIST_HEAD_STATIC(groups, ast_group_info); /*! * \brief This function presents a dialtone and reads an extension into 'collect' @@ -874,15 +874,15 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data) if (!ast_strlen_zero(category)) len += strlen(category) + 1; - AST_LIST_LOCK(&groups); - AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) { + AST_RWLIST_WRLOCK(&groups); + AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) { if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { - AST_LIST_REMOVE_CURRENT(&groups, list); + AST_RWLIST_REMOVE_CURRENT(&groups, list); free(gi); break; } } - AST_LIST_TRAVERSE_SAFE_END + AST_RWLIST_TRAVERSE_SAFE_END if ((gi = calloc(1, len))) { gi->chan = chan; @@ -892,12 +892,12 @@ int ast_app_group_set_channel(struct ast_channel *chan, const char *data) gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1; strcpy(gi->category, category); } - AST_LIST_INSERT_TAIL(&groups, gi, list); + AST_RWLIST_INSERT_TAIL(&groups, gi, list); } else { res = -1; } - AST_LIST_UNLOCK(&groups); + AST_RWLIST_UNLOCK(&groups); return res; } @@ -910,12 +910,12 @@ int ast_app_group_get_count(const char *group, const char *category) if (ast_strlen_zero(group)) return 0; - AST_LIST_LOCK(&groups); - AST_LIST_TRAVERSE(&groups, gi, list) { + AST_RWLIST_RDLOCK(&groups); + AST_RWLIST_TRAVERSE(&groups, gi, list) { if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || !strcasecmp(gi->category, category))) count++; } - AST_LIST_UNLOCK(&groups); + AST_RWLIST_UNLOCK(&groups); return count; } @@ -933,12 +933,12 @@ int ast_app_group_match_get_count(const char *groupmatch, const char *category) if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) return 0; - AST_LIST_LOCK(&groups); - AST_LIST_TRAVERSE(&groups, gi, list) { + AST_RWLIST_RDLOCK(&groups); + AST_RWLIST_TRAVERSE(&groups, gi, list) { if (!regexec(®exbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || !strcasecmp(gi->category, category))) count++; } - AST_LIST_UNLOCK(&groups); + AST_RWLIST_UNLOCK(&groups); regfree(®exbuf); @@ -949,12 +949,12 @@ int ast_app_group_update(struct ast_channel *old, struct ast_channel *new) { struct ast_group_info *gi = NULL; - AST_LIST_LOCK(&groups); - AST_LIST_TRAVERSE(&groups, gi, list) { + AST_RWLIST_WRLOCK(&groups); + AST_RWLIST_TRAVERSE(&groups, gi, list) { if (gi->chan == old) gi->chan = new; } - AST_LIST_UNLOCK(&groups); + AST_RWLIST_UNLOCK(&groups); return 0; } @@ -963,32 +963,37 @@ int ast_app_group_discard(struct ast_channel *chan) { struct ast_group_info *gi = NULL; - AST_LIST_LOCK(&groups); - AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) { + AST_RWLIST_WRLOCK(&groups); + AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) { if (gi->chan == chan) { - AST_LIST_REMOVE_CURRENT(&groups, list); + AST_RWLIST_REMOVE_CURRENT(&groups, list); ast_free(gi); } } - AST_LIST_TRAVERSE_SAFE_END - AST_LIST_UNLOCK(&groups); + AST_RWLIST_TRAVERSE_SAFE_END + AST_RWLIST_UNLOCK(&groups); return 0; } -int ast_app_group_list_lock(void) +int ast_app_group_list_wrlock(void) { - return AST_LIST_LOCK(&groups); + return AST_RWLIST_WRLOCK(&groups); +} + +int ast_app_group_list_rdlock(void) +{ + return AST_RWLIST_RDLOCK(&groups); } struct ast_group_info *ast_app_group_list_head(void) { - return AST_LIST_FIRST(&groups); + return AST_RWLIST_FIRST(&groups); } int ast_app_group_list_unlock(void) { - return AST_LIST_UNLOCK(&groups); + return AST_RWLIST_UNLOCK(&groups); } unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen) |