Browse Source

MT#55283 use typed GHashTables for globals calls hash

Change-Id: I9de9bc9ae8d35cd2360e58d9f4358cacc6831be1
pull/1776/head
Richard Fuchs 2 years ago
parent
commit
7c6f5d1dae
5 changed files with 26 additions and 24 deletions
  1. +14
    -14
      daemon/call.c
  2. +6
    -6
      daemon/call_interfaces.c
  3. +2
    -2
      daemon/cli.c
  4. +1
    -1
      daemon/statistics.c
  5. +3
    -1
      include/call.h

+ 14
- 14
daemon/call.c View File

@ -64,7 +64,7 @@ struct xmlrpc_helper {
};
rwlock_t rtpe_callhash_lock;
GHashTable *rtpe_callhash;
rtpe_calls_ht rtpe_callhash;
struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS];
static struct mqtt_timer *global_mqtt_timer;
@ -525,8 +525,8 @@ enum thread_looper_action call_timer(void) {
int call_init(void) {
rtpe_callhash = g_hash_table_new(str_hash, str_equal);
if (!rtpe_callhash)
rtpe_callhash = rtpe_calls_ht_new();
if (!t_hash_table_is_set(rtpe_callhash))
return -1;
rwlock_init(&rtpe_callhash_lock);
@ -587,15 +587,15 @@ static void __call_iterator_remove(struct call *c) {
}
void call_free(void) {
mqtt_timer_stop(&global_mqtt_timer);
GList *ll = g_hash_table_get_values(rtpe_callhash);
for (GList *l = ll; l; l = l->next) {
struct call *c = l->data;
rtpe_calls_ht_iter iter;
t_hash_table_iter_init(&iter, rtpe_callhash);
struct call *c;
while (t_hash_table_iter_next(&iter, NULL, &c)) {
__call_iterator_remove(c);
__call_cleanup(c);
obj_put(c);
}
g_list_free(ll);
g_hash_table_destroy(rtpe_callhash);
t_hash_table_destroy(rtpe_callhash);
}
@ -3617,10 +3617,10 @@ void call_destroy(struct call *c) {
rwlock_lock_w(&rtpe_callhash_lock);
struct call *call_ht = NULL;
g_hash_table_steal_extended(rtpe_callhash, &c->callid, NULL, (void **) &call_ht);
t_hash_table_steal_extended(rtpe_callhash, &c->callid, NULL, &call_ht);
if (call_ht) {
if (call_ht != c) {
g_hash_table_insert(rtpe_callhash, &call_ht->callid, call_ht);
t_hash_table_insert(rtpe_callhash, &call_ht->callid, call_ht);
call_ht = NULL;
}
else
@ -3974,19 +3974,19 @@ struct call *call_get_or_create(const str *callid, bool exclusive) {
restart:
rwlock_lock_r(&rtpe_callhash_lock);
c = g_hash_table_lookup(rtpe_callhash, callid);
c = t_hash_table_lookup(rtpe_callhash, callid);
if (!c) {
rwlock_unlock_r(&rtpe_callhash_lock);
/* completely new call-id, create call */
c = call_create(callid);
rwlock_lock_w(&rtpe_callhash_lock);
if (g_hash_table_lookup(rtpe_callhash, callid)) {
if (t_hash_table_lookup(rtpe_callhash, callid)) {
/* preempted */
rwlock_unlock_w(&rtpe_callhash_lock);
obj_put(c);
goto restart;
}
g_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c));
t_hash_table_insert(rtpe_callhash, &c->callid, obj_get(c));
RTPE_GAUGE_INC(total_sessions);
rwlock_lock_w(&c->master_lock);
@ -4050,7 +4050,7 @@ struct call *call_get(const str *callid) {
struct call *ret;
rwlock_lock_r(&rtpe_callhash_lock);
ret = g_hash_table_lookup(rtpe_callhash, callid);
ret = t_hash_table_lookup(rtpe_callhash, callid);
if (!ret) {
rwlock_unlock_r(&rtpe_callhash_lock);
return NULL;


+ 6
- 6
daemon/call_interfaces.c View File

@ -460,7 +460,7 @@ static void call_status_iterator(struct call *c, struct streambuf_stream *s) {
void calls_status_tcp(struct streambuf_stream *s) {
rwlock_lock_r(&rtpe_callhash_lock);
streambuf_printf(s->outbuf, "proxy %u "UINT64F"/%i/%i\n",
g_hash_table_size(rtpe_callhash),
t_hash_table_size(rtpe_callhash),
atomic64_get(&rtpe_stats_rate.bytes_user) + atomic64_get(&rtpe_stats_rate.bytes_kernel), 0, 0);
rwlock_unlock_r(&rtpe_callhash_lock);
@ -1896,7 +1896,7 @@ static enum load_limit_reasons call_offer_session_limit(void) {
rwlock_lock_r(&rtpe_config.config_lock);
if (rtpe_config.max_sessions>=0) {
rwlock_lock_r(&rtpe_callhash_lock);
if (g_hash_table_size(rtpe_callhash) -
if (t_hash_table_size(rtpe_callhash) -
atomic64_get(&rtpe_stats_gauge.foreign_sessions) >= rtpe_config.max_sessions)
{
/* foreign calls can't get rejected
@ -2535,13 +2535,13 @@ stats:
}
static void ng_list_calls(bencode_item_t *output, long long int limit) {
GHashTableIter iter;
gpointer key, value;
rtpe_calls_ht_iter iter;
rwlock_lock_r(&rtpe_callhash_lock);
g_hash_table_iter_init (&iter, rtpe_callhash);
while (limit-- && g_hash_table_iter_next (&iter, &key, &value)) {
t_hash_table_iter_init (&iter, rtpe_callhash);
str *key;
while (limit-- && t_hash_table_iter_next (&iter, &key, NULL)) {
bencode_list_add_str_dup(output, key);
}


+ 2
- 2
daemon/cli.c View File

@ -483,9 +483,9 @@ static void cli_incoming_list_totals(str *instr, struct cli_writer *cw) {
static void cli_incoming_list_numsessions(str *instr, struct cli_writer *cw) {
rwlock_lock_r(&rtpe_callhash_lock);
cw->cw_printf(cw, "Current sessions own: "UINT64F"\n", g_hash_table_size(rtpe_callhash) - atomic64_get(&rtpe_stats_gauge.foreign_sessions));
cw->cw_printf(cw, "Current sessions own: "UINT64F"\n", t_hash_table_size(rtpe_callhash) - atomic64_get(&rtpe_stats_gauge.foreign_sessions));
cw->cw_printf(cw, "Current sessions foreign: "UINT64F"\n", atomic64_get(&rtpe_stats_gauge.foreign_sessions));
cw->cw_printf(cw, "Current sessions total: %i\n", g_hash_table_size(rtpe_callhash));
cw->cw_printf(cw, "Current sessions total: %i\n", t_hash_table_size(rtpe_callhash));
rwlock_unlock_r(&rtpe_callhash_lock);
cw->cw_printf(cw, "Current transcoded media: "UINT64F"\n", atomic64_get(&rtpe_stats_gauge.transcoded_media));
cw->cw_printf(cw, "Current sessions ipv4 only media: " UINT64F "\n",


+ 1
- 1
daemon/statistics.c View File

@ -324,7 +324,7 @@ stats_metric_q *statistics_gather_metrics(struct interface_sampled_rate_stats *i
HEADER("{", "");
rwlock_lock_r(&rtpe_callhash_lock);
cur_sessions = g_hash_table_size(rtpe_callhash);
cur_sessions = t_hash_table_size(rtpe_callhash);
rwlock_unlock_r(&rtpe_callhash_lock);
METRIC("sessionsown", "Owned sessions", UINT64F, UINT64F, cur_sessions - atomic64_get(&rtpe_stats_gauge.foreign_sessions));


+ 3
- 1
include/call.h View File

@ -707,8 +707,10 @@ struct call {
* which uses call-IDs as keys and call objects as values,
* while holding a reference to each contained call.
*/
TYPED_GHASHTABLE(rtpe_calls_ht, str, struct call, str_hash, str_equal, NULL, NULL)
extern rwlock_t rtpe_callhash_lock;
extern GHashTable *rtpe_callhash;
extern rtpe_calls_ht rtpe_callhash;
extern struct call_iterator_list rtpe_call_iterators[NUM_CALL_ITERATORS];


Loading…
Cancel
Save