From c5199f1c92deb9812696fb57324fcc62a490c3ff Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 19 Dec 2024 15:02:56 -0400 Subject: [PATCH] MT#61368 refactor code to remove call from hash Create a dedicated helper function to remove a call from the global call hash based on a particular call ID. No-op as this just splits out the relevant code. Change-Id: I24e4bd89be882a1d941c5e09cada9cb055982f24 --- daemon/call.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index a6ab51b0b..05bee2942 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -3860,6 +3860,19 @@ static void __call_cleanup(call_t *c) { recording_finish(c, false); } +// rtpe_callhash_lock must be held +// returns true if call ID was removed +static bool __remove_call_id_from_hash(str *callid, call_t *c) { + call_t *call_ht = NULL; + t_hash_table_steal_extended(rtpe_callhash, callid, NULL, &call_ht); + if (!call_ht) + return false; + if (call_ht == c) + return true; + t_hash_table_insert(rtpe_callhash, &call_ht->callid, call_ht); + return false; +} + /* called lock-free, but must hold a reference to the call */ void call_destroy(call_t *c) { struct packet_stream *ps=0; @@ -3873,22 +3886,14 @@ void call_destroy(call_t *c) { } rwlock_lock_w(&rtpe_callhash_lock); - call_t *call_ht = NULL; - t_hash_table_steal_extended(rtpe_callhash, &c->callid, NULL, &call_ht); - if (call_ht) { - if (call_ht != c) { - t_hash_table_insert(rtpe_callhash, &call_ht->callid, call_ht); - call_ht = NULL; - } - else - RTPE_GAUGE_DEC(total_sessions); - } + bool removed = __remove_call_id_from_hash(&c->callid, c); rwlock_unlock_w(&rtpe_callhash_lock); // if call not found in callhash => previously deleted - if (!call_ht) + if (!removed) return; + RTPE_GAUGE_DEC(total_sessions); obj_put(c);