From 43b26174d593c22fbdc24ab8023997db5f78526c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 26 Jan 2023 10:39:16 -0500 Subject: [PATCH] MT#55283 convenience function for unlock/update As Redis updates must be triggered with the call unlocked, use a convenience wrapper function to unlock, update, unref. fixes #1602 Change-Id: I67095f31fb605b6977c88d9e9b3db581dd71a0d9 --- daemon/call_interfaces.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index fdd077e2d..489e4d29a 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -314,6 +314,14 @@ void call_unlock_release(struct call **c) { rwlock_unlock_w(&(*c)->master_lock); obj_put(*c); } +INLINE void call_unlock_release_update(struct call **c) { + if (!*c) + return; + rwlock_unlock_w(&(*c)->master_lock); + redis_update_onekey(*c, rtpe_redis_write); + obj_put(*c); + *c = NULL; +} @@ -358,12 +366,8 @@ static str *call_request_lookup_tcp(char **out, enum call_opmode opmode) { ret = streams_print(&dialogue[1]->medias, 1, s.length, NULL, SAF_TCP); out2: - rwlock_unlock_w(&c->master_lock); - - redis_update_onekey(c, rtpe_redis_write); - + call_unlock_release_update(&c); ilog(LOG_INFO, "Returning to SIP proxy: "STR_FORMAT"", STR_FMT0(ret)); - obj_put(c); out: g_hash_table_destroy(infohash); @@ -2953,6 +2957,7 @@ const char *call_publish_ng(bencode_item_t *input, bencode_item_t *output, const AUTO_CLEANUP(GQueue streams, sdp_streams_free) = G_QUEUE_INIT; AUTO_CLEANUP(str sdp_in, str_free_dup) = STR_NULL; AUTO_CLEANUP(str sdp_out, str_free_dup) = STR_NULL; + AUTO_CLEANUP_NULL(struct call *call, call_unlock_release); call_ng_process_flags(&flags, input, OP_PUBLISH); @@ -2970,7 +2975,7 @@ const char *call_publish_ng(bencode_item_t *input, bencode_item_t *output, const if (sdp_streams(&parsed, &streams, &flags)) return "Incomplete SDP specification"; - struct call *call = call_get_or_create(&flags.call_id, false, false); + call = call_get_or_create(&flags.call_id, false, false); updated_created_from(call, addr, sin); struct call_monologue *ml = call_get_or_create_monologue(call, &flags.from_tag); @@ -2986,13 +2991,10 @@ const char *call_publish_ng(bencode_item_t *input, bencode_item_t *output, const sdp_out = STR_NULL; // ownership passed to output } - rwlock_unlock_w(&call->master_lock); - obj_put(call); - if (ret) return "Failed to create SDP"; - redis_update_onekey(call, rtpe_redis_write); + call_unlock_release_update(&call); return NULL; } @@ -3118,7 +3120,7 @@ const char *call_subscribe_request_ng(bencode_item_t *input, bencode_item_t *out bencode_dictionary_add_str_dup(output, "to-tag", &dest_ml->tag); - redis_update_onekey(call, rtpe_redis_write); + call_unlock_release_update(&call); return NULL; } @@ -3157,7 +3159,7 @@ const char *call_subscribe_answer_ng(bencode_item_t *input, bencode_item_t *outp if (ret) return "Failed to process subscription answer"; - redis_update_onekey(call, rtpe_redis_write); + call_unlock_release_update(&call); return NULL; } @@ -3187,7 +3189,7 @@ const char *call_unsubscribe_ng(bencode_item_t *input, bencode_item_t *output) { if (ret) return "Failed to unsubscribe"; - redis_update_onekey(call, rtpe_redis_write); + call_unlock_release_update(&call); return NULL; }