]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Ensure manager hooks are executed when there are no manager sessions.
authorJeff Peeler <jpeeler@digium.com>
Thu, 28 Jan 2010 22:50:21 +0000 (22:50 +0000)
committerJeff Peeler <jpeeler@digium.com>
Thu, 28 Jan 2010 22:50:21 +0000 (22:50 +0000)
Conditional expanded to check for hooks before aborting manager event
processing. The other two changes are just optimizations.

(closes issue #16455)
Reported by: atis
Patches:
      manager_hooks_16.patch uploaded by atis (license 242)
Tested by: atis

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

main/manager.c

index dea59e97560b46ede64403cd3b0a5e163945681b..6eb05981f3eb35edf754bceddb77bf71556e6fea 100644 (file)
@@ -3083,8 +3083,8 @@ int __manager_event(int category, const char *event,
        struct timeval now;
        struct ast_str *buf;
 
-       /* Abort if there aren't any manager sessions */
-       if (!num_sessions)
+       /* Abort if there are neither any manager sessions nor hooks */
+       if (!num_sessions && AST_RWLIST_EMPTY(&manager_hooks))
                return 0;
 
        if (!(buf = ast_str_thread_get(&manager_event_buf, MANAGER_EVENT_BUF_INITSIZE)))
@@ -3119,27 +3119,31 @@ int __manager_event(int category, const char *event,
        append_event(buf->str, category);
 
        /* Wake up any sleeping sessions */
-       AST_LIST_LOCK(&sessions);
-       AST_LIST_TRAVERSE(&sessions, session, list) {
-               ast_mutex_lock(&session->__lock);
-               if (session->waiting_thread != AST_PTHREADT_NULL)
-                       pthread_kill(session->waiting_thread, SIGURG);
-               else
-                       /* We have an event to process, but the mansession is
-                        * not waiting for it. We still need to indicate that there
-                        * is an event waiting so that get_input processes the pending
-                        * event instead of polling.
-                        */
-                       session->pending_event = 1;
-               ast_mutex_unlock(&session->__lock);
+       if (num_sessions) {
+               AST_LIST_LOCK(&sessions);
+               AST_LIST_TRAVERSE(&sessions, session, list) {
+                       ast_mutex_lock(&session->__lock);
+                       if (session->waiting_thread != AST_PTHREADT_NULL)
+                               pthread_kill(session->waiting_thread, SIGURG);
+                       else
+                               /* We have an event to process, but the mansession is
+                                * not waiting for it. We still need to indicate that there
+                                * is an event waiting so that get_input processes the pending
+                                * event instead of polling.
+                                */
+                               session->pending_event = 1;
+                       ast_mutex_unlock(&session->__lock);
+               }
+               AST_LIST_UNLOCK(&sessions);
        }
-       AST_LIST_UNLOCK(&sessions);
 
-       AST_RWLIST_RDLOCK(&manager_hooks);
-       AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
-               hook->helper(category, event, buf->str);
+       if (!AST_RWLIST_EMPTY(&manager_hooks)) {
+               AST_RWLIST_RDLOCK(&manager_hooks);
+               AST_RWLIST_TRAVERSE(&manager_hooks, hook, list) {
+                       hook->helper(category, event, buf->str);
+               }
+               AST_RWLIST_UNLOCK(&manager_hooks);
        }
-       AST_RWLIST_UNLOCK(&manager_hooks);
 
        return 0;
 }