Merge remote-tracking branch 'kraxel/usb.44' into staging
[qemu/opensuse.git] / module.c
blob106a969449d71e6be12afe4f7cb473626166d31a
1 /*
2 * QEMU Module Infrastructure
4 * Copyright IBM, Corp. 2009
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
12 * Contributions after 2012-01-13 are licensed under the terms of the
13 * GNU GPL, version 2 or (at your option) any later version.
16 #include "qemu-common.h"
17 #include "qemu-queue.h"
18 #include "module.h"
20 typedef struct ModuleEntry
22 module_init_type type;
23 void (*init)(void);
24 QTAILQ_ENTRY(ModuleEntry) node;
25 } ModuleEntry;
27 typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList;
29 static ModuleTypeList init_type_list[MODULE_INIT_MAX];
31 static void init_types(void)
33 static int inited;
34 int i;
36 if (inited) {
37 return;
40 for (i = 0; i < MODULE_INIT_MAX; i++) {
41 QTAILQ_INIT(&init_type_list[i]);
44 inited = 1;
48 static ModuleTypeList *find_type(module_init_type type)
50 ModuleTypeList *l;
52 init_types();
54 l = &init_type_list[type];
56 return l;
59 void register_module_init(void (*fn)(void), module_init_type type)
61 ModuleEntry *e;
62 ModuleTypeList *l;
64 e = g_malloc0(sizeof(*e));
65 e->init = fn;
67 l = find_type(type);
69 QTAILQ_INSERT_TAIL(l, e, node);
72 void module_call_init(module_init_type type)
74 ModuleTypeList *l;
75 ModuleEntry *e;
77 l = find_type(type);
79 QTAILQ_FOREACH(e, l, node) {
80 e->init();