summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Liguori <aliguori@us.ibm.com>2009-05-14 17:57:31 -0500
committerAnthony Liguori <aliguori@us.ibm.com>2009-05-14 18:06:49 -0500
commitf7897430950ee94fb2dc4d6a5ca658d4909d9d85 (patch)
tree9d94be3c723a473f529074becb19cad654664ca7 /module.c
parentSyborg (Symbian Virtual Platform) board (diff)
downloadqemu-kvm-f7897430950ee94fb2dc4d6a5ca658d4909d9d85.tar.gz
qemu-kvm-f7897430950ee94fb2dc4d6a5ca658d4909d9d85.tar.bz2
qemu-kvm-f7897430950ee94fb2dc4d6a5ca658d4909d9d85.zip
Fix module initialization when more than 1 class is in use
Now that we're using enums for module types, it makes no sense to bother keeping a list of module types when we know exactly how many they are. Switching to an array simplifies the code and eliminates the aforementioned bug. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'module.c')
-rw-r--r--module.c57
1 files changed, 23 insertions, 34 deletions
diff --git a/module.c b/module.c
index 113eeefc6..372928383 100644
--- a/module.c
+++ b/module.c
@@ -22,44 +22,36 @@ typedef struct ModuleEntry
TAILQ_ENTRY(ModuleEntry) node;
} ModuleEntry;
-typedef struct ModuleTypeList
-{
- module_init_type type;
- TAILQ_HEAD(, ModuleEntry) entry_list;
- TAILQ_ENTRY(ModuleTypeList) node;
-} ModuleTypeList;
+typedef TAILQ_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++) {
+ TAILQ_INIT(&init_type_list[i]);
+ }
- if (!alloc)
- return NULL;
+ inited = 1;
+}
- o = qemu_mallocz(sizeof(*o));
- o->type = type;
- TAILQ_INIT(&o->entry_list);
- if (n) {
- TAILQ_INSERT_AFTER(&init_type_list, n, o, node);
- } else {
- TAILQ_INSERT_HEAD(&init_type_list, o, node);
- }
+static ModuleTypeList *find_type(module_init_type type)
+{
+ ModuleTypeList *l;
- n = o;
- }
+ init_types();
+
+ l = &init_type_list[type];
- return n;
+ return l;
}
void register_module_init(void (*fn)(void), module_init_type type)
@@ -70,9 +62,9 @@ void register_module_init(void (*fn)(void), module_init_type type)
e = qemu_mallocz(sizeof(*e));
e->init = fn;
- l = find_type_or_alloc(type, 1);
+ l = find_type(type);
- TAILQ_INSERT_TAIL(&l->entry_list, e, node);
+ TAILQ_INSERT_TAIL(l, e, node);
}
void module_call_init(module_init_type type)
@@ -80,12 +72,9 @@ 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) {
+ TAILQ_FOREACH(e, l, node) {
e->init();
}
}