mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-20 12:20:12 +00:00
loader: Use vector to build apha sorted module lists.
Change-Id: I9c519f4dec3cda98b2f34d314255a31d49a6a467
This commit is contained in:
102
main/loader.c
102
main/loader.c
@@ -135,13 +135,17 @@ struct ast_module {
|
|||||||
/*! This module is being held open until it's time to shutdown. */
|
/*! This module is being held open until it's time to shutdown. */
|
||||||
unsigned int keepuntilshutdown:1;
|
unsigned int keepuntilshutdown:1;
|
||||||
} flags;
|
} flags;
|
||||||
AST_LIST_ENTRY(ast_module) list_entry;
|
|
||||||
AST_DLLIST_ENTRY(ast_module) entry;
|
AST_DLLIST_ENTRY(ast_module) entry;
|
||||||
char resource[0];
|
char resource[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
static AST_DLLIST_HEAD_STATIC(module_list, ast_module);
|
static AST_DLLIST_HEAD_STATIC(module_list, ast_module);
|
||||||
|
|
||||||
|
static int module_vector_strcasecmp(struct ast_module *a, struct ast_module *b)
|
||||||
|
{
|
||||||
|
return strcasecmp(a->resource, b->resource);
|
||||||
|
}
|
||||||
|
|
||||||
static int module_vector_cmp(struct ast_module *a, struct ast_module *b)
|
static int module_vector_cmp(struct ast_module *a, struct ast_module *b)
|
||||||
{
|
{
|
||||||
/* if load_pri is not set, default is 128. Lower is better */
|
/* if load_pri is not set, default is 128. Lower is better */
|
||||||
@@ -1524,32 +1528,56 @@ void ast_update_use_count(void)
|
|||||||
AST_LIST_UNLOCK(&updaters);
|
AST_LIST_UNLOCK(&updaters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \internal
|
||||||
|
* \brief Build an alpha sorted list of modules.
|
||||||
|
*
|
||||||
|
* \param alpha_module_list Pointer to uninitialized module_vector.
|
||||||
|
*
|
||||||
|
* This function always initializes alpha_module_list.
|
||||||
|
*
|
||||||
|
* \pre module_list must be locked.
|
||||||
|
*/
|
||||||
|
static int alpha_module_list_create(struct module_vector *alpha_module_list)
|
||||||
|
{
|
||||||
|
struct ast_module *cur;
|
||||||
|
|
||||||
|
if (AST_VECTOR_INIT(alpha_module_list, 32)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
|
||||||
|
if (AST_VECTOR_ADD_SORTED(alpha_module_list, cur, module_vector_strcasecmp)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int ast_update_module_list(int (*modentry)(const char *module, const char *description,
|
int ast_update_module_list(int (*modentry)(const char *module, const char *description,
|
||||||
int usecnt, const char *status, const char *like,
|
int usecnt, const char *status, const char *like,
|
||||||
enum ast_module_support_level support_level),
|
enum ast_module_support_level support_level),
|
||||||
const char *like)
|
const char *like)
|
||||||
{
|
{
|
||||||
struct ast_module *cur;
|
|
||||||
int unlock = -1;
|
|
||||||
int total_mod_loaded = 0;
|
int total_mod_loaded = 0;
|
||||||
AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
|
struct module_vector alpha_module_list;
|
||||||
|
|
||||||
if (AST_DLLIST_TRYLOCK(&module_list)) {
|
AST_DLLIST_LOCK(&module_list);
|
||||||
unlock = 0;
|
|
||||||
|
if (!alpha_module_list_create(&alpha_module_list)) {
|
||||||
|
int idx;
|
||||||
|
|
||||||
|
for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
|
||||||
|
struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
|
||||||
|
|
||||||
|
total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
|
||||||
|
cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
|
AST_DLLIST_UNLOCK(&module_list);
|
||||||
AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
|
AST_VECTOR_FREE(&alpha_module_list);
|
||||||
}
|
|
||||||
|
|
||||||
while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
|
|
||||||
total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
|
|
||||||
cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unlock) {
|
|
||||||
AST_DLLIST_UNLOCK(&module_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
return total_mod_loaded;
|
return total_mod_loaded;
|
||||||
}
|
}
|
||||||
@@ -1560,22 +1588,24 @@ int ast_update_module_list_data(int (*modentry)(const char *module, const char *
|
|||||||
void *data),
|
void *data),
|
||||||
const char *like, void *data)
|
const char *like, void *data)
|
||||||
{
|
{
|
||||||
struct ast_module *cur;
|
|
||||||
int total_mod_loaded = 0;
|
int total_mod_loaded = 0;
|
||||||
AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
|
struct module_vector alpha_module_list;
|
||||||
|
|
||||||
AST_DLLIST_LOCK(&module_list);
|
AST_DLLIST_LOCK(&module_list);
|
||||||
|
|
||||||
AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
|
if (!alpha_module_list_create(&alpha_module_list)) {
|
||||||
AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
|
int idx;
|
||||||
}
|
|
||||||
|
|
||||||
while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
|
for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
|
||||||
total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
|
struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
|
||||||
cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);
|
|
||||||
|
total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
|
||||||
|
cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_DLLIST_UNLOCK(&module_list);
|
AST_DLLIST_UNLOCK(&module_list);
|
||||||
|
AST_VECTOR_FREE(&alpha_module_list);
|
||||||
|
|
||||||
return total_mod_loaded;
|
return total_mod_loaded;
|
||||||
}
|
}
|
||||||
@@ -1587,23 +1617,25 @@ int ast_update_module_list_condition(int (*modentry)(const char *module, const c
|
|||||||
void *data, const char *condition),
|
void *data, const char *condition),
|
||||||
const char *like, void *data, const char *condition)
|
const char *like, void *data, const char *condition)
|
||||||
{
|
{
|
||||||
struct ast_module *cur;
|
|
||||||
int conditions_met = 0;
|
int conditions_met = 0;
|
||||||
AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
|
struct module_vector alpha_module_list;
|
||||||
|
|
||||||
AST_DLLIST_LOCK(&module_list);
|
AST_DLLIST_LOCK(&module_list);
|
||||||
|
|
||||||
AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
|
if (!alpha_module_list_create(&alpha_module_list)) {
|
||||||
AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
|
int idx;
|
||||||
}
|
|
||||||
|
|
||||||
while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
|
for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
|
||||||
conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,
|
struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
|
||||||
cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,
|
|
||||||
condition);
|
conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,
|
||||||
|
cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,
|
||||||
|
condition);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AST_DLLIST_UNLOCK(&module_list);
|
AST_DLLIST_UNLOCK(&module_list);
|
||||||
|
AST_VECTOR_FREE(&alpha_module_list);
|
||||||
|
|
||||||
return conditions_met;
|
return conditions_met;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user