summaryrefslogtreecommitdiff
path: root/main/config.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-08-21 19:04:32 +0000
committerMark Michelson <mmichelson@digium.com>2012-08-21 19:04:32 +0000
commit89a5ff859d4e6a66c813f5b240d8c9f6ddb119a3 (patch)
tree9a6d125d64f7ff4c011b599218a22372ff8580bb /main/config.c
parentdb69da3667955373c06ebae66141c3cd42834fcc (diff)
Add scoped locks to Asterisk.
With the SCOPED_LOCK macro, you can create a variable that locks a specific lock and unlocks the lock when the variable goes out of scope. This is useful for situations where many breaks, continues, returns, or other interruptions would require separate unlock statements. With a scoped lock, these aren't necessary. There are specializations for mutexes, read locks, write locks, ao2 locks, ao2 read locks, ao2 write locks, and channel locks. Each of these is a SCOPED_LOCK at heart though. Review: https://reviewboard.asterisk.org/r/2060 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@371582 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/config.c')
-rw-r--r--main/config.c44
1 files changed, 17 insertions, 27 deletions
diff --git a/main/config.c b/main/config.c
index 336f51e39..bf9196316 100644
--- a/main/config.c
+++ b/main/config.c
@@ -2194,15 +2194,13 @@ static void clear_config_maps(void)
{
struct ast_config_map *map;
- ast_mutex_lock(&config_lock);
+ SCOPED_MUTEX(lock, &config_lock);
while (config_maps) {
map = config_maps;
config_maps = config_maps->next;
ast_free(map);
}
-
- ast_mutex_unlock(&config_lock);
}
static int append_mapping(const char *name, const char *driver, const char *database, const char *table, int priority)
@@ -2325,7 +2323,7 @@ int ast_config_engine_register(struct ast_config_engine *new)
{
struct ast_config_engine *ptr;
- ast_mutex_lock(&config_lock);
+ SCOPED_MUTEX(lock, &config_lock);
if (!config_engine_list) {
config_engine_list = new;
@@ -2334,7 +2332,6 @@ int ast_config_engine_register(struct ast_config_engine *new)
ptr->next = new;
}
- ast_mutex_unlock(&config_lock);
ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
return 1;
@@ -2344,7 +2341,7 @@ int ast_config_engine_deregister(struct ast_config_engine *del)
{
struct ast_config_engine *ptr, *last=NULL;
- ast_mutex_lock(&config_lock);
+ SCOPED_MUTEX(lock, &config_lock);
for (ptr = config_engine_list; ptr; ptr=ptr->next) {
if (ptr == del) {
@@ -2357,25 +2354,20 @@ int ast_config_engine_deregister(struct ast_config_engine *del)
last = ptr;
}
- ast_mutex_unlock(&config_lock);
-
return 0;
}
int ast_realtime_is_mapping_defined(const char *family)
{
struct ast_config_map *map;
- ast_mutex_lock(&config_lock);
+ SCOPED_MUTEX(lock, &config_lock);
for (map = config_maps; map; map = map->next) {
if (!strcasecmp(family, map->name)) {
- ast_mutex_unlock(&config_lock);
return 1;
}
}
- ast_mutex_unlock(&config_lock);
-
return 0;
}
@@ -2385,7 +2377,7 @@ static struct ast_config_engine *find_engine(const char *family, int priority, c
struct ast_config_engine *eng, *ret = NULL;
struct ast_config_map *map;
- ast_mutex_lock(&config_lock);
+ SCOPED_MUTEX(lock, &config_lock);
for (map = config_maps; map; map = map->next) {
if (!strcasecmp(family, map->name) && (priority == map->priority)) {
@@ -2405,8 +2397,6 @@ static struct ast_config_engine *find_engine(const char *family, int priority, c
}
}
- ast_mutex_unlock(&config_lock);
-
/* if we found a mapping, but the engine is not available, then issue a warning */
if (map && !ret)
ast_log(LOG_WARNING, "Realtime mapping for '%s' found to engine '%s', but the engine is not available\n", map->name, map->driver);
@@ -3028,24 +3018,24 @@ static char *handle_cli_core_show_config_mappings(struct ast_cli_entry *e, int c
return NULL;
}
- ast_mutex_lock(&config_lock);
+ {
+ SCOPED_MUTEX(lock, &config_lock);
- if (!config_engine_list) {
- ast_cli(a->fd, "No config mappings found.\n");
- } else {
- for (eng = config_engine_list; eng; eng = eng->next) {
- ast_cli(a->fd, "Config Engine: %s\n", eng->name);
- for (map = config_maps; map; map = map->next) {
- if (!strcasecmp(map->driver, eng->name)) {
- ast_cli(a->fd, "===> %s (db=%s, table=%s)\n", map->name, map->database,
- map->table ? map->table : map->name);
+ if (!config_engine_list) {
+ ast_cli(a->fd, "No config mappings found.\n");
+ } else {
+ for (eng = config_engine_list; eng; eng = eng->next) {
+ ast_cli(a->fd, "Config Engine: %s\n", eng->name);
+ for (map = config_maps; map; map = map->next) {
+ if (!strcasecmp(map->driver, eng->name)) {
+ ast_cli(a->fd, "===> %s (db=%s, table=%s)\n", map->name, map->database,
+ map->table ? map->table : map->name);
+ }
}
}
}
}
- ast_mutex_unlock(&config_lock);
-
return CLI_SUCCESS;
}