fx: start implementing global data cleanup

This commit is contained in:
2026-06-20 15:24:23 +01:00
parent f093c0fb6e
commit 32d4d0abf2
3 changed files with 127 additions and 31 deletions
+39
View File
@@ -0,0 +1,39 @@
#include <fx/global.h>
#include <fx/thread.h>
#include <stdlib.h>
#include <string.h>
static fx_queue globals = FX_QUEUE_INIT;
static fx_mutex globals_lock = FX_MUTEX_INIT;
struct global {
fx_object *g_object;
fx_queue_entry g_entry;
};
void fx_cleanup_global(void)
{
fx_queue_entry *cur = fx_queue_first(&globals);
while (cur) {
struct global *global = fx_unbox(struct global, cur, g_entry);
cur = fx_queue_next(cur);
fx_object_unref(global->g_object);
free(global);
}
}
void fx_register_global(fx_object *obj)
{
struct global *global = malloc(sizeof *global);
if (!global) {
return;
}
memset(global, 0x0, sizeof *global);
global->g_object = fx_object_ref(obj);
fx_mutex_lock(&globals_lock);
fx_queue_push_back(&globals, &global->g_entry);
fx_mutex_unlock(&globals_lock);
}