Optimization to manager events.
authorJeff Peeler <jpeeler@digium.com>
Thu, 28 Jan 2010 22:37:15 +0000 (22:37 +0000)
committerJeff Peeler <jpeeler@digium.com>
Thu, 28 Jan 2010 22:37:15 +0000 (22:37 +0000)
When potentially sending manager events, return immediately if there are no
sessions or hooks. Also, avoid locking the hooks list if it is empty.

(issue #16455)
Reported by: atis
Patches:
      manager_hooks_trunk.patch uploaded by atis (license 242)

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

main/manager.c

index 2d1fa47..fdcf2bb 100644 (file)
@@ -4286,6 +4286,10 @@ int __ast_manager_event_multichan(int category, const char *event, int chancount
        struct ast_str *buf;
        int i;
 
+       if (!sessions && AST_RWLIST_EMPTY(&manager_hooks)) {
+               return 0;
+       }
+       
        if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE))) {
                return -1;
        }
@@ -4343,11 +4347,13 @@ int __ast_manager_event_multichan(int category, const char *event, int chancount
                ao2_iterator_destroy(&i);
        }
 
-       AST_RWLIST_RDLOCK(&manager_hooks);
-       AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
-               hook->helper(category, event, ast_str_buffer(buf));
+       if (!AST_RWLIST_EMPTY(&manager_hooks)) {
+               AST_RWLIST_RDLOCK(&manager_hooks);
+               AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
+                       hook->helper(category, event, ast_str_buffer(buf));
+               }
+               AST_RWLIST_UNLOCK(&manager_hooks);
        }
-       AST_RWLIST_UNLOCK(&manager_hooks);
 
        return 0;
 }