Skip to content

Commit c218188

Browse files
committed
module: separate del_ref from module_done
now mostly the refactor but del_ref logic will be implemented later
1 parent 90168ab commit c218188

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

src/module.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,22 @@ void module_register(struct module *module_data, struct module *parent)
125125
module_mutex_unlock(&parent->module_priv->lock);
126126
}
127127

128-
void module_done(struct module *module_data)
128+
static void
129+
module_del_ref(struct module_priv_state *module_priv)
129130
{
130-
if(!module_data)
131-
return;
132-
133-
if (module_data->module_priv == NULL) {
134-
return;
135-
}
136-
137-
struct module_priv_state *module_priv = module_data->module_priv;
138-
139131
assert(module_priv->magic == MODULE_MAGIC);
140132

141133
if(module_priv->parent) {
142134
module_mutex_lock(&module_priv->parent->lock);
143135
bool found = simple_linked_list_remove(
144-
module_priv->parent->children, module_data->module_priv);
136+
module_priv->parent->children, module_priv);
145137
assert(found);
146138
module_mutex_unlock(&module_priv->parent->lock);
147139
}
148140

149141
if(simple_linked_list_size(module_priv->children) > 0) {
150142
log_msg(LOG_LEVEL_WARNING, "Warning: Child database not empty! Remaining:\n");
151-
dump_tree(module_data, 0);
143+
dump_tree(&module_priv->wrapper, 0);
152144
module_mutex_lock(&module_priv->lock);
153145
for(void *it = simple_linked_list_it_init(module_priv->children); it != NULL; ) {
154146
struct module_priv_state *child = simple_linked_list_it_next(&it);
@@ -165,10 +157,10 @@ void module_done(struct module *module_data)
165157
fprintf(stderr, "Warning: Message queue not empty!\n");
166158
if (log_level >= LOG_LEVEL_VERBOSE) {
167159
printf("Path: ");
168-
dump_parents(module_data);
160+
dump_parents(&module_priv->wrapper);
169161
}
170162
struct message *m;
171-
while ((m = check_message(module_data))) {
163+
while ((m = check_message(&module_priv->wrapper))) {
172164
free_message(m, NULL);
173165
}
174166
}
@@ -181,10 +173,24 @@ void module_done(struct module *module_data)
181173
simple_linked_list_destroy(module_priv->msg_queue_children);
182174

183175
pthread_mutex_destroy(&module_priv->lock);
184-
module_data->module_priv = NULL; // to multiple deinit
185176
free(module_priv);
186177
}
187178

179+
void
180+
module_done(struct module *module_data)
181+
{
182+
if (!module_data) {
183+
return;
184+
}
185+
186+
if (module_data->module_priv == NULL) {
187+
return;
188+
}
189+
struct module_priv_state *module_priv = module_data->module_priv;
190+
module_del_ref(module_priv);
191+
module_data->module_priv = NULL; // to avoid multiple deinit
192+
}
193+
188194
static const char *const module_class_name_pairs[] = {
189195
[MODULE_CLASS_ROOT] = "root",
190196
[MODULE_CLASS_PORT] = "port",

0 commit comments

Comments
 (0)