diff mbox series

[for-3.2,v3,08/14] qdev-props: convert global_props to GArray

Message ID 20181107123652.23417-9-marcandre.lureau@redhat.com
State New
Headers show
Series Generalize machine compatibility properties | expand

Commit Message

Marc-André Lureau Nov. 7, 2018, 12:36 p.m. UTC
A step towards being able to call object_apply_global_props().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

Comments

Igor Mammedov Nov. 23, 2018, 2:26 p.m. UTC | #1
On Wed,  7 Nov 2018 16:36:46 +0400
Marc-André Lureau <marcandre.lureau@redhat.com> wrote:

> A step towards being able to call object_apply_global_props().
it also makes code more uniform as we don't have to deal with type
inform of GList.

maybe move it at the beginning of series and include accel part as well?

otherwise looks good



> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  hw/core/qdev-properties.c | 29 ++++++++++++++++++++---------
>  1 file changed, 20 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 43c30a57f4..353e67c05a 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -1173,22 +1173,32 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
>      *ptr = value;
>  }
>  
> -static GList *global_props;
> +static GArray *global_props(void)
> +{
> +    static GArray *gp;
> +
> +    if (!gp) {
> +        gp = g_array_new(false, false, sizeof(GlobalProperty *));
> +    }
> +
> +    return gp;
> +}
>  
>  void qdev_prop_register_global(GlobalProperty *prop)
>  {
> -    global_props = g_list_append(global_props, prop);
> +    g_array_append_val(global_props(), prop);
>  }
>  
>  int qdev_prop_check_globals(void)
>  {
> -    GList *l;
> -    int ret = 0;
> +    int i, ret = 0;
>  
> -    for (l = global_props; l; l = l->next) {
> -        GlobalProperty *prop = l->data;
> +    for (i = 0; i < global_props()->len; i++) {
> +        GlobalProperty *prop;
>          ObjectClass *oc;
>          DeviceClass *dc;
> +
> +        prop = g_array_index(global_props(), GlobalProperty *, i);
>          if (prop->used) {
>              continue;
>          }
> @@ -1213,12 +1223,13 @@ int qdev_prop_check_globals(void)
>  
>  void qdev_prop_set_globals(DeviceState *dev)
>  {
> -    GList *l;
> +    int i;
>  
> -    for (l = global_props; l; l = l->next) {
> -        GlobalProperty *prop = l->data;
> +    for (i = 0; i < global_props()->len; i++) {
> +        GlobalProperty *prop;
>          Error *err = NULL;
>  
> +        prop = g_array_index(global_props(), GlobalProperty *, i);
>          if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
>              continue;
>          }
diff mbox series

Patch

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 43c30a57f4..353e67c05a 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1173,22 +1173,32 @@  void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
     *ptr = value;
 }
 
-static GList *global_props;
+static GArray *global_props(void)
+{
+    static GArray *gp;
+
+    if (!gp) {
+        gp = g_array_new(false, false, sizeof(GlobalProperty *));
+    }
+
+    return gp;
+}
 
 void qdev_prop_register_global(GlobalProperty *prop)
 {
-    global_props = g_list_append(global_props, prop);
+    g_array_append_val(global_props(), prop);
 }
 
 int qdev_prop_check_globals(void)
 {
-    GList *l;
-    int ret = 0;
+    int i, ret = 0;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         ObjectClass *oc;
         DeviceClass *dc;
+
+        prop = g_array_index(global_props(), GlobalProperty *, i);
         if (prop->used) {
             continue;
         }
@@ -1213,12 +1223,13 @@  int qdev_prop_check_globals(void)
 
 void qdev_prop_set_globals(DeviceState *dev)
 {
-    GList *l;
+    int i;
 
-    for (l = global_props; l; l = l->next) {
-        GlobalProperty *prop = l->data;
+    for (i = 0; i < global_props()->len; i++) {
+        GlobalProperty *prop;
         Error *err = NULL;
 
+        prop = g_array_index(global_props(), GlobalProperty *, i);
         if (object_dynamic_cast(OBJECT(dev), prop->driver) == NULL) {
             continue;
         }