]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Make mod_load_cmp() not as klunky.
authorRichard Mudgett <rmudgett@digium.com>
Wed, 1 May 2013 20:35:25 +0000 (20:35 +0000)
committerRichard Mudgett <rmudgett@digium.com>
Wed, 1 May 2013 20:35:25 +0000 (20:35 +0000)
There is a reason the heap comparison functions like qsort(), and other
comparison functions specify <0, >0, and =0 for the return values.

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387209 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/loader.c

index c82c7e608b38dd9c0b2dc759b0253f240250efee..cf53eda991196329fc2fbe1997e95836ef5d12bd 100644 (file)
@@ -993,16 +993,17 @@ static int mod_load_cmp(void *a, void *b)
 {
        struct ast_module *a_mod = (struct ast_module *) a;
        struct ast_module *b_mod = (struct ast_module *) b;
-       int res = -1;
-       /* if load_pri is not set, default is 128.  Lower is better*/
-       unsigned char a_pri = ast_test_flag(a_mod->info, AST_MODFLAG_LOAD_ORDER) ? a_mod->info->load_pri : 128;
-       unsigned char b_pri = ast_test_flag(b_mod->info, AST_MODFLAG_LOAD_ORDER) ? b_mod->info->load_pri : 128;
-       if (a_pri == b_pri) {
-               res = 0;
-       } else if (a_pri < b_pri) {
-               res = 1;
-       }
-       return res;
+       /* if load_pri is not set, default is 128.  Lower is better */
+       int a_pri = ast_test_flag(a_mod->info, AST_MODFLAG_LOAD_ORDER) ? a_mod->info->load_pri : 128;
+       int b_pri = ast_test_flag(b_mod->info, AST_MODFLAG_LOAD_ORDER) ? b_mod->info->load_pri : 128;
+
+       /*
+        * Returns comparison values for a min-heap
+        * <0 a_pri > b_pri
+        * =0 a_pri == b_pri
+        * >0 a_pri < b_pri
+        */
+       return b_pri - a_pri;
 }
 
 /*! loads modules in order by load_pri, updates mod_count