2
0

module.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * QEMU Module Infrastructure
  3. *
  4. * Copyright IBM, Corp. 2009
  5. *
  6. * Authors:
  7. * Anthony Liguori <aliguori@us.ibm.com>
  8. *
  9. * This work is licensed under the terms of the GNU GPL, version 2. See
  10. * the COPYING file in the top-level directory.
  11. *
  12. */
  13. #include "qemu-common.h"
  14. #include "qemu-queue.h"
  15. #include "module.h"
  16. typedef struct ModuleEntry
  17. {
  18. module_init_type type;
  19. void (*init)(void);
  20. QTAILQ_ENTRY(ModuleEntry) node;
  21. } ModuleEntry;
  22. typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList;
  23. static ModuleTypeList init_type_list[MODULE_INIT_MAX];
  24. static void init_types(void)
  25. {
  26. static int inited;
  27. int i;
  28. if (inited) {
  29. return;
  30. }
  31. for (i = 0; i < MODULE_INIT_MAX; i++) {
  32. QTAILQ_INIT(&init_type_list[i]);
  33. }
  34. inited = 1;
  35. }
  36. static ModuleTypeList *find_type(module_init_type type)
  37. {
  38. ModuleTypeList *l;
  39. init_types();
  40. l = &init_type_list[type];
  41. return l;
  42. }
  43. void register_module_init(void (*fn)(void), module_init_type type)
  44. {
  45. ModuleEntry *e;
  46. ModuleTypeList *l;
  47. e = g_malloc0(sizeof(*e));
  48. e->init = fn;
  49. l = find_type(type);
  50. QTAILQ_INSERT_TAIL(l, e, node);
  51. }
  52. void module_call_init(module_init_type type)
  53. {
  54. ModuleTypeList *l;
  55. ModuleEntry *e;
  56. l = find_type(type);
  57. QTAILQ_FOREACH(e, l, node) {
  58. e->init();
  59. }
  60. }