diff mbox

[4/5] boards: switch machine type list to QTAILQ

Message ID 1330092792-22455-5-git-send-email-lcapitulino@redhat.com
State New
Headers show

Commit Message

Luiz Capitulino Feb. 24, 2012, 2:13 p.m. UTC
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
 hw/boards.h |    3 ++-
 vl.c        |   16 ++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

Comments

Andreas Färber Feb. 24, 2012, 2:23 p.m. UTC | #1
Am 24.02.2012 15:13, schrieb Luiz Capitulino:
> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>

Unless this fixes a bug, I'd rather not refactor this as in my head this
is already just object_class_foreach() / object_class_by_name(), similar
to CPUs on my qom-cpu branch.

Andreas

> ---
>  hw/boards.h |    3 ++-
>  vl.c        |   16 ++++++----------
>  2 files changed, 8 insertions(+), 11 deletions(-)
> 
> diff --git a/hw/boards.h b/hw/boards.h
> index 342a774..1eb8314 100644
> --- a/hw/boards.h
> +++ b/hw/boards.h
> @@ -4,6 +4,7 @@
>  #define HW_BOARDS_H
>  
>  #include "qdev.h"
> +#include "qemu-queue.h"
>  
>  typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
>                                   const char *boot_device,
> @@ -28,7 +29,7 @@ typedef struct QEMUMachine {
>      int is_default;
>      const char *default_machine_opts;
>      GlobalProperty *compat_props;
> -    struct QEMUMachine *next;
> +    QTAILQ_ENTRY(QEMUMachine) next;
>  } QEMUMachine;
>  
>  void machine_register(QEMUMachine *m);
> diff --git a/vl.c b/vl.c
> index 9f9927c..4935106 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1160,24 +1160,20 @@ void pcmcia_info(Monitor *mon)
>  /***********************************************************/
>  /* machine registration */
>  
> -static QEMUMachine *first_machine = NULL;
> +static QTAILQ_HEAD(QEMUMachineHead, QEMUMachine) machine_types = 
> +    QTAILQ_HEAD_INITIALIZER(machine_types);
>  QEMUMachine *current_machine = NULL;
>  
>  void machine_register(QEMUMachine *m)
>  {
> -    QEMUMachine **pm;
> -    pm = &first_machine;
> -    while (*pm != NULL)
> -        pm = &(*pm)->next;
> -    m->next = NULL;
> -    *pm = m;
> +    QTAILQ_INSERT_TAIL(&machine_types, m, next);
>  }
>  
>  static QEMUMachine *machine_find(const char *name)
>  {
>      QEMUMachine *m;
>  
> -    for(m = first_machine; m != NULL; m = m->next) {
> +    QTAILQ_FOREACH(m, &machine_types, next) {
>          if (!strcmp(m->name, name))
>              return m;
>          if (m->alias && !strcmp(m->alias, name))
> @@ -1190,7 +1186,7 @@ QEMUMachine *machine_find_default(void)
>  {
>      QEMUMachine *m;
>  
> -    for(m = first_machine; m != NULL; m = m->next) {
> +    QTAILQ_FOREACH(m, &machine_types, next) {
>          if (m->is_default) {
>              return m;
>          }
> @@ -1203,7 +1199,7 @@ void machine_print_all(void)
>      QEMUMachine *m;
>  
>      printf("Supported machines are:\n");
> -    for (m = first_machine; m != NULL; m = m->next) {
> +    QTAILQ_FOREACH(m, &machine_types, next) {
>          if (m->alias) {
>              printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
>          }
Luiz Capitulino Feb. 24, 2012, 2:56 p.m. UTC | #2
On Fri, 24 Feb 2012 15:23:43 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Am 24.02.2012 15:13, schrieb Luiz Capitulino:
> > Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> 
> Unless this fixes a bug, I'd rather not refactor this as in my head this
> is already just object_class_foreach() / object_class_by_name(), similar
> to CPUs on my qom-cpu branch.

Is there a plan to convert this to qom anytime soon?

If there isn't, then I'd do the refactoring because the resulting code is
simpler & cleaner.
Andreas Färber Feb. 24, 2012, 3:21 p.m. UTC | #3
Am 24.02.2012 15:56, schrieb Luiz Capitulino:
> On Fri, 24 Feb 2012 15:23:43 +0100
> Andreas Färber <afaerber@suse.de> wrote:
> 
>> Am 24.02.2012 15:13, schrieb Luiz Capitulino:
>>> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
>>
>> Unless this fixes a bug, I'd rather not refactor this as in my head this
>> is already just object_class_foreach() / object_class_by_name(), similar
>> to CPUs on my qom-cpu branch.
> 
> Is there a plan to convert this to qom anytime soon?

I was planning to look into it after CPU is done, if no one beats me.
Since CPU will touch on the machine init functions, doing both in
parallel did not seem like a good idea to me.

I consider both CPU and machine 1.1 material - if we can agree on the
way there, then the code you are changing here will not see a release.
It certainly doesn't hurt to commit it though. :)

Andreas
Luiz Capitulino Feb. 24, 2012, 3:23 p.m. UTC | #4
On Fri, 24 Feb 2012 16:21:56 +0100
Andreas Färber <afaerber@suse.de> wrote:

> Am 24.02.2012 15:56, schrieb Luiz Capitulino:
> > On Fri, 24 Feb 2012 15:23:43 +0100
> > Andreas Färber <afaerber@suse.de> wrote:
> > 
> >> Am 24.02.2012 15:13, schrieb Luiz Capitulino:
> >>> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
> >>
> >> Unless this fixes a bug, I'd rather not refactor this as in my head this
> >> is already just object_class_foreach() / object_class_by_name(), similar
> >> to CPUs on my qom-cpu branch.
> > 
> > Is there a plan to convert this to qom anytime soon?
> 
> I was planning to look into it after CPU is done, if no one beats me.
> Since CPU will touch on the machine init functions, doing both in
> parallel did not seem like a good idea to me.
> 
> I consider both CPU and machine 1.1 material - if we can agree on the
> way there, then the code you are changing here will not see a release.
> It certainly doesn't hurt to commit it though. :)

Well, if you're already planning to do it I can drop the patch then.
diff mbox

Patch

diff --git a/hw/boards.h b/hw/boards.h
index 342a774..1eb8314 100644
--- a/hw/boards.h
+++ b/hw/boards.h
@@ -4,6 +4,7 @@ 
 #define HW_BOARDS_H
 
 #include "qdev.h"
+#include "qemu-queue.h"
 
 typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
                                  const char *boot_device,
@@ -28,7 +29,7 @@  typedef struct QEMUMachine {
     int is_default;
     const char *default_machine_opts;
     GlobalProperty *compat_props;
-    struct QEMUMachine *next;
+    QTAILQ_ENTRY(QEMUMachine) next;
 } QEMUMachine;
 
 void machine_register(QEMUMachine *m);
diff --git a/vl.c b/vl.c
index 9f9927c..4935106 100644
--- a/vl.c
+++ b/vl.c
@@ -1160,24 +1160,20 @@  void pcmcia_info(Monitor *mon)
 /***********************************************************/
 /* machine registration */
 
-static QEMUMachine *first_machine = NULL;
+static QTAILQ_HEAD(QEMUMachineHead, QEMUMachine) machine_types = 
+    QTAILQ_HEAD_INITIALIZER(machine_types);
 QEMUMachine *current_machine = NULL;
 
 void machine_register(QEMUMachine *m)
 {
-    QEMUMachine **pm;
-    pm = &first_machine;
-    while (*pm != NULL)
-        pm = &(*pm)->next;
-    m->next = NULL;
-    *pm = m;
+    QTAILQ_INSERT_TAIL(&machine_types, m, next);
 }
 
 static QEMUMachine *machine_find(const char *name)
 {
     QEMUMachine *m;
 
-    for(m = first_machine; m != NULL; m = m->next) {
+    QTAILQ_FOREACH(m, &machine_types, next) {
         if (!strcmp(m->name, name))
             return m;
         if (m->alias && !strcmp(m->alias, name))
@@ -1190,7 +1186,7 @@  QEMUMachine *machine_find_default(void)
 {
     QEMUMachine *m;
 
-    for(m = first_machine; m != NULL; m = m->next) {
+    QTAILQ_FOREACH(m, &machine_types, next) {
         if (m->is_default) {
             return m;
         }
@@ -1203,7 +1199,7 @@  void machine_print_all(void)
     QEMUMachine *m;
 
     printf("Supported machines are:\n");
-    for (m = first_machine; m != NULL; m = m->next) {
+    QTAILQ_FOREACH(m, &machine_types, next) {
         if (m->alias) {
             printf("%-10s %s (alias of %s)\n", m->alias, m->desc, m->name);
         }