summaryrefslogtreecommitdiff
path: root/main/loader.c
diff options
context:
space:
mode:
authorCorey Farrell <git@cfware.com>2015-04-17 03:16:59 -0400
committerCorey Farrell <git@cfware.com>2015-04-27 18:37:26 -0400
commit5c1d07baf083fd791c8f717209551d9227413ef7 (patch)
tree7eff8c651efb82e89fd7918038102b84fe888ced /main/loader.c
parentd7f4788341f08f386341416aa3944c7f9bc0dc1b (diff)
Astobj2: Allow reference debugging to be enabled/disabled by config.
* The REF_DEBUG compiler flag no longer has any effect on code that uses Astobj2. It is used to determine if reference debugging is enabled by default. Reference debugging can be enabled or disabled in asterisk.conf. * Caller information is provided in logger errors for ao2 bad magic numbers. * Optimizes AO2 by merging internal functions with the public counterpart. This was possible now that we no longer require a dual ABI. ASTERISK-24974 #close Reported by: Corey Farrell Change-Id: Icf3552721fe999365ba8a8cf00a965aa6b897cc1
Diffstat (limited to 'main/loader.c')
-rw-r--r--main/loader.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/main/loader.c b/main/loader.c
index 26d229fdb..eb959fa80 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -122,10 +122,8 @@ static int modules_loaded;
struct ast_module {
const struct ast_module_info *info;
-#ifdef REF_DEBUG
- /* Used to get module references into REF_DEBUG logs */
+ /* Used to get module references into refs log */
void *ref_debug;
-#endif
void *lib; /* the shared lib, or NULL if embedded */
int usecount; /* the number of 'users' currently in this module */
struct module_user_list users; /* the list of users in the module */
@@ -199,9 +197,9 @@ void ast_module_register(const struct ast_module_info *info)
ast_debug(5, "Registering module %s\n", info->name);
mod->info = info;
-#ifdef REF_DEBUG
- mod->ref_debug = ao2_t_alloc(0, NULL, info->name);
-#endif
+ if (ast_opt_ref_debug) {
+ mod->ref_debug = ao2_t_alloc(0, NULL, info->name);
+ }
AST_LIST_HEAD_INIT(&mod->users);
/* during startup, before the loader has been initialized,
@@ -248,9 +246,7 @@ void ast_module_unregister(const struct ast_module_info *info)
if (mod) {
ast_debug(5, "Unregistering module %s\n", info->name);
AST_LIST_HEAD_DESTROY(&mod->users);
-#ifdef REF_DEBUG
ao2_cleanup(mod->ref_debug);
-#endif
ast_free(mod);
}
}
@@ -270,9 +266,9 @@ struct ast_module_user *__ast_module_user_add(struct ast_module *mod, struct ast
AST_LIST_INSERT_HEAD(&mod->users, u, entry);
AST_LIST_UNLOCK(&mod->users);
-#ifdef REF_DEBUG
- ao2_ref(mod->ref_debug, +1);
-#endif
+ if (mod->ref_debug) {
+ ao2_ref(mod->ref_debug, +1);
+ }
ast_atomic_fetchadd_int(&mod->usecount, +1);
@@ -298,9 +294,9 @@ void __ast_module_user_remove(struct ast_module *mod, struct ast_module_user *u)
return;
}
-#ifdef REF_DEBUG
- ao2_ref(mod->ref_debug, -1);
-#endif
+ if (mod->ref_debug) {
+ ao2_ref(mod->ref_debug, -1);
+ }
ast_atomic_fetchadd_int(&mod->usecount, -1);
ast_free(u);
@@ -318,9 +314,9 @@ void __ast_module_user_hangup_all(struct ast_module *mod)
ast_softhangup(u->chan, AST_SOFTHANGUP_APPUNLOAD);
}
-#ifdef REF_DEBUG
- ao2_ref(mod->ref_debug, -1);
-#endif
+ if (mod->ref_debug) {
+ ao2_ref(mod->ref_debug, -1);
+ }
ast_atomic_fetchadd_int(&mod->usecount, -1);
ast_free(u);
@@ -641,9 +637,7 @@ void ast_module_shutdown(void)
mod->info->unload();
}
AST_LIST_HEAD_DESTROY(&mod->users);
-#ifdef REF_DEBUG
ao2_cleanup(mod->ref_debug);
-#endif
ast_free(mod);
somethingchanged = 1;
}
@@ -1477,9 +1471,9 @@ struct ast_module *__ast_module_ref(struct ast_module *mod, const char *file, in
return NULL;
}
-#ifdef REF_DEBUG
- __ao2_ref_debug(mod->ref_debug, +1, "", file, line, func);
-#endif
+ if (mod->ref_debug) {
+ __ao2_ref(mod->ref_debug, +1, "", file, line, func);
+ }
ast_atomic_fetchadd_int(&mod->usecount, +1);
ast_update_use_count();
@@ -1503,9 +1497,9 @@ void __ast_module_unref(struct ast_module *mod, const char *file, int line, cons
return;
}
-#ifdef REF_DEBUG
- __ao2_ref_debug(mod->ref_debug, -1, "", file, line, func);
-#endif
+ if (mod->ref_debug) {
+ __ao2_ref(mod->ref_debug, -1, "", file, line, func);
+ }
ast_atomic_fetchadd_int(&mod->usecount, -1);
ast_update_use_count();