<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7521">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">loader: Use vector to build apha sorted module lists.<br><br>Change-Id: I9c519f4dec3cda98b2f34d314255a31d49a6a467<br>---<br>M main/loader.c<br>1 file changed, 64 insertions(+), 27 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/7521/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/loader.c b/main/loader.c<br>index cdfdcb6..f19a4bd 100644<br>--- a/main/loader.c<br>+++ b/main/loader.c<br>@@ -135,12 +135,16 @@<br> /*! This module is being held open until it's time to shutdown. */<br> unsigned int keepuntilshutdown:1;<br> } flags;<br>- AST_LIST_ENTRY(ast_module) list_entry;<br> AST_DLLIST_ENTRY(ast_module) entry;<br> char resource[0];<br> };<br> <br> static AST_DLLIST_HEAD_STATIC(module_list, ast_module);<br>+<br>+static int module_vector_strcasecmp(struct ast_module *a, struct ast_module *b)<br>+{<br>+ return strcasecmp(a->resource, b->resource);<br>+}<br> <br> static int module_vector_cmp(struct ast_module *a, struct ast_module *b)<br> {<br>@@ -1520,29 +1524,58 @@<br> AST_LIST_UNLOCK(&updaters);<br> }<br> <br>+/*!<br>+ * \internal<br>+ * \brief Build an alpha sorted list of modules.<br>+ *<br>+ * \param alpha_module_list Pointer to uninitialized module_vector.<br>+ *<br>+ * This function always initializes alpha_module_list.<br>+ *<br>+ * \pre module_list must be locked.<br>+ */<br>+static int alpha_module_list_create(struct module_vector *alpha_module_list)<br>+{<br>+ struct ast_module *cur;<br>+<br>+ if (AST_VECTOR_INIT(alpha_module_list, 32)) {<br>+ return -1;<br>+ }<br>+<br>+ AST_DLLIST_TRAVERSE(&module_list, cur, entry) {<br>+ if (AST_VECTOR_ADD_SORTED(alpha_module_list, cur, module_vector_strcasecmp)) {<br>+ return -1;<br>+ }<br>+ }<br>+<br>+ return 0;<br>+}<br>+<br> int ast_update_module_list(int (*modentry)(const char *module, const char *description,<br> int usecnt, const char *status, const char *like,<br> enum ast_module_support_level support_level),<br> const char *like)<br> {<br>- struct ast_module *cur;<br> int unlock = -1;<br> int total_mod_loaded = 0;<br>- AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;<br>+ struct module_vector alpha_module_list;<br> <br> if (AST_DLLIST_TRYLOCK(&module_list)) {<br> unlock = 0;<br> }<br> <br>- AST_DLLIST_TRAVERSE(&module_list, cur, entry) {<br>- AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);<br>+ if (!alpha_module_list_create(&alpha_module_list)) {<br>+ int idx;<br>+<br>+ for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {<br>+ struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);<br>+<br>+ total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,<br>+ cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);<br>+ }<br> }<br> <br>- while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {<br>- total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,<br>- cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);<br>- }<br>-<br>+ AST_VECTOR_FREE(&alpha_module_list);<br> if (unlock) {<br> AST_DLLIST_UNLOCK(&module_list);<br> }<br>@@ -1556,22 +1589,24 @@<br> void *data),<br> const char *like, void *data)<br> {<br>- struct ast_module *cur;<br> int total_mod_loaded = 0;<br>- AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;<br>+ struct module_vector alpha_module_list;<br> <br> AST_DLLIST_LOCK(&module_list);<br> <br>- AST_DLLIST_TRAVERSE(&module_list, cur, entry) {<br>- AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);<br>- }<br>+ if (!alpha_module_list_create(&alpha_module_list)) {<br>+ int idx;<br> <br>- while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {<br>- total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,<br>- cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);<br>+ for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {<br>+ struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);<br>+<br>+ total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,<br>+ cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);<br>+ }<br> }<br> <br> AST_DLLIST_UNLOCK(&module_list);<br>+ AST_VECTOR_FREE(&alpha_module_list);<br> <br> return total_mod_loaded;<br> }<br>@@ -1583,23 +1618,25 @@<br> void *data, const char *condition),<br> const char *like, void *data, const char *condition)<br> {<br>- struct ast_module *cur;<br> int conditions_met = 0;<br>- AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;<br>+ struct module_vector alpha_module_list;<br> <br> AST_DLLIST_LOCK(&module_list);<br> <br>- AST_DLLIST_TRAVERSE(&module_list, cur, entry) {<br>- AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);<br>- }<br>+ if (!alpha_module_list_create(&alpha_module_list)) {<br>+ int idx;<br> <br>- while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {<br>- conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,<br>- cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,<br>- condition);<br>+ for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {<br>+ struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);<br>+<br>+ conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,<br>+ cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,<br>+ condition);<br>+ }<br> }<br> <br> AST_DLLIST_UNLOCK(&module_list);<br>+ AST_VECTOR_FREE(&alpha_module_list);<br> <br> return conditions_met;<br> }<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7521">change 7521</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/7521"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I9c519f4dec3cda98b2f34d314255a31d49a6a467 </div>
<div style="display:none"> Gerrit-Change-Number: 7521 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>