mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-03 19:16:46 +00:00
This patch optimizes how forwards are dispatched in Stasis. Originally, forwards were dispatched as subscriptions that are invoked on the publishing thread. This did not account for the vast number of forwards we would end up having in the system, and the amount of work it would take to walk though the forward subscriptions. This patch modifies Stasis so that rather than walking the tree of forwards on every dispatch, when forwards and subscriptions are changed, the subscriber list for every topic in the tree is changed. This has a couple of benefits. First, this reduces the workload of dispatching messages. It also reduces contention when dispatching to different topics that happen to forward to the same aggregation topic (as happens with all of the channel, bridge and endpoint topics). Since forwards are no longer subscriptions, the bulk of this patch is simply changing stasis_subscription objects to stasis_forward objects (which, admittedly, I should have done in the first place.) Since this required me to yet again put in a growing array, I finally abstracted that out into a set of ast_vector macros in asterisk/vector.h. Review: https://reviewboard.asterisk.org/r/2883/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@400180 65c4cc65-6c06-0410-ace0-fbb531ad65f3
82 lines
1.8 KiB
C
82 lines
1.8 KiB
C
/*
|
|
* Asterisk -- An open source telephony toolkit.
|
|
*
|
|
* Copyright (C) 2013, Digium, Inc.
|
|
*
|
|
* Jason Parker <jparker@digium.com>
|
|
*
|
|
* See http://www.asterisk.org for more information about
|
|
* the Asterisk project. Please do not directly contact
|
|
* any of the maintainers of this project for assistance;
|
|
* the project provides a web site, mailing lists and IRC
|
|
* channels for your use.
|
|
*
|
|
* This program is free software, distributed under the terms of
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
* at the top of the source tree.
|
|
*/
|
|
|
|
/*! \file
|
|
*
|
|
* \brief System AMI event handling
|
|
*
|
|
* \author Jason Parker <jparker@digium.com>
|
|
*/
|
|
|
|
#include "asterisk.h"
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
#include "asterisk/stasis.h"
|
|
#include "asterisk/stasis_message_router.h"
|
|
#include "asterisk/stasis_system.h"
|
|
|
|
/*! \brief The \ref stasis subscription returned by the forwarding of the system topic
|
|
* to the manager topic
|
|
*/
|
|
static struct stasis_forward *topic_forwarder;
|
|
|
|
static void manager_system_shutdown(void)
|
|
{
|
|
stasis_forward_cancel(topic_forwarder);
|
|
topic_forwarder = NULL;
|
|
}
|
|
|
|
int manager_system_init(void)
|
|
{
|
|
int ret = 0;
|
|
struct stasis_topic *manager_topic;
|
|
struct stasis_topic *system_topic;
|
|
struct stasis_message_router *message_router;
|
|
|
|
manager_topic = ast_manager_get_topic();
|
|
if (!manager_topic) {
|
|
return -1;
|
|
}
|
|
message_router = ast_manager_get_message_router();
|
|
if (!message_router) {
|
|
return -1;
|
|
}
|
|
system_topic = ast_system_topic();
|
|
if (!system_topic) {
|
|
return -1;
|
|
}
|
|
|
|
topic_forwarder = stasis_forward_all(system_topic, manager_topic);
|
|
if (!topic_forwarder) {
|
|
return -1;
|
|
}
|
|
|
|
ast_register_atexit(manager_system_shutdown);
|
|
|
|
/* If somehow we failed to add any routes, just shut down the whole
|
|
* thing and fail it.
|
|
*/
|
|
if (ret) {
|
|
manager_system_shutdown();
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|