From 730d2f88ba18662401f4ca66ba4ea5c317a94777 Mon Sep 17 00:00:00 2001 From: Chris Rienzo Date: Fri, 13 Jun 2014 11:33:33 -0400 Subject: [PATCH] mod_rayo: rename reference counting functions to something more sensible --- src/mod/event_handlers/mod_rayo/mod_rayo.c | 98 +++++++++---------- src/mod/event_handlers/mod_rayo/mod_rayo.h | 8 +- .../event_handlers/mod_rayo/rayo_components.c | 4 +- .../mod_rayo/rayo_cpa_component.c | 12 +-- .../mod_rayo/rayo_fax_components.c | 10 +- .../mod_rayo/rayo_input_component.c | 22 +++-- .../mod_rayo/rayo_output_component.c | 8 +- .../mod_rayo/rayo_prompt_component.c | 4 +- .../mod_rayo/rayo_record_component.c | 10 +- 9 files changed, 90 insertions(+), 86 deletions(-) diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.c b/src/mod/event_handlers/mod_rayo/mod_rayo.c index 75ee53a506..1d46fdb2a5 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.c +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.c @@ -775,7 +775,7 @@ static void *SWITCH_THREAD_FUNC deliver_message_thread(switch_thread_t *thread, switch_log_printf(SWITCH_CHANNEL_ID_LOG, msg->file, "", msg->line, "", SWITCH_LOG_DEBUG, "Deliver %s => %s %s\n", msg->from_jid, msg->to_jid, iks_string(iks_stack(msg->payload), msg->payload)); actor->send_fn(actor, msg); switch_mutex_unlock(actor->mutex); - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } else if (!msg->is_reply) { /* unknown actor */ RAYO_SEND_REPLY(globals.server, msg->from_jid, iks_new_error(msg->payload, STANZA_ERROR_ITEM_NOT_FOUND)); @@ -877,7 +877,7 @@ void rayo_message_send(struct rayo_actor *from, const char *to, iks *payload, in /** * Get access to Rayo actor with JID. * @param jid the JID - * @return the actor or NULL. Call RAYO_UNLOCK() when done with pointer. + * @return the actor or NULL. Call RAYO_RELEASE() when done with pointer. */ struct rayo_actor *rayo_actor_locate(const char *jid, const char *file, int line) { @@ -903,7 +903,7 @@ struct rayo_actor *rayo_actor_locate(const char *jid, const char *file, int line /** * Get exclusive access to Rayo actor with internal ID * @param id the internal ID - * @return the actor or NULL. Call RAYO_UNLOCK() when done with pointer. + * @return the actor or NULL. Call RAYO_RELEASE() when done with pointer. */ struct rayo_actor *rayo_actor_locate_by_id(const char *id, const char *file, int line) { @@ -961,7 +961,7 @@ void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int line) /** * Increment actor ref count - locks from destruction. */ -void rayo_actor_rdlock(struct rayo_actor *actor, const char *file, int line) +void rayo_actor_retain(struct rayo_actor *actor, const char *file, int line) { if (actor) { switch_mutex_lock(globals.actors_mutex); @@ -972,18 +972,18 @@ void rayo_actor_rdlock(struct rayo_actor *actor, const char *file, int line) } /** - * Unlock rayo actor + * Release rayo actor reference */ -void rayo_actor_unlock(struct rayo_actor *actor, const char *file, int line) +void rayo_actor_release(struct rayo_actor *actor, const char *file, int line) { if (actor) { switch_mutex_lock(globals.actors_mutex); actor->ref_count--; if (actor->ref_count < 0) { /* too many unlocks detected! */ - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_WARNING, "Unlock %s: ref count = %i\n", RAYO_JID(actor), actor->ref_count); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_WARNING, "Release %s: ref count = %i\n", RAYO_JID(actor), actor->ref_count); } else { - switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_DEBUG, "Unlock %s: ref count = %i\n", RAYO_JID(actor), actor->ref_count); + switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, "", line, "", SWITCH_LOG_DEBUG, "Release %s: ref count = %i\n", RAYO_JID(actor), actor->ref_count); } if (actor->ref_count <= 0 && actor->destroy) { rayo_actor_destroy(actor, file, line); @@ -1016,7 +1016,7 @@ static struct rayo_call *rayo_call_locate(const char *call_uri, const char *file if (actor && is_call_actor(actor)) { return RAYO_CALL(actor); } else if (actor) { - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } return NULL; } @@ -1033,7 +1033,7 @@ static struct rayo_call *rayo_call_locate_by_id(const char *call_uuid, const cha if (actor && is_call_actor(actor)) { return RAYO_CALL(actor); } else if (actor) { - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } return NULL; } @@ -1203,7 +1203,7 @@ void rayo_call_set_faxing(struct rayo_call *call, int faxing) /** * Get access to Rayo mixer data. * @param mixer_name the mixer name - * @return the mixer or NULL. Call RAYO_UNLOCK() when done with mixer pointer. + * @return the mixer or NULL. Call RAYO_RELEASE() when done with mixer pointer. */ static struct rayo_mixer *rayo_mixer_locate(const char *mixer_name, const char *file, int line) { @@ -1211,7 +1211,7 @@ static struct rayo_mixer *rayo_mixer_locate(const char *mixer_name, const char * if (actor && !strcmp(RAT_MIXER, actor->type)) { return RAYO_MIXER(actor); } else if (actor) { - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } return NULL; } @@ -1407,7 +1407,7 @@ static void rayo_component_cleanup(struct rayo_actor *actor) } /* parent can now be destroyed */ - RAYO_UNLOCK(RAYO_COMPONENT(actor)->parent); + RAYO_RELEASE(RAYO_COMPONENT(actor)->parent); } /** @@ -1432,7 +1432,7 @@ struct rayo_component *_rayo_component_init(struct rayo_component *component, sw component = RAYO_COMPONENT(rayo_actor_init(RAYO_ACTOR(component), pool, type, subtype, id, jid, rayo_component_cleanup, rayo_component_send, file, line)); if (component) { - RAYO_RDLOCK(parent); + RAYO_RETAIN(parent); component->client_jid = switch_core_strdup(pool, client_jid); component->ref = switch_core_strdup(pool, ref); component->parent = parent; @@ -1562,7 +1562,7 @@ static void rayo_peer_server_cleanup(struct rayo_actor *actor) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Removing %s from peer server %s\n", RAYO_JID(client), RAYO_JID(rserver)); switch_core_hash_delete(rserver->clients, key); RAYO_CLIENT(client)->peer_server = NULL; - RAYO_UNLOCK(client); + RAYO_RELEASE(client); RAYO_DESTROY(client); } switch_core_hash_destroy(&rserver->clients); @@ -1719,7 +1719,7 @@ void rayo_server_send(struct rayo_actor *server, struct rayo_message *msg) if (!strcmp(RAT_CLIENT, client->type)) { on_client_presence(RAYO_CLIENT(client), iq); } - RAYO_UNLOCK(client); + RAYO_RELEASE(client); } return; } @@ -2080,7 +2080,7 @@ static iks *join_call(struct rayo_call *call, switch_core_session_t *session, st } else if (b_call->joined) { /* don't support multiple joined calls */ response = iks_new_error_detailed(node, STANZA_ERROR_CONFLICT, "multiple joined calls not supported"); - RAYO_UNLOCK(b_call); + RAYO_RELEASE(b_call); } else { /* bridge this call to call-uri */ switch_channel_set_variable(switch_core_session_get_channel(session), "bypass_media", bypass); @@ -2095,7 +2095,7 @@ static iks *join_call(struct rayo_call *call, switch_core_session_t *session, st RAYO_SEND_REPLY(call, iks_find_attrib_soft(request, "from"), result); iks_delete(call->pending_join_request); } - RAYO_UNLOCK(b_call); + RAYO_RELEASE(b_call); } return response; } @@ -2690,12 +2690,12 @@ static void *SWITCH_THREAD_FUNC rayo_dial_thread(switch_thread_t *thread, void * goto done; } else if (b_call->joined) { response = iks_new_error_detailed(iq, STANZA_ERROR_SERVICE_UNAVAILABLE, "b-leg already joined to another call"); - RAYO_UNLOCK(b_call); + RAYO_RELEASE(b_call); goto done; } app = "bridge"; app_args = switch_core_strdup(dtdata->pool, rayo_call_get_uuid(b_call)); - RAYO_UNLOCK(b_call); + RAYO_RELEASE(b_call); } else { /* conference */ app = "conference"; @@ -2757,7 +2757,7 @@ static void *SWITCH_THREAD_FUNC rayo_dial_thread(switch_thread_t *thread, void * /* destroy call */ RAYO_DESTROY(call); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); break; } case SWITCH_CAUSE_EXCHANGE_ROUTING_ERROR: @@ -2812,7 +2812,7 @@ done: /* destroy call */ if (call) { RAYO_DESTROY(call); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } @@ -3024,7 +3024,7 @@ static void on_client_presence(struct rayo_client *rclient, iks *node) /* destroy if not a local client (connected via peer_server) and is OFFLINE */ if (rclient->peer_server && rclient->availability == PS_OFFLINE) { RAYO_DESTROY(rclient); - RAYO_UNLOCK(rclient); + RAYO_RELEASE(rclient); } pause_when_offline(); @@ -3119,7 +3119,7 @@ static void on_mixer_delete_member_event(struct rayo_mixer *mixer, switch_event_ call->joined = 0; call->joined_id = NULL; switch_mutex_unlock(RAYO_ACTOR(call)->mutex); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } /* send mixer unjoined event to member DCP */ @@ -3164,7 +3164,7 @@ static void on_mixer_destroy_event(struct rayo_mixer *mixer, switch_event_t *eve /* remove from hash and destroy */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, destroying mixer: %s\n", RAYO_JID(mixer), rayo_mixer_get_name(mixer)); - RAYO_UNLOCK(mixer); /* release original lock */ + RAYO_RELEASE(mixer); /* release original lock */ RAYO_DESTROY(mixer); } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "destroy: NULL mixer\n"); @@ -3257,7 +3257,7 @@ static void on_mixer_add_member_event(struct rayo_mixer *mixer, switch_event_t * iks_insert_attrib(x, "mixer-name", rayo_mixer_get_name(mixer)); RAYO_SEND_MESSAGE(call, call->dcp_jid, add_member_event); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } /* broadcast member joined event to subscribers */ @@ -3268,7 +3268,7 @@ static void on_mixer_add_member_event(struct rayo_mixer *mixer, switch_event_t * iks_delete(add_member_event); if (lmixer) { - RAYO_UNLOCK(lmixer); + RAYO_RELEASE(lmixer); } } @@ -3301,7 +3301,7 @@ static void route_mixer_event(switch_event_t *event) /* TODO speaking events */ done: - RAYO_UNLOCK(mixer); + RAYO_RELEASE(mixer); } /** @@ -3336,7 +3336,7 @@ static void on_call_originate_event(struct rayo_client *rclient, switch_event_t } switch_mutex_unlock(RAYO_ACTOR(call)->mutex); } - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } /** @@ -3361,10 +3361,10 @@ static void on_call_end_event(switch_event_t *event) if (zstr(call->dial_request_id) && !call->dial_request_failed) { switch_event_dup(&call->end_event, event); RAYO_DESTROY(call); - RAYO_UNLOCK(call); /* decrement ref from creation */ + RAYO_RELEASE(call); /* decrement ref from creation */ } switch_mutex_unlock(RAYO_ACTOR(call)->mutex); - RAYO_UNLOCK(call); /* decrement this ref */ + RAYO_RELEASE(call); /* decrement this ref */ } } @@ -3381,7 +3381,7 @@ static void on_call_answer_event(struct rayo_client *rclient, switch_event_t *ev switch_event_get_header(event, "variable_rayo_call_jid"), switch_event_get_header(event, "variable_rayo_dcp_jid")); RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } @@ -3405,7 +3405,7 @@ static void on_call_ringing_event(struct rayo_client *rclient, switch_event_t *e RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent); } switch_mutex_unlock(RAYO_ACTOR(call)->mutex); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } } @@ -3458,7 +3458,7 @@ static void on_call_bridge_event(struct rayo_client *rclient, switch_event_t *ev iks_insert_attrib_printf(joined, "call-uri", "%s", b_call->joined_id); RAYO_SEND_MESSAGE(b_call, rayo_call_get_dcp_jid(b_call), revent); - RAYO_UNLOCK(b_call); + RAYO_RELEASE(b_call); } /* send A-leg event */ @@ -3470,7 +3470,7 @@ static void on_call_bridge_event(struct rayo_client *rclient, switch_event_t *ev RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } @@ -3510,7 +3510,7 @@ static void on_call_park_event(struct rayo_client *rclient, switch_event_t *even iks_insert_attrib_printf(unjoined, "call-uri", "%s", joined_id); RAYO_SEND_MESSAGE(call, RAYO_JID(rclient), revent); } - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } @@ -3524,7 +3524,7 @@ static void on_call_execute_event(struct rayo_client *rclient, switch_event_t *e struct rayo_call *call = RAYO_CALL_LOCATE_BY_ID(switch_event_get_header(event, "Unique-ID")); if (call) { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_ID(call)), SWITCH_LOG_DEBUG, "Application %s execute\n", switch_event_get_header(event, "Application")); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } @@ -3541,7 +3541,7 @@ static void on_call_execute_complete_event(struct rayo_client *rclient, switch_e switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_ID(call)), SWITCH_LOG_DEBUG, "Application %s execute complete: %s \n", app, switch_event_get_header(event, "Application-Response")); - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } } @@ -3608,7 +3608,7 @@ static void route_call_event(switch_event_t *event) /* TODO orphaned call... maybe allow events to queue so they can be delivered on reconnect? */ switch_log_printf(SWITCH_CHANNEL_UUID_LOG(uuid), SWITCH_LOG_DEBUG, "Orphaned call event %s to %s\n", switch_event_name(event->event_id), dcp_jid); } - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } } @@ -3737,7 +3737,7 @@ SWITCH_STANDARD_APP(rayo_app) /* don't need to keep call reference count incremented in session- call is destroyed after all apps finish */ if (call) { - RAYO_UNLOCK(call); + RAYO_RELEASE(call); } /* is outbound call already under control? */ @@ -3847,15 +3847,15 @@ static struct rayo_actor *xmpp_stream_client_locate(struct xmpp_stream *stream, /* previously unknown client - add it */ struct rayo_peer_server *rserver = RAYO_PEER_SERVER(xmpp_stream_get_private(stream)); actor = RAYO_ACTOR(rayo_client_create(jid, xmpp_stream_get_jid(stream), PS_UNKNOWN, rayo_client_send, rserver)); - RAYO_RDLOCK(actor); + RAYO_RETAIN(actor); } else if (strcmp(RAT_CLIENT, actor->type)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s, not a client: %s\n", xmpp_stream_get_jid(stream), jid); - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); actor = NULL; } } else { actor = RAYO_ACTOR(xmpp_stream_get_private(stream)); - RAYO_RDLOCK(actor); + RAYO_RETAIN(actor); } return actor; } @@ -3926,14 +3926,14 @@ static void on_xmpp_stream_recv(struct xmpp_stream *stream, iks *stanza) if (actor) { rayo_client_presence_check(RAYO_CLIENT(actor)); rayo_client_command_recv(RAYO_CLIENT(actor), stanza); - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } } else if (!strcmp("presence", name)) { const char *from = iks_find_attrib_soft(stanza, "from"); struct rayo_actor *actor = xmpp_stream_client_locate(stream, from); if (actor) { on_client_presence(RAYO_CLIENT(actor), stanza); - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } } else if (!strcmp("message", name)) { const char *from = iks_find_attrib_soft(stanza, "from"); @@ -3941,7 +3941,7 @@ static void on_xmpp_stream_recv(struct xmpp_stream *stream, iks *stanza) if (actor) { rayo_client_presence_check(RAYO_CLIENT(actor)); on_client_message(RAYO_CLIENT(actor), stanza); - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } } } @@ -3954,7 +3954,7 @@ static void on_xmpp_stream_destroy(struct xmpp_stream *stream) /* destroy peer server / client associated with this stream */ void *actor = xmpp_stream_get_private(stream); if (actor) { - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); RAYO_DESTROY(actor); } } @@ -4836,13 +4836,13 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_rayo_shutdown) stop_deliver_message_threads(); if (globals.console) { - RAYO_UNLOCK(globals.console); + RAYO_RELEASE(globals.console); RAYO_DESTROY(globals.console); globals.console = NULL; } if (globals.server) { - RAYO_UNLOCK(globals.server); + RAYO_RELEASE(globals.server); RAYO_DESTROY(globals.server); globals.server = NULL; } diff --git a/src/mod/event_handlers/mod_rayo/mod_rayo.h b/src/mod/event_handlers/mod_rayo/mod_rayo.h index 43ed7d3dbc..074e32fd5e 100644 --- a/src/mod/event_handlers/mod_rayo/mod_rayo.h +++ b/src/mod/event_handlers/mod_rayo/mod_rayo.h @@ -142,8 +142,8 @@ extern iks *rayo_message_remove_payload(struct rayo_message *msg); extern struct rayo_actor *rayo_actor_locate(const char *jid, const char *file, int line); extern struct rayo_actor *rayo_actor_locate_by_id(const char *id, const char *file, int line); extern int rayo_actor_seq_next(struct rayo_actor *actor); -extern void rayo_actor_rdlock(struct rayo_actor *actor, const char *file, int line); -extern void rayo_actor_unlock(struct rayo_actor *actor, const char *file, int line); +extern void rayo_actor_retain(struct rayo_actor *actor, const char *file, int line); +extern void rayo_actor_release(struct rayo_actor *actor, const char *file, int line); extern void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int line); #define RAYO_LOCATE(jid) rayo_actor_locate(jid, __FILE__, __LINE__) @@ -153,8 +153,8 @@ extern void rayo_actor_destroy(struct rayo_actor *actor, const char *file, int l #define RAYO_JID(x) RAYO_ACTOR(x)->jid #define RAYO_ID(x) RAYO_ACTOR(x)->id #define RAYO_POOL(x) RAYO_ACTOR(x)->pool -#define RAYO_RDLOCK(x) rayo_actor_rdlock(RAYO_ACTOR(x), __FILE__, __LINE__) -#define RAYO_UNLOCK(x) rayo_actor_unlock(RAYO_ACTOR(x), __FILE__, __LINE__) +#define RAYO_RETAIN(x) rayo_actor_retain(RAYO_ACTOR(x), __FILE__, __LINE__) +#define RAYO_RELEASE(x) rayo_actor_release(RAYO_ACTOR(x), __FILE__, __LINE__) #define RAYO_DESTROY(x) rayo_actor_destroy(RAYO_ACTOR(x), __FILE__, __LINE__) #define RAYO_SEQ_NEXT(x) rayo_actor_seq_next(RAYO_ACTOR(x)) diff --git a/src/mod/event_handlers/mod_rayo/rayo_components.c b/src/mod/event_handlers/mod_rayo/rayo_components.c index ac1c66175d..1232bee47a 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_components.c +++ b/src/mod/event_handlers/mod_rayo/rayo_components.c @@ -43,7 +43,7 @@ struct rayo_component *rayo_component_locate(const char *id, const char *file, i if (actor && is_component_actor(actor)) { return RAYO_COMPONENT(actor); } else if (actor) { - RAYO_UNLOCK(actor); + RAYO_RELEASE(actor); } return NULL; } @@ -114,7 +114,7 @@ void rayo_component_send_complete_event(struct rayo_component *component, iks *r { component->complete = 1; RAYO_SEND_REPLY(component, iks_find_attrib(response, "to"), response); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); } diff --git a/src/mod/event_handlers/mod_rayo/rayo_cpa_component.c b/src/mod/event_handlers/mod_rayo/rayo_cpa_component.c index 364a6b6176..634968d4a8 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_cpa_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_cpa_component.c @@ -236,7 +236,7 @@ static void rayo_cpa_detector_event(const char *jid, void *user_data) } else { switch_log_printf(SWITCH_CHANNEL_UUID_LOG(RAYO_COMPONENT(component)->parent->id), SWITCH_LOG_DEBUG, "Skipping CPA event\n"); } - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } @@ -257,7 +257,7 @@ static void rayo_cpa_component_hangup(const char *jid, void *user_data) if (component) { stop_cpa_detectors(CPA_COMPONENT(component)); rayo_component_send_complete(RAYO_COMPONENT(component), COMPONENT_COMPLETE_HANGUP); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } @@ -303,7 +303,7 @@ iks *rayo_cpa_component_start(struct rayo_actor *call, struct rayo_message *msg, if (zstr(url)) { stop_cpa_detectors(component); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "Missing grammar URL"); } @@ -318,7 +318,7 @@ iks *rayo_cpa_component_start(struct rayo_actor *call, struct rayo_message *msg, if (switch_core_hash_find(component->signals, url)) { free(url_dup); stop_cpa_detectors(component); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "Duplicate URL"); } @@ -334,7 +334,7 @@ iks *rayo_cpa_component_start(struct rayo_actor *call, struct rayo_message *msg, } else { free(url_dup); stop_cpa_detectors(component); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, error_str); } @@ -345,7 +345,7 @@ iks *rayo_cpa_component_start(struct rayo_actor *call, struct rayo_message *msg, if (!have_grammar) { stop_cpa_detectors(component); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "No grammar defined"); } diff --git a/src/mod/event_handlers/mod_rayo/rayo_fax_components.c b/src/mod/event_handlers/mod_rayo/rayo_fax_components.c index f47d9c1cf7..0ceb0532b7 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_fax_components.c +++ b/src/mod/event_handlers/mod_rayo/rayo_fax_components.c @@ -217,7 +217,7 @@ static iks *start_sendfax_component(struct rayo_actor *call, struct rayo_message switch_event_destroy(&execute_event); } rayo_call_set_faxing(RAYO_CALL(call), 0); - RAYO_UNLOCK(sendfax_component); + RAYO_RELEASE(sendfax_component); } else { /* component starting... */ rayo_component_send_start(RAYO_COMPONENT(sendfax_component), iq); @@ -225,7 +225,7 @@ static iks *start_sendfax_component(struct rayo_actor *call, struct rayo_message } else { response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to create txfax event"); rayo_call_set_faxing(RAYO_CALL(call), 0); - RAYO_UNLOCK(sendfax_component); + RAYO_RELEASE(sendfax_component); } return response; @@ -320,7 +320,7 @@ static iks *start_receivefax_component(struct rayo_actor *call, struct rayo_mess switch_event_destroy(&execute_event); } rayo_call_set_faxing(RAYO_CALL(call), 0); - RAYO_UNLOCK(receivefax_component); + RAYO_RELEASE(receivefax_component); } else { /* component starting... */ rayo_component_send_start(RAYO_COMPONENT(receivefax_component), iq); @@ -328,7 +328,7 @@ static iks *start_receivefax_component(struct rayo_actor *call, struct rayo_mess } else { response = iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "failed to create rxfax event"); rayo_call_set_faxing(RAYO_CALL(call), 0); - RAYO_UNLOCK(receivefax_component); + RAYO_RELEASE(receivefax_component); } return response; @@ -463,7 +463,7 @@ static void on_execute_complete_event(switch_event_t *event) rayo_component_send_complete_event(RAYO_COMPONENT(component), result); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } } diff --git a/src/mod/event_handlers/mod_rayo/rayo_input_component.c b/src/mod/event_handlers/mod_rayo/rayo_input_component.c index 1435b90a27..4bcab10b0d 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_input_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_input_component.c @@ -551,7 +551,7 @@ static iks *start_call_voice_input(struct input_component *component, switch_cor if (component->speech_mode && handler->voice_component) { /* don't allow multi voice input */ - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_CONFLICT, "Multiple voice input is not allowed"); } @@ -565,7 +565,7 @@ static iks *start_call_voice_input(struct input_component *component, switch_cor /* if recognition engine is different, we can't handle this request */ if (!zstr(handler->last_recognizer) && strcmp(component->recognizer, handler->last_recognizer)) { handler->voice_component = NULL; - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "Must use the same recognizer for the entire call"); } else if (zstr(handler->last_recognizer)) { @@ -582,7 +582,7 @@ static iks *start_call_voice_input(struct input_component *component, switch_cor if (!grammar) { handler->voice_component = NULL; - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, stanza_error, error_detail); } @@ -614,7 +614,7 @@ static iks *start_call_dtmf_input(struct input_component *component, switch_core /* parse the grammar */ if (!(component->grammar = srgs_parse(globals.parser, iks_find_cdata(input, "grammar")))) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Failed to parse grammar body\n"); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_BAD_REQUEST, "Failed to parse grammar body"); } @@ -654,7 +654,7 @@ static iks *start_call_input(struct input_component *component, switch_core_sess /* fire up media bug to monitor lifecycle */ if (switch_core_media_bug_add(session, "rayo_input_component", NULL, input_handler_bug_callback, handler, 0, SMBF_READ_REPLACE, &handler->bug) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Failed to create input handler media bug\n"); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "Failed to create input handler media bug"); } @@ -666,7 +666,7 @@ static iks *start_call_input(struct input_component *component, switch_core_sess /* handler bug was destroyed */ switch_mutex_unlock(handler->mutex); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Input handler media bug is closed\n"); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error_detailed(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR, "Input handler media bug is closed\n"); } @@ -767,7 +767,9 @@ static iks *stop_call_input_component(struct rayo_actor *component, struct rayo_ switch_mutex_lock(input_component->handler->mutex); input_component->stop = 1; if (input_component->speech_mode) { + switch_mutex_unlock(input_component->handler->mutex); switch_ivr_stop_detect_speech(session); + switch_mutex_lock(input_component->handler->mutex); rayo_component_send_complete(RAYO_COMPONENT(component), COMPONENT_COMPLETE_STOP); } switch_mutex_unlock(input_component->handler->mutex); @@ -789,7 +791,9 @@ static iks *start_timers_call_input_component(struct rayo_actor *component, stru if (session) { switch_mutex_lock(input_component->handler->mutex); if (input_component->speech_mode) { + switch_mutex_unlock(input_component->handler->mutex); switch_ivr_detect_speech_start_input_timers(session); + switch_mutex_lock(input_component->handler->mutex); } else { input_component->last_digit_time = switch_micro_time_now(); input_component->start_timers = 1; @@ -861,7 +865,7 @@ static void on_detected_speech_event(switch_event_t *event) rayo_component_send_complete(component, INPUT_NOMATCH); } } - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } else if (!strcasecmp("begin-speaking", speech_type)) { char *component_id = switch_mprintf("%s-input-voice", uuid); @@ -870,7 +874,7 @@ static void on_detected_speech_event(switch_event_t *event) if (component && INPUT_COMPONENT(component)->barge_event) { send_barge_event(component); } - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } else if (!strcasecmp("closed", speech_type)) { char *component_id = switch_mprintf("%s-input-voice", uuid); struct rayo_component *component = RAYO_COMPONENT_LOCATE(component_id); @@ -887,7 +891,7 @@ static void on_detected_speech_event(switch_event_t *event) /* shouldn't get here... */ rayo_component_send_complete(component, COMPONENT_COMPLETE_ERROR); } - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } switch_safe_free(event_str); diff --git a/src/mod/event_handlers/mod_rayo/rayo_output_component.c b/src/mod/event_handlers/mod_rayo/rayo_output_component.c index 9a19b1753e..82cf3a0272 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_output_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_output_component.c @@ -112,11 +112,11 @@ static iks *start_call_output(struct rayo_component *component, switch_core_sess stream.write_function(&stream, "}fileman://rayo://%s", RAYO_JID(component)); if (switch_ivr_displace_session(session, stream.data, 0, "m") == SWITCH_STATUS_SUCCESS) { - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } else { if (component->complete) { /* component is already destroyed */ - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } else { /* need to destroy component */ if (OUTPUT_COMPONENT(component)->document) { @@ -210,7 +210,7 @@ static iks *start_mixer_output_component(struct rayo_actor *mixer, struct rayo_m rayo_component_api_execute_async(component, "conference", stream.data); switch_safe_free(stream.data); - RAYO_UNLOCK(component); + RAYO_RELEASE(component); return NULL; } @@ -512,7 +512,7 @@ static switch_status_t rayo_file_open(switch_file_handle_t *handle, const char * if (status != SWITCH_STATUS_SUCCESS && context->component) { /* complete error event will be sent by calling thread */ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Status = %i\n", status); - RAYO_UNLOCK(context->component); + RAYO_RELEASE(context->component); } return status; diff --git a/src/mod/event_handlers/mod_rayo/rayo_prompt_component.c b/src/mod/event_handlers/mod_rayo/rayo_prompt_component.c index 7431558a0a..7003762839 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_prompt_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_prompt_component.c @@ -288,7 +288,7 @@ static iks *prompt_component_handle_input_error(struct rayo_actor *prompt, struc /* done */ iks_delete(PROMPT_COMPONENT(prompt)->iq); - RAYO_UNLOCK(prompt); + RAYO_RELEASE(prompt); RAYO_DESTROY(prompt); break; @@ -357,7 +357,7 @@ static iks *prompt_component_handle_output_error(struct rayo_actor *prompt, stru /* done */ iks_delete(PROMPT_COMPONENT(prompt)->iq); - RAYO_UNLOCK(prompt); + RAYO_RELEASE(prompt); RAYO_DESTROY(prompt); break; diff --git a/src/mod/event_handlers/mod_rayo/rayo_record_component.c b/src/mod/event_handlers/mod_rayo/rayo_record_component.c index 2dfd817364..d9474022f2 100644 --- a/src/mod/event_handlers/mod_rayo/rayo_record_component.c +++ b/src/mod/event_handlers/mod_rayo/rayo_record_component.c @@ -141,7 +141,7 @@ static void on_call_record_stop_event(switch_event_t *event) /* TODO assume final timeout, for now */ complete_record(component, RECORD_COMPLETE_FINAL_TIMEOUT); } - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } @@ -282,7 +282,7 @@ static iks *start_call_record_component(struct rayo_actor *call, struct rayo_mes if (start_call_record(session, component)) { rayo_component_send_start(component, iq); } else { - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR); } @@ -369,7 +369,7 @@ static void on_mixer_record_event(switch_event_t *event) complete_record(component, RECORD_COMPLETE_FINAL_TIMEOUT); } } - RAYO_UNLOCK(component); + RAYO_RELEASE(component); } } @@ -412,7 +412,7 @@ static iks *start_mixer_record_component(struct rayo_actor *mixer, struct rayo_m /* mixer doesn't allow "send" */ if (!strcmp("send", iks_find_attrib_soft(record, "direction"))) { - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error(iq, STANZA_ERROR_BAD_REQUEST); } @@ -420,7 +420,7 @@ static iks *start_mixer_record_component(struct rayo_actor *mixer, struct rayo_m if (start_mixer_record(component)) { rayo_component_send_start(component, iq); } else { - RAYO_UNLOCK(component); + RAYO_RELEASE(component); RAYO_DESTROY(component); return iks_new_error(iq, STANZA_ERROR_INTERNAL_SERVER_ERROR); }