Skip to content

Commit 75aa303

Browse files
committed
MT#55283 convert ssrc_hash to g_direct
Change-Id: I5cd5a308a8c5f6fefed94e4f594eee3a31b0f6fd
1 parent 859ac06 commit 75aa303

File tree

7 files changed

+10
-21
lines changed

7 files changed

+10
-21
lines changed

Diff for: daemon/call.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4182,7 +4182,7 @@ void call_destroy(call_t *c) {
41824182
}
41834183
}
41844184

4185-
k = g_hash_table_get_values(ml->ssrc_hash->ht);
4185+
k = g_hash_table_get_values(ml->ssrc_hash->nht);
41864186
while (k) {
41874187
struct ssrc_entry_call *se = k->data;
41884188

Diff for: daemon/call_interfaces.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3031,7 +3031,7 @@ static void ng_stats_ssrc_mos_entry_dict_avg(const ng_parser_t *parser, parser_a
30313031
}
30323032

30333033
static void ng_stats_ssrc(const ng_parser_t *parser, parser_arg dict, struct ssrc_hash *ht) {
3034-
GList *ll = g_hash_table_get_values(ht->ht);
3034+
GList *ll = g_hash_table_get_values(ht->nht);
30353035

30363036
for (GList *l = ll; l; l = l->next) {
30373037
struct ssrc_entry_call *se = l->data;

Diff for: daemon/redis.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,7 @@ static str redis_encode_json(ng_parser_ctx_t *ctx, call_t *c, void **to_free) {
26372637

26382638
// SSRC table dump
26392639
rwlock_lock_r(&ml->ssrc_hash->lock);
2640-
k = g_hash_table_get_values(ml->ssrc_hash->ht);
2640+
k = g_hash_table_get_values(ml->ssrc_hash->nht);
26412641
snprintf(tmp, sizeof(tmp), "ssrc_table-%u", ml->unique_id);
26422642
parser_arg list = parser->dict_add_list_dup(root, tmp);
26432643
for (GList *m = k; m; m = m->next) {

Diff for: daemon/ssrc.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static struct ssrc_entry *create_ssrc_entry_call(void *uptr) {
5252
}
5353
static void add_ssrc_entry(uint32_t ssrc, struct ssrc_entry *ent, struct ssrc_hash *ht) {
5454
init_ssrc_entry(ent, ssrc);
55-
g_hash_table_replace(ht->ht, &ent->ssrc, ent);
55+
g_hash_table_replace(ht->nht, GUINT_TO_POINTER(ent->ssrc), ent);
5656
obj_hold(ent); // HT entry
5757
g_queue_push_tail(&ht->q, ent);
5858
obj_hold(ent); // queue entry
@@ -190,7 +190,7 @@ static void *find_ssrc(uint32_t ssrc, struct ssrc_hash *ht) {
190190
rwlock_lock_r(&ht->lock);
191191
struct ssrc_entry *ret = atomic_get_na(&ht->cache);
192192
if (!ret || ret->ssrc != ssrc) {
193-
ret = g_hash_table_lookup(ht->ht, &ssrc);
193+
ret = g_hash_table_lookup(ht->nht, GUINT_TO_POINTER(ssrc));
194194
if (ret) {
195195
obj_hold(ret);
196196
// cache shares the reference from ht
@@ -253,11 +253,11 @@ void *get_ssrc_full(uint32_t ssrc, struct ssrc_hash *ht, bool *created) {
253253
"deleting SSRC %s%x%s",
254254
FMT_M(ssrc), FMT_M(old_ent->ssrc));
255255
atomic_set(&ht->cache, NULL);
256-
g_hash_table_remove(ht->ht, &old_ent->ssrc); // does obj_put
256+
g_hash_table_remove(ht->nht, GUINT_TO_POINTER(old_ent->ssrc)); // does obj_put
257257
obj_put(old_ent); // for the queue entry
258258
}
259259

260-
if (g_hash_table_lookup(ht->ht, &ssrc)) {
260+
if (g_hash_table_lookup(ht->nht, GUINT_TO_POINTER(ssrc))) {
261261
// preempted
262262
rwlock_unlock_w(&ht->lock);
263263
// return created entry if slot is still empty
@@ -277,7 +277,7 @@ void *get_ssrc_full(uint32_t ssrc, struct ssrc_hash *ht, bool *created) {
277277
void free_ssrc_hash(struct ssrc_hash **ht) {
278278
if (!*ht)
279279
return;
280-
g_hash_table_destroy((*ht)->ht);
280+
g_hash_table_destroy((*ht)->nht);
281281
g_queue_clear_full(&(*ht)->q, ssrc_entry_put);
282282
if ((*ht)->precreat)
283283
obj_put((struct ssrc_entry *) (*ht)->precreat);
@@ -302,7 +302,7 @@ void ssrc_hash_foreach(struct ssrc_hash *sh, void (*f)(void *, void *), void *pt
302302
struct ssrc_hash *create_ssrc_hash_full_fast(ssrc_create_func_t cfunc, void *uptr) {
303303
struct ssrc_hash *ret;
304304
ret = g_new0(__typeof(*ret), 1);
305-
ret->ht = g_hash_table_new_full(uint32_hash, uint32_eq, NULL, ssrc_entry_put);
305+
ret->nht = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, ssrc_entry_put);
306306
rwlock_init(&ret->lock);
307307
ret->create_func = cfunc;
308308
ret->uptr = uptr;

Diff for: include/ssrc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ enum ssrc_dir;
1919
typedef struct ssrc_entry *(*ssrc_create_func_t)(void *uptr);
2020

2121
struct ssrc_hash {
22-
GHashTable *ht;
22+
GHashTable *nht;
2323
GQueue q;
2424
rwlock_t lock;
2525
ssrc_create_func_t create_func;

Diff for: lib/auxlib.c

-9
Original file line numberDiff line numberDiff line change
@@ -537,15 +537,6 @@ int in6_addr_eq(const void *a, const void *b) {
537537
return !memcmp(A, B, sizeof(*A));
538538
}
539539

540-
unsigned int uint32_hash(const void *p) {
541-
const uint32_t *a = p;
542-
return *a;
543-
}
544-
int uint32_eq(const void *a, const void *b) {
545-
const uint32_t *A = a, *B = b;
546-
return (*A == *B) ? TRUE : FALSE;
547-
}
548-
549540
int timeval_cmp_zero(const void *a, const void *b) {
550541
const struct timeval *A = a, *B = b;
551542

Diff for: lib/auxlib.h

-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,6 @@ int thread_create(void *(*func)(void *), void *arg, bool joinable, pthread_t *ha
114114

115115
unsigned int in6_addr_hash(const void *p);
116116
int in6_addr_eq(const void *a, const void *b);
117-
unsigned int uint32_hash(const void *p);
118-
int uint32_eq(const void *a, const void *b);
119117
int num_cpu_cores(int);
120118

121119

0 commit comments

Comments
 (0)