MT#55283 modernise t_hash_table_iter

Change-Id: Ie7e6e794f6b2cd2905f154aecbc92c9681fd535a
pull/2079/head
Richard Fuchs 4 months ago
parent 0b726872b7
commit cb3edfb996

@ -651,8 +651,7 @@ static void __call_iterator_remove(call_t *c) {
}
void call_free(void) {
mqtt_timer_stop(&global_mqtt_timer);
rtpe_calls_ht_iter iter;
t_hash_table_iter_init(&iter, rtpe_callhash);
__auto_type iter = t_hash_table_iter(rtpe_callhash);
call_t *c;
while (t_hash_table_iter_next(&iter, NULL, &c)) {
__call_iterator_remove(c);
@ -1229,8 +1228,7 @@ void __rtp_stats_update(rtp_stats_ht dst, struct codec_store *cs) {
/* "src" is a call_media->codecs table, while "dst" is a
* packet_stream->rtp_stats table */
codecs_ht_iter iter;
t_hash_table_iter_init(&iter, src);
__auto_type iter = t_hash_table_iter(src);
while (t_hash_table_iter_next(&iter, NULL, &pt))
rtp_stats_add_pt(dst, pt);
@ -3048,8 +3046,7 @@ static void media_update_extmap(struct call_media *media, struct stream_params *
}
// clean up of orig table
extmap_ht_iter iter;
t_hash_table_iter_init(&iter, orig);
__auto_type iter = t_hash_table_iter(orig);
struct rtp_extension *ext;
while (t_hash_table_iter_next(&iter, NULL, &ext))
rtp_extension_free(ext);
@ -4674,8 +4671,7 @@ const rtp_payload_type *__rtp_stats_codec(struct call_media *m) {
ps = m->streams.head->data;
rtp_stats_ht_iter iter;
t_hash_table_iter_init(&iter, ps->rtp_stats);
__auto_type iter = t_hash_table_iter(ps->rtp_stats);
struct rtp_stats *rs, *top = NULL;
while (t_hash_table_iter_next(&iter, NULL, &rs)) {
if (!top || __rtp_stats_sort(rs, top) < 0)

@ -3213,12 +3213,11 @@ stats:
}
static void ng_list_calls(ng_command_ctx_t *ctx, parser_arg output, long long int limit) {
rtpe_calls_ht_iter iter;
const ng_parser_t *parser = ctx->parser_ctx.parser;
rwlock_lock_r(&rtpe_callhash_lock);
t_hash_table_iter_init (&iter, rtpe_callhash);
__auto_type iter = t_hash_table_iter(rtpe_callhash);
str *key;
while (limit-- && t_hash_table_iter_next (&iter, &key, NULL)) {
parser->list_add_str_dup(output, key);
@ -4484,8 +4483,7 @@ static void parse_templates(charp_ht templates) {
if (!t_hash_table_is_set(templates))
return;
charp_ht_iter iter;
t_hash_table_iter_init(&iter, templates);
__auto_type iter = t_hash_table_iter(templates);
char *keyp, *valuep;
while (t_hash_table_iter_next(&iter, &keyp, &valuep)) {
char *key = keyp;

@ -1827,8 +1827,7 @@ static void cli_incoming_list_transcoders(str *instr, struct cli_writer *cw, con
int last_tv_sec = rtpe_now / 1000000L - 1;
unsigned int idx = last_tv_sec & 1;
codec_stats_ht_iter iter;
t_hash_table_iter_init(&iter, rtpe_codec_stats);
__auto_type iter = t_hash_table_iter(rtpe_codec_stats);
char *chain;
struct codec_stats *stats_entry;
while (t_hash_table_iter_next(&iter, &chain, &stats_entry)) {

@ -43,8 +43,7 @@ static void control_list(struct control_tcp *c, struct streambuf_stream *s) {
mutex_lock(&c->listener.lock);
tcp_streams_ht_iter iter;
t_hash_table_iter_init(&iter, c->listener.streams);
__auto_type iter = t_hash_table_iter(c->listener.streams);
struct streambuf_stream *cl;
while (t_hash_table_iter_next(&iter, NULL, &cl))

@ -123,8 +123,7 @@ static void dtmf_bencode_and_notify(struct call_media *media, unsigned int event
bencode_dictionary_add_str(data, "source_label", &ml->label);
}
tags_ht_iter iter;
t_hash_table_iter_init(&iter, call->tags);
__auto_type iter = t_hash_table_iter(call->tags);
struct call_monologue *tml;
while (t_hash_table_iter_next(&iter, NULL, &tml))
bencode_list_add_str(tags, &tml->tag);
@ -162,8 +161,7 @@ static GString *dtmf_json_print(struct call_media *media, unsigned int event, un
STR_FMT(&ml->tag),
STR_FMT(ml->label.s ? &ml->label : &STR_EMPTY));
tags_ht_iter iter;
t_hash_table_iter_init(&iter, call->tags);
__auto_type iter = t_hash_table_iter(call->tags);
int i = 0;
struct call_monologue *tml;
while (t_hash_table_iter_next(&iter, NULL, &tml)) {

@ -191,8 +191,7 @@ GString *print_graphite_data(void) {
int last_tv_sec = rtpe_now / 1000000 - 1;
unsigned int idx = last_tv_sec & 1;
codec_stats_ht_iter iter;
t_hash_table_iter_init(&iter, rtpe_codec_stats);
__auto_type iter = t_hash_table_iter(rtpe_codec_stats);
char *chain;
struct codec_stats *stats_entry;
while (t_hash_table_iter_next(&iter, &chain, &stats_entry)) {

@ -147,8 +147,7 @@ static void janus_send_json_sync_response(struct websocket_message *wm, JsonBuil
static void janus_send_json_async(struct janus_session *session, JsonBuilder *builder) {
char *result = glib_json_print(builder);
janus_websockets_ht_iter iter;
t_hash_table_iter_init(&iter, session->websockets);
__auto_type iter = t_hash_table_iter(session->websockets);
struct websocket_conn *wc;
while (t_hash_table_iter_next(&iter, NULL, &wc)) {
@ -398,8 +397,7 @@ static void janus_publishers_list(JsonBuilder *builder, call_t *call, struct jan
{
json_builder_begin_array(builder); // [
janus_feeds_ht_iter iter;
t_hash_table_iter_init(&iter, room->publishers);
__auto_type iter = t_hash_table_iter(room->publishers);
uint64_t *feed_id_ptr, *handle_id_ptr;
while (t_hash_table_iter_next(&iter, &handle_id_ptr, &feed_id_ptr)) {
@ -748,8 +746,7 @@ static void janus_notify_publishers(uint64_t room_id, uint64_t except, void *ptr
if (!room)
return;
janus_feeds_ht_iter iter;
t_hash_table_iter_init(&iter, room->publishers);
__auto_type iter = t_hash_table_iter(room->publishers);
uint64_t *handle_id, *feed_id;
while (t_hash_table_iter_next(&iter, &handle_id, &feed_id)) {
@ -1436,8 +1433,7 @@ static const char *janus_detach(struct websocket_message *wm, JsonReader *reader
// janus_lock must be held
static void janus_session_cleanup(struct janus_session *session) {
janus_handles_set_iter iter;
t_hash_table_iter_init(&iter, session->handles);
__auto_type iter = t_hash_table_iter(session->handles);
uint64_t *handle_id;
while (t_hash_table_iter_next(&iter, &handle_id, NULL)) {
struct janus_handle *handle = NULL;

@ -828,8 +828,7 @@ static void media_player_cache_entry_decoder_thread(struct media_player_cache_en
entry->finished = true;
cond_broadcast(&entry->cond);
media_player_ht_iter iter;
t_hash_table_iter_init(&iter, entry->wait_queue);
__auto_type iter = t_hash_table_iter(entry->wait_queue);
struct media_player *mp;
while (t_hash_table_iter_next(&iter, &mp, NULL)) {
if (mp->media)
@ -2117,8 +2116,7 @@ static void __media_player_cache_entry_free(struct media_player_cache_entry *e)
mutex_destroy(&e->lock);
g_free(e->info_str);
if (t_hash_table_is_set(e->wait_queue)) {
media_player_ht_iter iter;
t_hash_table_iter_init(&iter, e->wait_queue);
__auto_type iter = t_hash_table_iter(e->wait_queue);
struct media_player *mp;
while (t_hash_table_iter_next(&iter, &mp, NULL))
obj_put(&mp->tt_obj);
@ -2749,9 +2747,8 @@ charp_q media_player_list_player_cache(void) {
#ifdef WITH_TRANSCODING
if (!t_hash_table_is_set(media_player_cache))
return ret;
media_player_cache_ht_iter iter;
LOCK(&media_player_cache_lock);
t_hash_table_iter_init(&iter, media_player_cache);
__auto_type iter = t_hash_table_iter(media_player_cache);
struct media_player_cache_entry *entry;
while (t_hash_table_iter_next(&iter, NULL, &entry))
t_queue_push_tail(&ret, g_strdup_printf("%s for PT " STR_FORMAT, entry->info_str,
@ -2778,10 +2775,9 @@ unsigned int media_player_evict_player_caches(void) {
// grab references from hash table
media_player_cache_entry_q q = TYPED_GQUEUE_INIT;
media_player_cache_ht_iter iter;
{
LOCK(&media_player_cache_lock);
t_hash_table_iter_init(&iter, media_player_cache);
__auto_type iter = t_hash_table_iter(media_player_cache);
struct media_player_cache_entry *entry;
while (t_hash_table_iter_next(&iter, NULL, &entry))
t_queue_push_tail(&q, obj_get(entry));

@ -1534,8 +1534,7 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(kernelize_state, kernelize_state_clear)
__attribute__((nonnull(1, 2)))
static void fill_bundle_pt_stats(kernelize_state *s, struct call_media *bundle, unsigned int component) {
pt_media_ht_iter iter;
t_hash_table_iter_init(&iter, bundle->pt_media);
__auto_type iter = t_hash_table_iter(bundle->pt_media);
void *pt;
struct call_media *pt_media;
while (t_hash_table_iter_next(&iter, &pt, &pt_media)) {
@ -1556,8 +1555,7 @@ static void fill_pt_stats(kernelize_state *s, struct packet_stream *stream, unsi
return;
}
rtp_stats_ht_iter iter;
t_hash_table_iter_init(&iter, stream->rtp_stats);
__auto_type iter = t_hash_table_iter(stream->rtp_stats);
struct rtp_stats *rs;
while (t_hash_table_iter_next(&iter, NULL, &rs) && s->num_payload_types < RTPE_NUM_PAYLOAD_TYPES) {
s->pts[s->num_payload_types].stream = stream;
@ -4041,15 +4039,13 @@ void interfaces_free(void) {
t_hash_table_destroy(__logical_intf_name_family_hash);
local_intf_ht_iter l_iter;
t_hash_table_iter_init(&l_iter, __local_intf_addr_type_hash);
__auto_type l_iter = t_hash_table_iter(__local_intf_addr_type_hash);
local_intf_list *lifl;
while (t_hash_table_iter_next(&l_iter, NULL, &lifl))
t_list_free(lifl);
t_hash_table_destroy(__local_intf_addr_type_hash);
intf_spec_ht_iter s_iter;
t_hash_table_iter_init(&s_iter, __intf_spec_addr_type_hash);
__auto_type s_iter = t_hash_table_iter(__intf_spec_addr_type_hash);
intf_spec_q *spec_q;
while (t_hash_table_iter_next(&s_iter, NULL, &spec_q)) {
while (spec_q->length) {
@ -4065,8 +4061,7 @@ void interfaces_free(void) {
}
t_hash_table_destroy(__intf_spec_addr_type_hash);
intf_rr_lookup_iter r_iter;
t_hash_table_iter_init(&r_iter, __logical_intf_name_family_rr_hash);
__auto_type r_iter = t_hash_table_iter(__logical_intf_name_family_rr_hash);
struct intf_rr *rr;
while (t_hash_table_iter_next(&r_iter, NULL, &rr)) {
t_queue_clear(&rr->logical_intfs);

@ -1060,8 +1060,7 @@ static void setup_media_proc(struct call_media *media) {
append_meta_chunk_null(recording, "MEDIA %u PTIME %i", media->unique_id, media->ptime);
codecs_ht_iter iter;
t_hash_table_iter_init(&iter, media->codecs.codecs);
__auto_type iter = t_hash_table_iter(media->codecs.codecs);
rtp_payload_type *pt;
while (t_hash_table_iter_next(&iter, NULL, &pt)) {

@ -3128,8 +3128,7 @@ static void append_bundle_groups(GString *out, struct call_monologue *ml, sdp_ng
}
}
bundle_ht_iter iter;
t_hash_table_iter_init(&iter, ht);
__auto_type iter = t_hash_table_iter(ht);
GString *bundle_str;
while (t_hash_table_iter_next(&iter, NULL, &bundle_str)) {

@ -882,8 +882,7 @@ stats_metric_q *statistics_gather_metrics(struct interface_sampled_rate_stats *i
int last_tv_sec = rtpe_now / 1000000 - 1;
unsigned int idx = last_tv_sec & 1;
codec_stats_ht_iter iter;
t_hash_table_iter_init(&iter, rtpe_codec_stats);
codec_stats_ht_iter iter = t_hash_table_iter(rtpe_codec_stats);
char *chain;
struct codec_stats *stats_entry;
while (t_hash_table_iter_next(&iter, &chain, &stats_entry)) {

@ -781,8 +781,7 @@ static void websocket_conn_cleanup(struct websocket_conn *wc) {
// detach all Janus sessions
if (t_hash_table_is_set(janus_sessions)) {
janus_sessions_ht_iter iter;
t_hash_table_iter_init(&iter, janus_sessions);
__auto_type iter = t_hash_table_iter(janus_sessions);
struct janus_session *session;
while (t_hash_table_iter_next(&iter, &session, NULL)) {
janus_detach_websocket(session, wc);

@ -14,18 +14,20 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) {
#endif
#define TYPED_GHASHTABLE_PROTO(type_name, key_type, value_type) \
typedef union type_name##_iter type_name##_iter; \
typedef union { \
GHashTable *ht; \
/* unused members to store the contained types */ \
key_type *__key; \
const key_type *__ckey; \
value_type *__value; \
type_name##_iter *__iter; \
} type_name; \
typedef union { \
union type_name##_iter { \
GHashTableIter it; \
/* unused members to store the contained types */ \
type_name __ht; \
} type_name##_iter; \
}; \
static inline type_name type_name##_null(void) { \
return (type_name) { NULL }; \
} \
@ -98,9 +100,10 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) {
__ret; \
})
#define t_hash_table_iter_init(i, h) ({ \
__typeof__((i)->__ht) *__h = &(h); \
g_hash_table_iter_init(&(i)->it, __h->ht); \
#define t_hash_table_iter(h) ({ \
__typeof__(*(h).__iter) __ret; \
g_hash_table_iter_init(&__ret.it, (h).ht); \
__ret; \
})
#define t_hash_table_iter_next(i, kp, vp) ({ \

@ -281,8 +281,7 @@ static void db_do_call_metadata(metafile_t *mf) {
MYSQL_BIND b[3];
my_ull(&b[0], &mf->db_id); // stays persistent
metadata_ht_iter iter;
t_hash_table_iter_init(&iter, mf->metadata_parsed);
__auto_type iter = t_hash_table_iter(mf->metadata_parsed);
str *key;
str_q *vals;
while (t_hash_table_iter_next(&iter, &key, &vals)) {

Loading…
Cancel
Save