mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-18 15:49:56 +00:00
Merge "Fix deadlock handling subscribe req during res_parking reload" into 13
This commit is contained in:
85
main/pbx.c
85
main/pbx.c
@@ -373,6 +373,7 @@ struct ast_hint {
|
|||||||
};
|
};
|
||||||
|
|
||||||
STASIS_MESSAGE_TYPE_DEFN_LOCAL(hint_change_message_type);
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(hint_change_message_type);
|
||||||
|
STASIS_MESSAGE_TYPE_DEFN_LOCAL(hint_remove_message_type);
|
||||||
|
|
||||||
#define HINTDEVICE_DATA_LENGTH 16
|
#define HINTDEVICE_DATA_LENGTH 16
|
||||||
AST_THREADSTORAGE(hintdevice_data);
|
AST_THREADSTORAGE(hintdevice_data);
|
||||||
@@ -3560,6 +3561,30 @@ static void device_state_cb(void *unused, struct stasis_subscription *sub, struc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hint_remove_message_type() == stasis_message_type(msg)) {
|
||||||
|
/* The extension has already been destroyed */
|
||||||
|
struct ast_state_cb *state_cb;
|
||||||
|
struct ao2_iterator cb_iter;
|
||||||
|
struct ast_hint *hint = stasis_message_data(msg);
|
||||||
|
|
||||||
|
ao2_lock(hint);
|
||||||
|
hint->laststate = AST_EXTENSION_DEACTIVATED;
|
||||||
|
ao2_unlock(hint);
|
||||||
|
|
||||||
|
cb_iter = ao2_iterator_init(hint->callbacks, 0);
|
||||||
|
for (; (state_cb = ao2_iterator_next(&cb_iter)); ao2_ref(state_cb, -1)) {
|
||||||
|
execute_state_callback(state_cb->change_cb,
|
||||||
|
hint->context_name,
|
||||||
|
hint->exten_name,
|
||||||
|
state_cb->data,
|
||||||
|
AST_HINT_UPDATE_DEVICE,
|
||||||
|
hint,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
ao2_iterator_destroy(&cb_iter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ast_device_state_message_type() != stasis_message_type(msg)) {
|
if (ast_device_state_message_type() != stasis_message_type(msg)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3809,34 +3834,7 @@ static void destroy_hint(void *obj)
|
|||||||
struct ast_hint *hint = obj;
|
struct ast_hint *hint = obj;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (hint->callbacks) {
|
ao2_cleanup(hint->callbacks);
|
||||||
struct ast_state_cb *state_cb;
|
|
||||||
const char *context_name;
|
|
||||||
const char *exten_name;
|
|
||||||
|
|
||||||
if (hint->exten) {
|
|
||||||
context_name = ast_get_context_name(ast_get_extension_context(hint->exten));
|
|
||||||
exten_name = ast_get_extension_name(hint->exten);
|
|
||||||
hint->exten = NULL;
|
|
||||||
} else {
|
|
||||||
/* The extension has already been destroyed */
|
|
||||||
context_name = hint->context_name;
|
|
||||||
exten_name = hint->exten_name;
|
|
||||||
}
|
|
||||||
hint->laststate = AST_EXTENSION_DEACTIVATED;
|
|
||||||
while ((state_cb = ao2_callback(hint->callbacks, OBJ_UNLINK, NULL, NULL))) {
|
|
||||||
/* Notify with -1 and remove all callbacks */
|
|
||||||
execute_state_callback(state_cb->change_cb,
|
|
||||||
context_name,
|
|
||||||
exten_name,
|
|
||||||
state_cb->data,
|
|
||||||
AST_HINT_UPDATE_DEVICE,
|
|
||||||
hint,
|
|
||||||
NULL);
|
|
||||||
ao2_ref(state_cb, -1);
|
|
||||||
}
|
|
||||||
ao2_ref(hint->callbacks, -1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < AST_VECTOR_SIZE(&hint->devices); i++) {
|
for (i = 0; i < AST_VECTOR_SIZE(&hint->devices); i++) {
|
||||||
char *device = AST_VECTOR_GET(&hint->devices, i);
|
char *device = AST_VECTOR_GET(&hint->devices, i);
|
||||||
@@ -3847,6 +3845,27 @@ static void destroy_hint(void *obj)
|
|||||||
ast_free(hint->last_presence_message);
|
ast_free(hint->last_presence_message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \brief Publish a hint removed event */
|
||||||
|
static int publish_hint_remove(struct ast_hint *hint)
|
||||||
|
{
|
||||||
|
struct stasis_message *message;
|
||||||
|
|
||||||
|
if (!hint_remove_message_type()) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(message = stasis_message_create(hint_remove_message_type(), hint))) {
|
||||||
|
ao2_ref(hint, -1);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
stasis_publish(ast_device_state_topic_all(), message);
|
||||||
|
|
||||||
|
ao2_ref(message, -1);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*! \brief Remove hint from extension */
|
/*! \brief Remove hint from extension */
|
||||||
static int ast_remove_hint(struct ast_exten *e)
|
static int ast_remove_hint(struct ast_exten *e)
|
||||||
{
|
{
|
||||||
@@ -3877,6 +3896,8 @@ static int ast_remove_hint(struct ast_exten *e)
|
|||||||
hint->exten = NULL;
|
hint->exten = NULL;
|
||||||
ao2_unlock(hint);
|
ao2_unlock(hint);
|
||||||
|
|
||||||
|
publish_hint_remove(hint);
|
||||||
|
|
||||||
ao2_ref(hint, -1);
|
ao2_ref(hint, -1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -3983,8 +4004,7 @@ static int publish_hint_change(struct ast_hint *hint, struct ast_exten *ne)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The message is going to be published to two topics so the hint needs two refs */
|
if (!(message = stasis_message_create(hint_change_message_type(), hint))) {
|
||||||
if (!(message = stasis_message_create(hint_change_message_type(), ao2_bump(hint)))) {
|
|
||||||
ao2_ref(hint, -1);
|
ao2_ref(hint, -1);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -8341,6 +8361,7 @@ int load_pbx(void)
|
|||||||
}
|
}
|
||||||
stasis_subscription_accept_message_type(device_state_sub, ast_device_state_message_type());
|
stasis_subscription_accept_message_type(device_state_sub, ast_device_state_message_type());
|
||||||
stasis_subscription_accept_message_type(device_state_sub, hint_change_message_type());
|
stasis_subscription_accept_message_type(device_state_sub, hint_change_message_type());
|
||||||
|
stasis_subscription_accept_message_type(device_state_sub, hint_remove_message_type());
|
||||||
stasis_subscription_set_filter(device_state_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
|
stasis_subscription_set_filter(device_state_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
|
||||||
|
|
||||||
if (!(presence_state_sub = stasis_subscribe(ast_presence_state_topic_all(), presence_state_cb, NULL))) {
|
if (!(presence_state_sub = stasis_subscribe(ast_presence_state_topic_all(), presence_state_cb, NULL))) {
|
||||||
@@ -8697,6 +8718,7 @@ static int statecbs_cmp(void *obj, void *arg, int flags)
|
|||||||
static void pbx_shutdown(void)
|
static void pbx_shutdown(void)
|
||||||
{
|
{
|
||||||
STASIS_MESSAGE_TYPE_CLEANUP(hint_change_message_type);
|
STASIS_MESSAGE_TYPE_CLEANUP(hint_change_message_type);
|
||||||
|
STASIS_MESSAGE_TYPE_CLEANUP(hint_remove_message_type);
|
||||||
|
|
||||||
if (hints) {
|
if (hints) {
|
||||||
ao2_container_unregister("hints");
|
ao2_container_unregister("hints");
|
||||||
@@ -8773,6 +8795,9 @@ int ast_pbx_init(void)
|
|||||||
if (STASIS_MESSAGE_TYPE_INIT(hint_change_message_type) != 0) {
|
if (STASIS_MESSAGE_TYPE_INIT(hint_change_message_type) != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (STASIS_MESSAGE_TYPE_INIT(hint_remove_message_type) != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return (hints && hintdevices && statecbs) ? 0 : -1;
|
return (hints && hintdevices && statecbs) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user