qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qom: Use atomics for object refcounting
@ 2013-07-02  9:36 Jan Kiszka
  2013-07-02 11:15 ` Andreas Färber
  2013-07-02 14:47 ` Anthony Liguori
  0 siblings, 2 replies; 16+ messages in thread
From: Jan Kiszka @ 2013-07-02  9:36 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Liu Ping Fan, qemu-devel

Objects can soon be referenced/dereference outside the BQL. So we need
to use atomics in object_ref/unref.

Based on patch by Liu Ping Fan.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
 qom/object.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/qom/object.c b/qom/object.c
index 803b94b..a76a30b 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -683,16 +683,15 @@ GSList *object_class_get_list(const char *implements_type,
 
 void object_ref(Object *obj)
 {
-    obj->ref++;
+     __sync_fetch_and_add(&obj->ref, 1);
 }
 
 void object_unref(Object *obj)
 {
     g_assert(obj->ref > 0);
-    obj->ref--;
 
     /* parent always holds a reference to its children */
-    if (obj->ref == 0) {
+    if (__sync_sub_and_fetch(&obj->ref, 1) == 0) {
         object_finalize(obj);
     }
 }
-- 
1.7.3.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2013-07-04  8:12 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-02  9:36 [Qemu-devel] [PATCH] qom: Use atomics for object refcounting Jan Kiszka
2013-07-02 11:15 ` Andreas Färber
2013-07-02 11:28   ` Paolo Bonzini
2013-07-02 11:44     ` Jan Kiszka
2013-07-02 11:49       ` Paolo Bonzini
2013-07-02 11:52         ` Jan Kiszka
2013-07-02 12:00           ` Paolo Bonzini
2013-07-02 14:47 ` Anthony Liguori
2013-07-02 15:33   ` Paolo Bonzini
2013-07-02 16:36     ` Anthony Liguori
2013-07-03  1:23       ` liu ping fan
2013-07-03 16:36         ` Andreas Färber
2013-07-04  4:46           ` liu ping fan
2013-07-04  5:43             ` Andreas Färber
2013-07-04  7:21               ` liu ping fan
2013-07-04  7:59       ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).