Browse Source

MT#63317 type safety for free functions

Change-Id: I31cf09d7bd8d00626f95dc84a3cd9e0c48026d49
rfuchs/dtls-ice
Richard Fuchs 4 months ago
parent
commit
60a3637b20
4 changed files with 16 additions and 7 deletions
  1. +2
    -1
      daemon/janus.c
  2. +3
    -3
      daemon/media_player.c
  3. +1
    -1
      daemon/sdp.c
  4. +10
    -2
      lib/containers.h

+ 2
- 1
daemon/janus.c View File

@ -28,7 +28,8 @@ struct janus_session { // "login" session
janus_handles_set handles; // handle ID -> 0x1. handle ID owned by janus_handles
};
TYPED_GHASHTABLE(janus_sessions_ht, uint64_t, struct janus_session, int64_hash, int64_eq, NULL, __obj_put)
TYPED_GHASHTABLE(janus_sessions_ht, uint64_t, struct janus_session, int64_hash, int64_eq, NULL,
(void (*)(struct janus_session *)) __obj_put)
struct janus_handle { // corresponds to a conference participant


+ 3
- 3
daemon/media_player.c View File

@ -109,12 +109,12 @@ static gboolean media_player_cache_entry_eq(const struct media_player_cache_inde
static void __media_player_cache_entry_free(struct media_player_cache_entry *p);
TYPED_GHASHTABLE(media_player_cache_ht, struct media_player_cache_index, struct media_player_cache_entry,
media_player_cache_entry_hash, media_player_cache_entry_eq,
NULL, __obj_put)
NULL, (void(*)(struct media_player_cache_entry *)) __obj_put)
TYPED_GQUEUE(media_player_cache_entry, struct media_player_cache_entry)
static media_player_cache_ht media_player_cache; // keys and values only ever freed at shutdown
TYPED_GHASHTABLE(media_player_media_files_ht, str, struct media_player_media_file, str_hash, str_equal,
NULL, __obj_put);
NULL, (void(*)(struct media_player_media_file *)) __obj_put);
static mutex_t media_player_media_files_lock = MUTEX_STATIC_INIT;
static media_player_media_files_ht media_player_media_files;
static rwlock_t media_player_media_files_names_lock = RWLOCK_STATIC_INIT;
@ -122,7 +122,7 @@ static str_q media_player_media_files_names = TYPED_GQUEUE_INIT;
// lock order: media_player_media_files_names_lock first, media_player_media_files_lock second
TYPED_GHASHTABLE(media_player_db_media_ht, void, struct media_player_media_file, g_direct_hash, g_direct_equal,
NULL, __obj_put);
NULL, (void(*)(struct media_player_media_file *)) __obj_put);
static mutex_t media_player_db_media_lock = MUTEX_STATIC_INIT;
static media_player_db_media_ht media_player_db_media;
static rwlock_t media_player_db_media_ids_lock = RWLOCK_STATIC_INIT;


+ 1
- 1
daemon/sdp.c View File

@ -80,7 +80,7 @@ struct sdp_connection {
TYPED_GQUEUE(attributes, struct sdp_attribute)
TYPED_GHASHTABLE(attr_id_ht, void, struct sdp_attribute, g_direct_hash, g_direct_equal, NULL, NULL)
TYPED_GHASHTABLE(attr_list_ht, void, attributes_q, g_direct_hash, g_direct_equal, NULL, g_queue_free)
TYPED_GHASHTABLE(attr_list_ht, void, attributes_q, g_direct_hash, g_direct_equal, NULL, attributes_q_free)
TYPED_GHASHTABLE_LOOKUP_INSERT(attr_list_ht, NULL, attributes_q_new)
struct sdp_attributes {


+ 10
- 2
lib/containers.h View File

@ -125,9 +125,17 @@ static inline void g_queue_clear_full(GQueue *q, GDestroyNotify free_func) {
__typeof__(((type_name *)0)->__ckey))) (eq_func), \
default: (eq_func) \
); \
void (*__k_free_func)(__typeof__(((type_name *)0)->__key)) = _Generic((key_free_func), \
void (*)(void *): (void (*)(__typeof__(((type_name *)0)->__key))) (key_free_func), \
default: (key_free_func) \
); \
void (*__v_free_func)(__typeof__(((type_name *)0)->__value)) = _Generic((value_free_func), \
void (*)(void *): (void (*)(__typeof__(((type_name *)0)->__value))) (value_free_func), \
default: (value_free_func) \
); \
GHashTable *ht = g_hash_table_new_full((GHashFunc) __hash_func, (GEqualFunc) __eq_func, \
(GDestroyNotify) key_free_func, \
(GDestroyNotify) value_free_func); \
(GDestroyNotify) __k_free_func, \
(GDestroyNotify) __v_free_func); \
return (type_name) { ht }; \
} \


Loading…
Cancel
Save