resource: fix/simplify unload

Wait for ongoing load to finish before doing anything, and do actual
unload after releasing the ires.
This commit is contained in:
Andrei Alexeyev 2023-05-08 04:13:08 +02:00
parent ca15faf23c
commit 7133618cb3
No known key found for this signature in database
GPG key ID: 72D26128040B9690

View file

@ -1092,6 +1092,7 @@ static bool unload_resource(InternalResource *ires) {
ResourceHandler *handler = get_ires_handler(ires);
const char *tname = handler->typename;
wait_for_resource_load(ires, RESF_RELOAD);
ires_lock(ires);
assert(!ires->is_transient_reloader);
@ -1113,21 +1114,19 @@ static bool unload_resource(InternalResource *ires) {
assert(ires->dependents.num_elements_occupied == 0);
ht_unset(&handler->private.mapping, ires->name);
attr_unused ResourceFlags flags = ires->res.flags;
ires_unlock(ires);
if(wait_for_resource_load(ires, RESF_RELOAD) == RES_STATUS_LOADED) {
handler->procs.unload(ires->res.data);
}
ires_lock(ires);
ires_unmake_dependent(ires, &ires->dependencies);
ires_remove_watched_paths(ires);
void *loaded_data = ires->res.data;
char *name = ires->name;
ires_release(ires);
ires_unlock(ires);
if(loaded_data) {
handler->procs.unload(loaded_data);
}
log_info("Unloaded %s '%s'", tname, name);
mem_free(name);