qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Liu Ping Fan <qemulist@gmail.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH v2 2/2] object: Object apply the refcnt interface by Qref
Date: Tue, 16 Jul 2013 12:36:30 +0800	[thread overview]
Message-ID: <1373949390-3642-2-git-send-email-pingfank@linux.vnet.ibm.com> (raw)
In-Reply-To: <1373949390-3642-1-git-send-email-pingfank@linux.vnet.ibm.com>

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 include/qom/object.h |  3 ++-
 qom/object.c         | 15 +++++----------
 2 files changed, 7 insertions(+), 11 deletions(-)

diff --git a/include/qom/object.h b/include/qom/object.h
index 23fc048..6331972 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -18,6 +18,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include "qemu/queue.h"
+#include "qemu/refcnt.h"
 
 struct Visitor;
 struct Error;
@@ -384,7 +385,7 @@ struct Object
     ObjectClass *class;
     ObjectFree *free;
     QTAILQ_HEAD(, ObjectProperty) properties;
-    uint32_t ref;
+    Qref ref;
     Object *parent;
 };
 
diff --git a/qom/object.c b/qom/object.c
index b2479d1..e7e5c26 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -388,15 +388,15 @@ static void object_deinit(Object *obj, TypeImpl *type)
     }
 }
 
-static void object_finalize(void *data)
+static void object_finalize(Qref *qref)
 {
-    Object *obj = data;
+    Object *obj = container_of(qref, Object, ref);
     TypeImpl *ti = obj->class->type;
 
     object_deinit(obj, ti);
     object_property_del_all(obj);
 
-    g_assert(obj->ref == 0);
+    g_assert(qref->count == 0);
     if (obj->free) {
         obj->free(obj);
     }
@@ -683,17 +683,12 @@ GSList *object_class_get_list(const char *implements_type,
 
 void object_ref(Object *obj)
 {
-     atomic_inc(&obj->ref);
+     qref_inc(&obj->ref);
 }
 
 void object_unref(Object *obj)
 {
-    g_assert(obj->ref > 0);
-
-    /* parent always holds a reference to its children */
-    if (atomic_fetch_dec(&obj->ref) == 1) {
-        object_finalize(obj);
-    }
+    qref_dec(&obj->ref, object_finalize);
 }
 
 void object_property_add(Object *obj, const char *name, const char *type,
-- 
1.8.1.4

      reply	other threads:[~2013-07-16  4:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-16  4:36 [Qemu-devel] [PATCH v2 1/2] refcnt: introduce Qref to abstract the refcnt interface Liu Ping Fan
2013-07-16  4:36 ` Liu Ping Fan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373949390-3642-2-git-send-email-pingfank@linux.vnet.ibm.com \
    --to=qemulist@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).