aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2010-01-28 22:56:59 +0000
committerjpeeler <jpeeler@f38db490-d61c-443f-a65b-d21fe96a405b>2010-01-28 22:56:59 +0000
commit523f7212310e858e32a5f4cb8f6de8ec7d1ea778 (patch)
treeeca540ec0d5cf71aa3a70dc01b1c760b9b65a868 /main
parent0941905dd5272d402998e129746b28d4e3672478 (diff)
Ensure manager hooks are executed when there are no manager sessions.
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: http://svn.digium.com/svn/asterisk/branches/1.6.2@243989 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main')
-rw-r--r--main/manager.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/main/manager.c b/main/manager.c
index f444af4b3..115976a76 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -3308,8 +3308,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)))
@@ -3343,28 +3343,32 @@ int __manager_event(int category, const char *event,
append_event(ast_str_buffer(buf), 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) {
+ /* 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);
+ }
+ AST_LIST_UNLOCK(&sessions);
}
- AST_LIST_UNLOCK(&sessions);
- 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;
}