remove module.deleter

This commit is contained in:
Martin Pulec
2025-06-16 10:08:13 +02:00
parent dd4e68001c
commit 99588ababe
11 changed files with 44 additions and 53 deletions

View File

@@ -9,7 +9,7 @@
* Martin Pulec <martin.pulec@cesnet.cz>
* Ian Wesley-Smith <iwsmith@cct.lsu.edu>
*
* Copyright (c) 2005-2024 CESNET z.s.p.o.
* Copyright (c) 2005-2025 CESNET
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
@@ -457,7 +457,7 @@ int audio_init(struct state_audio **ret,
error:
if(s->tx_session)
module_done(CAST_MODULE(s->tx_session));
tx_done(s->tx_session);
if(s->audio_participants) {
pdb_destroy(&s->audio_participants);
}
@@ -534,7 +534,9 @@ void audio_done(struct state_audio *s)
free_message(msg, r);
}
module_done(CAST_MODULE(s->tx_session));
if (s->tx_session) {
tx_done(s->tx_session);
}
if(s->audio_network_device)
rtp_done(s->audio_network_device);
if(s->audio_participants) {

View File

@@ -3,7 +3,7 @@
* @author Martin Pulec <pulec@cesnet.cz>
*/
/*
* Copyright (c) 2016-2024 CESNET
* Copyright (c) 2016-2025 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -129,7 +129,7 @@ struct am_participant {
}
~am_participant() {
if (m_tx_session) {
module_done(CAST_MODULE(m_tx_session));
tx_done(m_tx_session);
}
if (m_network_device) {
rtp_done(m_network_device);

View File

@@ -550,9 +550,6 @@ struct state_root {
platform_pipe_close(should_exit_pipe[0]);
}
}
static void deleter(struct module *m) {
delete (state_root*) m->priv_data;
}
static void should_exit_watcher(state_root *s) {
set_thread_name(__func__);
@@ -608,11 +605,14 @@ void init_root_module(struct module *root_mod) {
root_mod->cls = MODULE_CLASS_ROOT;
root_mod->new_message = nullptr; // note that the root mod messages
// processes also the reflector
root_mod->deleter = state_root::deleter;
state_root_static = new state_root();
root_mod->priv_data = state_root_static;
}
void destroy_root_module(struct module *root_mod) {
delete (state_root *) root_mod->priv_data;
}
/**
* Exit function that sets return value and brodcasts registered modules should_exit.
*

View File

@@ -12,7 +12,7 @@
* This file contains common (global) variables and functions.
*/
/*
* Copyright (c) 2005-2024, CESNET
* Copyright (c) 2005-2025, CESNET
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
@@ -132,6 +132,7 @@ void common_cleanup(struct init_data *init_data);
// root module management
void init_root_module(struct module *root_mod);
void destroy_root_module(struct module *root_mod);
void register_should_exit_callback(struct module *mod, void (*callback)(void *), void *udata);
void unregister_should_exit_callback(struct module *mod,
void (*callback)(void *), void *udata);

View File

@@ -149,6 +149,7 @@ struct state_uv {
}
~state_uv() {
module_done(&root_module);
destroy_root_module(&root_module);
}
struct vidcap *capture_device{};

View File

@@ -3,7 +3,7 @@
* @author Martin Pulec <pulec@cesnet.cz>
*/
/*
* Copyright (c) 2013-2024 CESNET
* Copyright (c) 2013-2025 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -108,53 +108,44 @@ void module_done(struct module *module_data)
module_mutex_unlock(&module_data->parent->lock);
}
// we assume that deleter may dealloc space where are structure stored
module_mutex_lock(&module_data->lock);
struct module tmp;
memcpy(&tmp, module_data, sizeof(struct module));
module_mutex_unlock(&module_data->lock);
module_data->cls = MODULE_CLASS_NONE;
if(module_data->deleter)
module_data->deleter(module_data);
if(simple_linked_list_size(tmp.children) > 0) {
if(simple_linked_list_size(module_data->children) > 0) {
log_msg(LOG_LEVEL_WARNING, "Warning: Child database not empty! Remaining:\n");
dump_tree(&tmp, 0);
module_mutex_lock(&tmp.lock);
dump_tree(module_data, 0);
module_mutex_lock(&module_data->lock);
for(void *it = simple_linked_list_it_init(module_data->children); it != NULL; ) {
struct module *child = simple_linked_list_it_next(&it);
module_mutex_lock(&child->lock);
child->parent = NULL;
module_mutex_unlock(&child->lock);
}
module_mutex_unlock(&tmp.lock);
module_mutex_unlock(&module_data->lock);
}
simple_linked_list_destroy(tmp.children);
simple_linked_list_destroy(module_data->children);
if(simple_linked_list_size(tmp.msg_queue) > 0) {
if(simple_linked_list_size(module_data->msg_queue) > 0) {
fprintf(stderr, "Warning: Message queue not empty!\n");
if (log_level >= LOG_LEVEL_VERBOSE) {
printf("Path: ");
dump_parents(&tmp);
dump_parents(module_data);
}
struct message *m;
while ((m = check_message(&tmp))) {
while ((m = check_message(module_data))) {
free_message(m, NULL);
}
}
simple_linked_list_destroy(tmp.msg_queue);
simple_linked_list_destroy(module_data->msg_queue);
while (simple_linked_list_size(tmp.msg_queue_children) > 0) {
struct message *m = simple_linked_list_pop(tmp.msg_queue_children);
while (simple_linked_list_size(module_data->msg_queue_children) > 0) {
struct message *m = simple_linked_list_pop(module_data->msg_queue_children);
free_message_for_child(m, NULL);
}
simple_linked_list_destroy(tmp.msg_queue_children);
simple_linked_list_destroy(module_data->msg_queue_children);
pthread_mutex_destroy(&tmp.lock);
pthread_mutex_destroy(&module_data->lock);
free(tmp.name);
free(module_data->name);
}
static const char *module_class_name_pairs[] = {

View File

@@ -4,7 +4,7 @@
* @ingroup module
*/
/*
* Copyright (c) 2013-2024 CESNET
* Copyright (c) 2013-2025 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -51,7 +51,6 @@
* module_init_default(&s->mod);
* s->mod.cls = MODULE_CLASS_<NAME>; // always needed
* s->mod.priv_data = s; // optional
* s->mod.deleter = deleter; // only used for generic modules, see a note below
* module_register(&s->mod, s->parent);
* ```
*
@@ -100,12 +99,11 @@ enum module_class {
struct module;
struct simple_linked_list;
typedef void (*module_deleter_t)(struct module *);
typedef void (*notify_t)(struct module *);
/**
* @struct module
* Only members cls, deleter, priv_data and msg_queue may be directly touched
* Only members cls, priv_data and msg_queue may be directly touched
* by user. The others should be considered private.
*/
struct module {
@@ -115,7 +113,6 @@ struct module {
enum module_class cls;
struct module *parent;
struct simple_linked_list *children;
module_deleter_t deleter;
notify_t new_message; ///< if set, notifies module that new message is in queue, receiver lock is hold during the call
pthread_mutex_t msg_queue_lock; // protects msg_queue

View File

@@ -23,7 +23,7 @@
* derived from the algorithms published in that specification.
*
* Copyright (c) 2005-2010 Fundació i2CAT, Internet I Innovació Digital a Catalunya
* Copyright (c) 2005-2023 CESNET z.s.p.o.
* Copyright (c) 2005-2053 CESNET
* Copyright (c) 2001-2004 University of Southern California
* Copyright (c) 2003-2004 University of Glasgow
* Copyright (c) 1998-2001 University College London

View File

@@ -17,7 +17,7 @@
*
* Copyright (c) 2005-2010 Fundació i2CAT, Internet I Innovació Digital a Catalunya
* Copyright (c) 2001-2004 University of Southern California
* Copyright (c) 2005-2023 CESNET z.s.p.o.
* Copyright (c) 2005-2025 CESNET
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
@@ -116,7 +116,6 @@ using std::array;
using std::vector;
static void tx_update(struct tx *tx, struct video_frame *frame, int substream);
static void tx_done(struct module *tx);
static uint32_t format_interl_fps_hdr_row(enum interlacing_t interlacing, double input_fps);
static void
@@ -230,7 +229,6 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
module_init_default(&tx->mod);
tx->mod.cls = MODULE_CLASS_TX;
tx->mod.priv_data = tx;
tx->mod.deleter = tx_done;
module_register(&tx->mod, parent);
tx->magic = TRANSMIT_MAGIC;
@@ -244,7 +242,7 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
tx->last_frame_fragment_id = -1;
if (fec) {
if(!set_fec(tx, fec)) {
module_done(&tx->mod);
tx_done(tx);
return NULL;
}
}
@@ -253,13 +251,13 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
LIBRARY_CLASS_UNDEFINED, OPENSSL_ENCRYPT_ABI_VERSION));
if (!tx->enc_funcs) {
fprintf(stderr, "UltraGrid was build without OpenSSL support!\n");
module_done(&tx->mod);
tx_done(tx);
return NULL;
}
if (tx->enc_funcs->init(&tx->encryption,
encryption) != 0) {
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Unable to initialize encryption\n");
module_done(&tx->mod);
tx_done(tx);
return NULL;
}
}
@@ -405,11 +403,11 @@ static void fec_check_messages(struct tx *tx)
}
}
static void tx_done(struct module *mod)
void tx_done(struct tx *tx_session)
{
struct tx *tx = (struct tx *) mod->priv_data;
assert(tx->magic == TRANSMIT_MAGIC);
free(tx);
assert(tx_session->magic == TRANSMIT_MAGIC);
module_done(&tx_session->mod);
free(tx_session);
}
/*

View File

@@ -15,7 +15,7 @@
*
* Copyright (c) 2005-2010 Fundació i2CAT, Internet I Innovació Digital a Catalunya
* Copyright (c) 2001-2002 University of Southern California
* Copyright (c) 2005-2023 CESNET z.s.p.o.
* Copyright (c) 2005-2025 CESNET
*
* Redistribution and use in source and binary forms, with or without
* modification, is permitted provided that the following conditions
@@ -78,6 +78,7 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
void tx_send(struct tx *tx_session, struct video_frame *frame, struct rtp *rtp_session);
void format_video_header(struct video_frame *frame, int tile_idx, int buffer_idx,
uint32_t *hdr);
void tx_done(struct tx *tx_session);
void tx_send_h264(struct tx *tx_session, struct video_frame *frame, struct rtp *rtp_session);
void tx_send_h265(struct tx *tx_session, struct video_frame *frame, struct rtp *rtp_session);

View File

@@ -3,7 +3,7 @@
* @author Martin Pulec <pulec@cesnet.cz>
*/
/*
* Copyright (c) 2013-2024 CESNET z.s.p.o.
* Copyright (c) 2013-2025 CESNET
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -227,7 +227,7 @@ rtp_video_rxtx::rtp_video_rxtx(map<string, param_u> const &params) :
rtp_video_rxtx::~rtp_video_rxtx()
{
if (m_tx) {
module_done(CAST_MODULE(m_tx));
tx_done(m_tx);
}
m_network_devices_lock.lock();