[PATCH] qom/object.c How about using G_LOCK ? thread safety

zhuguanghong posted 1 patch 2 years, 9 months ago
Test checkpatch failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20210722092703.27038-1-zhuguanghong@uniontech.com
Maintainers: Eduardo Habkost <ehabkost@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>
qom/object.c | 4 ++++
1 file changed, 4 insertions(+)
[PATCH] qom/object.c How about using G_LOCK ? thread safety
Posted by zhuguanghong 2 years, 9 months ago
Signed-off-by: zhuguanghong <zhuguanghong@uniontech.com>
---
 qom/object.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/qom/object.c b/qom/object.c
index 6a01d56546..dc0a363ed0 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -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;
 }
 
-- 
2.20.1