From 11b6157f29542bb0b7dccc36d9126c7165e28586 Mon Sep 17 00:00:00 2001 From: Corey Farrell Date: Fri, 20 Sep 2019 12:02:37 -0400 Subject: [PATCH] Better REF_DEBUG Change-Id: I4f94502d46a235cb48f6d20fa8f623fc1f8eecac --- include/asterisk/mwi.h | 21 +++++++++++---------- include/asterisk/stasis_state.h | 14 ++++++++++---- main/mwi.c | 26 +++++++++----------------- main/stasis_state.c | 27 ++++++++++++++++----------- 4 files changed, 46 insertions(+), 42 deletions(-) diff --git a/include/asterisk/mwi.h b/include/asterisk/mwi.h index 3ce2b0647d..b95ce3f95e 100644 --- a/include/asterisk/mwi.h +++ b/include/asterisk/mwi.h @@ -362,8 +362,11 @@ int ast_mwi_publish(struct ast_mwi_publisher *publisher, int urgent_msgs, * \since 13.28.0 * \since 16.5.0 */ -int ast_mwi_publish_by_mailbox(const char *mailbox, const char *context, int urgent_msgs, - int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid); +#define ast_mwi_publish_by_mailbox(mailbox, context, urgent_msgs, new_msgs, old_msgs, channel_id, eid) \ + __ast_mwi_publish_by_mailbox(mailbox, context, urgent_msgs, new_msgs, old_msgs, channel_id, eid, __FILE__, __LINE__, __PRETTY_FUNCTION__) +int __ast_mwi_publish_by_mailbox(const char *mailbox, const char *context, int urgent_msgs, + int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid, + const char *file, int line, const char *func); /*! * \since 12 @@ -412,13 +415,8 @@ int ast_mwi_publish_by_mailbox(const char *mailbox, const char *context, int urg * \retval 0 Success * \retval -1 Failure */ -int ast_publish_mwi_state_full( - const char *mailbox, - const char *context, - int new_msgs, - int old_msgs, - const char *channel_id, - struct ast_eid *eid); +#define ast_publish_mwi_state_full(mailbox, context, new_msgs, old_msgs, channel_id, eid) \ + ast_mwi_publish_by_mailbox(mailbox, context, 0, new_msgs, old_msgs, channel_id, eid) /*! * \since 12.2.0 @@ -444,7 +442,10 @@ int ast_publish_mwi_state_full( * \retval 0 Success * \retval -1 Failure */ -int ast_delete_mwi_state_full(const char *mailbox, const char *context, struct ast_eid *eid); +#define ast_delete_mwi_state_full(mailbox, context, eid) \ + __ast_delete_mwi_state_full(mailbox, context, eid, __FILE__, __LINE__, __PRETTY_FUNCTION__) +int __ast_delete_mwi_state_full(const char *mailbox, const char *context, struct ast_eid *eid, + const char *file, int line, const char *func); /*! \addtogroup StasisTopicsAndMessages * @{ diff --git a/include/asterisk/stasis_state.h b/include/asterisk/stasis_state.h index a1d36253ad..1f13ceea35 100644 --- a/include/asterisk/stasis_state.h +++ b/include/asterisk/stasis_state.h @@ -435,8 +435,11 @@ void stasis_state_publish(struct stasis_state_publisher *pub, struct stasis_mess * \since 13.28.0 * \since 16.5.0 */ -void stasis_state_publish_by_id(struct stasis_state_manager *manager, const char *id, - const struct ast_eid *eid, struct stasis_message *msg); +#define stasis_state_publish_by_id(manager, id, eid, msg) \ + __stasis_state_publish_by_id(manager, id, eid, msg, __FILE__, __LINE__, __PRETTY_FUNCTION__) +void __stasis_state_publish_by_id(struct stasis_state_manager *manager, const char *id, + const struct ast_eid *eid, struct stasis_message *msg, + const char *file, int line, const char *func); /*! * \brief Publish to a managed named by id topic, and remove an implicit publisher. @@ -456,8 +459,11 @@ void stasis_state_publish_by_id(struct stasis_state_manager *manager, const char * \since 13.28.0 * \since 16.5.0 */ -void stasis_state_remove_publish_by_id(struct stasis_state_manager *manager, - const char *id, const struct ast_eid *eid, struct stasis_message *msg); +#define stasis_state_remove_publish_by_id(manager, id, eid, msg) \ + __stasis_state_remove_publish_by_id(manager, id, eid, msg, __FILE__, __LINE__, __PRETTY_FUNCTION__) +void __stasis_state_remove_publish_by_id(struct stasis_state_manager *manager, + const char *id, const struct ast_eid *eid, struct stasis_message *msg, + const char *file, int line, const char *func); /*! \brief Managed stasis state event interface */ struct stasis_state_observer { diff --git a/main/mwi.c b/main/mwi.c index e81766cbc2..70c6dd57be 100644 --- a/main/mwi.c +++ b/main/mwi.c @@ -367,8 +367,9 @@ int ast_mwi_publish(struct ast_mwi_publisher *pub, int urgent_msgs, return 0; } -int ast_mwi_publish_by_mailbox(const char *mailbox, const char *context, int urgent_msgs, - int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid) +int __ast_mwi_publish_by_mailbox(const char *mailbox, const char *context, int urgent_msgs, + int new_msgs, int old_msgs, const char *channel_id, struct ast_eid *eid, + const char *file, int line, const char *func) { struct ast_mwi_state *mwi_state; struct stasis_message *msg = mwi_state_create_message( @@ -379,24 +380,15 @@ int ast_mwi_publish_by_mailbox(const char *mailbox, const char *context, int urg } mwi_state = stasis_message_data(msg); - stasis_state_publish_by_id(mwi_state_manager, mwi_state->uniqueid, NULL, msg); + __stasis_state_publish_by_id(mwi_state_manager, mwi_state->uniqueid, NULL, msg, + file, line, func); ao2_ref(msg, -1); return 0; } -int ast_publish_mwi_state_full( - const char *mailbox, - const char *context, - int new_msgs, - int old_msgs, - const char *channel_id, - struct ast_eid *eid) -{ - return ast_mwi_publish_by_mailbox(mailbox, context, 0, new_msgs, old_msgs, channel_id, eid); -} - -int ast_delete_mwi_state_full(const char *mailbox, const char *context, struct ast_eid *eid) +int __ast_delete_mwi_state_full(const char *mailbox, const char *context, struct ast_eid *eid, + const char *file, int line, const char *func) { RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); struct stasis_message *cached_msg; @@ -426,13 +418,13 @@ int ast_delete_mwi_state_full(const char *mailbox, const char *context, struct a ast_mwi_state_type(), mwi_state->uniqueid, &ast_eid_default); if (!cached_msg) { /* Nothing to clear from the cache, but still need to remove state */ - stasis_state_remove_publish_by_id(mwi_state_manager, mwi_state->uniqueid, eid, NULL); + __stasis_state_remove_publish_by_id(mwi_state_manager, mwi_state->uniqueid, eid, NULL, file, line, func); return -1; } ao2_cleanup(cached_msg); clear_msg = stasis_cache_clear_create(msg); - stasis_state_remove_publish_by_id(mwi_state_manager, mwi_state->uniqueid, eid, clear_msg); + __stasis_state_remove_publish_by_id(mwi_state_manager, mwi_state->uniqueid, eid, clear_msg, file, line, func); ao2_cleanup(clear_msg); return 0; diff --git a/main/stasis_state.c b/main/stasis_state.c index a5f1b7aa22..ae69e0ff8d 100644 --- a/main/stasis_state.c +++ b/main/stasis_state.c @@ -279,7 +279,8 @@ static struct stasis_state *__state_find_or_add(struct stasis_state_manager *man id = state_id_by_topic(manager->all_topic, state_topic); } - state = ao2_weakproxy_find(manager->states, id, OBJ_SEARCH_KEY | OBJ_NOLOCK, ""); + state = __ao2_weakproxy_find(manager->states, id, OBJ_SEARCH_KEY | OBJ_NOLOCK, + "", file, line, func); if (!state) { state = state_alloc(manager, state_topic, id, file, line, func); } @@ -583,7 +584,8 @@ void stasis_state_publish(struct stasis_state_publisher *pub, struct stasis_mess * \param state The state object * \param eid The system id to add to the state object */ -static void state_find_or_add_eid(struct stasis_state *state, const struct ast_eid *eid) +static void state_find_or_add_eid(struct stasis_state *state, const struct ast_eid *eid, + const char *file, int line, const char *func) { size_t i; @@ -599,7 +601,7 @@ static void state_find_or_add_eid(struct stasis_state *state, const struct ast_e if (i == AST_VECTOR_SIZE(&state->eids)) { if (!AST_VECTOR_APPEND(&state->eids, *eid)) { - ao2_ref(state, +1); + __ao2_ref(state, +1, __PRETTY_FUNCTION__, file, line, func); } } } @@ -616,7 +618,8 @@ static void state_find_or_add_eid(struct stasis_state *state, const struct ast_e * \param state The state object * \param eid The system id to remove from the state object */ -static void state_find_and_remove_eid(struct stasis_state *state, const struct ast_eid *eid) +static void state_find_and_remove_eid(struct stasis_state *state, const struct ast_eid *eid, + const char *file, int line, const char *func) { size_t i; @@ -627,14 +630,15 @@ static void state_find_and_remove_eid(struct stasis_state *state, const struct a for (i = 0; i < AST_VECTOR_SIZE(&state->eids); ++i) { if (!ast_eid_cmp(AST_VECTOR_GET_ADDR(&state->eids, i), eid)) { AST_VECTOR_REMOVE_UNORDERED(&state->eids, i); - ao2_ref(state, -1); + __ao2_ref(state, -1, __PRETTY_FUNCTION__, file, line, func); return; } } } -void stasis_state_publish_by_id(struct stasis_state_manager *manager, const char *id, - const struct ast_eid *eid, struct stasis_message *msg) +void __stasis_state_publish_by_id(struct stasis_state_manager *manager, const char *id, + const struct ast_eid *eid, struct stasis_message *msg, + const char *file, int line, const char *func) { struct stasis_state *state; @@ -644,7 +648,7 @@ void stasis_state_publish_by_id(struct stasis_state_manager *manager, const char } ao2_lock(state); - state_find_or_add_eid(state, eid); + state_find_or_add_eid(state, eid, file, line, func); ao2_replace(state->msg, msg); ao2_unlock(state); @@ -653,8 +657,9 @@ void stasis_state_publish_by_id(struct stasis_state_manager *manager, const char ao2_ref(state, -1); } -void stasis_state_remove_publish_by_id(struct stasis_state_manager *manager, - const char *id, const struct ast_eid *eid, struct stasis_message *msg) +void __stasis_state_remove_publish_by_id(struct stasis_state_manager *manager, + const char *id, const struct ast_eid *eid, struct stasis_message *msg, + const char *file, int line, const char *func) { struct stasis_state *state = ao2_weakproxy_find(manager->states, id, OBJ_SEARCH_KEY, ""); @@ -677,7 +682,7 @@ void stasis_state_remove_publish_by_id(struct stasis_state_manager *manager, } ao2_lock(state); - state_find_and_remove_eid(state, eid); + state_find_and_remove_eid(state, eid, file, line, func); ao2_unlock(state); ao2_ref(state, -1); -- 2.21.0