From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uyx3H-0002nE-5f for qemu-devel@nongnu.org; Tue, 16 Jul 2013 00:39:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uyx3G-0001ky-A6 for qemu-devel@nongnu.org; Tue, 16 Jul 2013 00:39:51 -0400 Received: from mail-ie0-x236.google.com ([2607:f8b0:4001:c03::236]:39533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uyx3G-0001ku-5u for qemu-devel@nongnu.org; Tue, 16 Jul 2013 00:39:50 -0400 Received: by mail-ie0-f182.google.com with SMTP id s9so618115iec.27 for ; Mon, 15 Jul 2013 21:39:49 -0700 (PDT) From: Liu Ping Fan Date: Tue, 16 Jul 2013 12:36:30 +0800 Message-Id: <1373949390-3642-2-git-send-email-pingfank@linux.vnet.ibm.com> In-Reply-To: <1373949390-3642-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1373949390-3642-1-git-send-email-pingfank@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 2/2] object: Object apply the refcnt interface by Qref List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Richard Henderson Signed-off-by: Liu Ping Fan --- 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 #include #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