qom/object.c 'if (type_table == NULL)' statement is redundant , delete it.
PATCH 1/1 qom/object.c 'if (type_table == NULL)' statement is redundant , delete it.
--- qom/object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
qom/object.c +1 -3
@@ -78,9 +78,7 @@ static GHashTable *type_table_get(void) {static GHashTable *type_table; -if (type_table ==NULL ) { - type_table =g_hash_table_new (g_str_hash, g_str_equal); - } + type_table =g_hash_table_new (g_str_hash, g_str_equal);return type_table; }
Signature · 1 line
2.20.1
Hi
Quoted 10 lines · zhuguanghong
Signed-off-by zhuguanghong <[email protected]>--- qom/object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)qom/object.c +0
-0
qom/object.c static GHashTable *type_table_get(void) · line 83
Quoted 9 lines
qom/object.c +1
-3@@ -78,9 +78,7 @@ static GHashTable *type_table_get(void) {static GHashTable *type_table; -if (type_table ==NULL ) { - type_table =g_hash_table_new (g_str_hash, g_str_equal); - } + type_table =g_hash_table_new (g_str_hash, g_str_equal);
nack.It's not redundant, it does a one-time initialization.
We may want to replace it with a more explicit and thread-safe version though:
https://developer.gnome.org/glib/stable/glib-Threads.html#g-once-init-enter
return type_table;
Quoted 8 lines
qom/object.c +0
-1} --2.20.1
Signature · 1 line
Marc-André Lureau
Quoted 26 lines · Marc-André Lureau
Hi
Quoted 10 lines · zhuguanghong
Signed-off-by zhuguanghong <[email protected]>--- qom/object.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)qom/object.c +0
-0qom/object.c static GHashTable *type_table_get(void) · line 83
Quoted 9 lines
qom/object.c +1
-3@@ -78,9 +78,7 @@ static GHashTable *type_table_get(void) {static GHashTable *type_table; -if (type_table ==NULL ) { - type_table =g_hash_table_new (g_str_hash, g_str_equal); - } + type_table =g_hash_table_new (g_str_hash, g_str_equal);nack.It's not redundant, it does a one-time initialization.
Quoted 3 lines
We may want to replace it with a more explicit and thread-safe version though:
https://developer.gnome.org/glib/stable/glib-Threads.html#g-once-init-enter
I would have thought QOM usage is so widespread in QEMU that we'll trigger initialization of this hash tble very early in startup while we're still single threaded.
That said there's not really any harm in using g_once
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Hi
---
qom/object.c | 4 ++++
1 file changed, 4 insertions(+)
qom/object.c +0 -0
@@ -73,15 +73,19 @@ struct TypeImpl
};
static Type type_interface;
+G_LOCK_DEFINE (GHashTable_mutex);
static GHashTable *type_table_get(void)
{
static GHashTable *type_table;
+ G_LOCK ( GHashTable_mutex);
if (type_table == NULL) {
type_table = g_hash_table_new(g_str_hash, g_str_equal); }
+ G_UNLOCK ( GHashTable_mutex); +
return type_table;
}
How about using G_LOCK ? thread safety
------------------ Original ------------------
From: "Daniel P. Berrangé"<[email protected]>;
Date: Wed, Jul 21, 2021 10:00 PM
To: "Marc-André Lureau"<[email protected]>;
Cc: "zhuguanghong"<[email protected]>; "Paolo Bonzini"<[email protected]>; "Eduardo Habkost"<[email protected]>; "QEMU"<[email protected]>;
Subject: Re: [PATCH] qom/object.c 'if (type_table == NULL)' statement is redundant , delete it.
On Wed, Jul 21, 2021 at 05:55:44PM +0400, Marc-André Lureau wrote:
> Hi
>
> On Wed, Jul 21, 2021 at 5:22 PM zhuguanghong <[email protected]>
> wrote:
>
> > Signed-off-by: zhuguanghong <[email protected]>
> > ---
> > qom/object.c | 4 +---
> > 1 file changed, 1 insertion(+), 3 deletions(-)
> >
> > diff --git a/qom/object.c b/qom/object.c
> > index 6a01d56546..c8f5481afe 100644
> > --- a/qom/object.c
> > +++ b/qom/object.c
> > @@ -78,9 +78,7 @@ static GHashTable *type_table_get(void)
> > {
> > static GHashTable *type_table;
> >
> > - if (type_table == NULL) {
> > - type_table = g_hash_table_new(g_str_hash, g_str_equal); > > - }
> > + type_table = g_hash_table_new(g_str_hash, g_str_equal);
> >
> >
> nack.It's not redundant, it does a one-time initialization.
>
> We may want to replace it with a more explicit and thread-safe version
> though:
> https://developer.gnome.org/glib/stable/glib-Threads.html#g-once-init-enter
I would have thought QOM usage is so widespread in QEMU that we'll trigger initialization of this hash tble very early in startup while we're still single threaded.
That said there's not really any harm in using g_once
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 32 lines · 朱光宏
Hi
Signed-off-by zhuguanghong <[email protected]>---
qom/object.c | 4 ++++
1 file changed, 4 insertions(+)qom/object.c +4
-0@@ -73,15 +73,19 @@ struct TypeImpl }; static Type type_interface; +G_LOCK_DEFINE (GHashTable_mutex); static GHashTable *type_table_get (void ) { static GHashTable *type_table; + G_LOCK ( GHashTable_mutex); if (type_table ==NULL ) { type_table =g_hash_table_new (g_str_hash, g_str_equal); } + G_UNLOCK ( GHashTable_mutex); +
Quoted 2 lines
return
type_table;
}
Please could you check your mail client settings so that it correctly sends *plain* text messages. This is a multipart text/plain+text/html message, but the text/plain part is full of HTML entities. This makes your messages almost impossible to read and reply to.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|