Remove dispatch object allocation from Stasis publishing

While looking for areas for performance improvement, I realized that an
unused feature in Stasis was negatively impacting performance.

When a message is sent to a subscriber, a dispatch object is allocated
for the dispatch, containing the topic the message was published to, the
subscriber the message is being sent to, and the message itself.

The topic is actually unused by any subscriber in Asterisk today. And
the subscriber is associated with the taskprocessor the message is being
dispatched to.

First, this patch removes the unused topic parameter from Stasis
subscription callbacks.

Second, this patch introduces the concept of taskprocessor local data,
data that may be set on a taskprocessor and provided along with the data
pointer when a task is pushed using the ast_taskprocessor_push_local()
call. This allows the task to have both data specific to that
taskprocessor, in addition to data specific to that invocation.

With those two changes, the dispatch object can be removed completely,
and the message is simply refcounted and sent directly to the
taskprocessor.

Review: https://reviewboard.asterisk.org/r/2884/


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@400181 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
David M. Lee
2013-09-30 18:48:57 +00:00
parent 9d21631aee
commit 516dbe86a0
46 changed files with 376 additions and 282 deletions

View File

@@ -347,18 +347,6 @@ const char *stasis_topic_name(const struct stasis_topic *topic);
*/
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message);
/*!
* \brief Publish a message from a specified topic to all the subscribers of a
* possibly different topic.
* \param topic Topic to publish message to.
* \param topic Original topic message was from.
* \param message Message
* \since 12
*/
void stasis_forward_message(struct stasis_topic *topic,
struct stasis_topic *publisher_topic,
struct stasis_message *message);
/*!
* \brief Wait for all pending messages on a given topic to be processed.
* \param topic Topic to await pending messages on.
@@ -381,11 +369,10 @@ struct stasis_subscription;
/*!
* \brief Callback function type for Stasis subscriptions.
* \param data Data field provided with subscription.
* \param topic Topic to which the message was published.
* \param message Published message.
* \since 12
*/
typedef void (*stasis_subscription_cb)(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message);
typedef void (*stasis_subscription_cb)(void *data, struct stasis_subscription *sub, struct stasis_message *message);
/*!
* \brief Create a subscription.
@@ -583,8 +570,6 @@ struct stasis_message_type *stasis_cache_update_type(void);
* \since 12
*/
struct stasis_cache_update {
/*! \brief Topic that published \c new_snapshot */
struct stasis_topic *topic;
/*! \brief Convenience reference to snapshot type */
struct stasis_message_type *type;
/*! \brief Old value from the cache */

View File

@@ -62,7 +62,7 @@ struct stasis_message;
*/
struct stasis_subscription *internal_stasis_subscribe(
struct stasis_topic *topic,
void (*stasis_subscription_cb)(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message),
void (*stasis_subscription_cb)(void *data, struct stasis_subscription *sub, struct stasis_message *message),
void *data,
int needs_mailbox);

View File

@@ -175,6 +175,18 @@ struct ast_taskprocessor *ast_taskprocessor_get(const char *name, enum ast_tps_o
*/
struct ast_taskprocessor *ast_taskprocessor_create_with_listener(const char *name, struct ast_taskprocessor_listener *listener);
/*!
* \brief Sets the local data associated with a taskprocessor.
*
* \since 12.0.0
*
* See ast_taskprocessor_push_local().
*
* \param tps Task processor.
* \param local_data Local data to associate with \a tps.
*/
void ast_taskprocessor_set_local(struct ast_taskprocessor *tps, void *local_data);
/*!
* \brief Unreference the specified taskprocessor and its reference count will decrement.
*
@@ -197,6 +209,32 @@ void *ast_taskprocessor_unreference(struct ast_taskprocessor *tps);
*/
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int (*task_exe)(void *datap), void *datap);
/*! \brief Local data parameter */
struct ast_taskprocessor_local {
/*! Local data, associated with the taskprocessor. */
void *local_data;
/*! Data pointer passed with this task. */
void *data;
};
/*!
* \brief Push a task into the specified taskprocessor queue and signal the
* taskprocessor thread.
*
* The callback receives a \ref ast_taskprocessor_local struct, which contains
* both the provided \a datap pointer, and any local data set on the
* taskprocessor with ast_taskprocessor_set_local().
*
* \param tps The taskprocessor structure
* \param task_exe The task handling function to push into the taskprocessor queue
* \param datap The data to be used by the task handling function
* \retval 0 success
* \retval -1 failure
* \since 12.0.0
*/
int ast_taskprocessor_push_local(struct ast_taskprocessor *tps,
int (*task_exe)(struct ast_taskprocessor_local *local), void *datap);
/*!
* \brief Pop a task off the taskprocessor and execute it.
*