* This work is licensed under the terms of the GNU GPL, version 2. See
* the COPYING file in the top-level directory.
*
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
*/
#include "qemu-common.h"
-#include "sys-queue.h"
+#include "qemu-queue.h"
#include "module.h"
typedef struct ModuleEntry
{
- module_init_type type;
void (*init)(void);
- TAILQ_ENTRY(ModuleEntry) node;
+ QTAILQ_ENTRY(ModuleEntry) node;
} ModuleEntry;
-typedef struct ModuleTypeList
-{
- module_init_type type;
- TAILQ_HEAD(, ModuleEntry) entry_list;
- TAILQ_ENTRY(ModuleTypeList) node;
-} ModuleTypeList;
+typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList;
-static TAILQ_HEAD(, ModuleTypeList) init_type_list;
+static ModuleTypeList init_type_list[MODULE_INIT_MAX];
-static ModuleTypeList *find_type_or_alloc(module_init_type type, int alloc)
+static void init_types(void)
{
- ModuleTypeList *n;
+ static int inited;
+ int i;
- TAILQ_FOREACH(n, &init_type_list, node) {
- if (type >= n->type)
- break;
+ if (inited) {
+ return;
}
- if (!n || n->type != type) {
- ModuleTypeList *o;
+ for (i = 0; i < MODULE_INIT_MAX; i++) {
+ QTAILQ_INIT(&init_type_list[i]);
+ }
+
+ inited = 1;
+}
- if (!alloc)
- return NULL;
- o = qemu_mallocz(sizeof(*o));
- o->type = type;
- TAILQ_INIT(&o->entry_list);
+static ModuleTypeList *find_type(module_init_type type)
+{
+ ModuleTypeList *l;
- if (n) {
- TAILQ_INSERT_AFTER(&init_type_list, n, o, node);
- } else {
- TAILQ_INSERT_HEAD(&init_type_list, o, node);
- }
+ init_types();
- n = o;
- }
+ l = &init_type_list[type];
- return n;
+ return l;
}
void register_module_init(void (*fn)(void), module_init_type type)
ModuleEntry *e;
ModuleTypeList *l;
- e = qemu_mallocz(sizeof(*e));
+ e = g_malloc0(sizeof(*e));
e->init = fn;
- l = find_type_or_alloc(type, 1);
+ l = find_type(type);
- TAILQ_INSERT_TAIL(&l->entry_list, e, node);
+ QTAILQ_INSERT_TAIL(l, e, node);
}
void module_call_init(module_init_type type)
ModuleTypeList *l;
ModuleEntry *e;
- l = find_type_or_alloc(type, 0);
- if (!l) {
- return;
- }
+ l = find_type(type);
- TAILQ_FOREACH(e, &l->entry_list, node) {
+ QTAILQ_FOREACH(e, l, node) {
e->init();
}
}