From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:54778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQEFV-0002rY-Eh for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TQEFP-0006hy-DD for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:41 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:51988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQEFO-0006hl-Q0 for qemu-devel@nongnu.org; Mon, 22 Oct 2012 05:24:35 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Oct 2012 14:54:32 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay04.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q9M9OAsi52035824 for ; Mon, 22 Oct 2012 14:54:10 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q9MErxq6027087 for ; Mon, 22 Oct 2012 14:54:01 GMT From: Liu Ping Fan Date: Mon, 22 Oct 2012 17:23:45 +0800 Message-Id: <1350897839-29593-3-git-send-email-pingfank@linux.vnet.ibm.com> In-Reply-To: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1350897839-29593-1-git-send-email-pingfank@linux.vnet.ibm.com> Subject: [Qemu-devel] [patch v4 02/16] qom: apply atomic on object's refcount List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi , Marcelo Tosatti , Avi Kivity , Anthony Liguori , Jan Kiszka , Paolo Bonzini Signed-off-by: Liu Ping Fan --- include/qemu/object.h | 3 ++- qom/object.c | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/qemu/object.h b/include/qemu/object.h index cc75fee..0c02614 100644 --- a/include/qemu/object.h +++ b/include/qemu/object.h @@ -18,6 +18,7 @@ #include #include #include "qemu-queue.h" +#include "qemu/atomic.h" struct Visitor; struct Error; @@ -262,7 +263,7 @@ struct Object /*< private >*/ ObjectClass *class; QTAILQ_HEAD(, ObjectProperty) properties; - uint32_t ref; + Atomic ref; Object *parent; }; diff --git a/qom/object.c b/qom/object.c index e3e9242..34ec2a1 100644 --- a/qom/object.c +++ b/qom/object.c @@ -383,7 +383,7 @@ void object_finalize(void *data) object_deinit(obj, ti); object_property_del_all(obj); - g_assert(obj->ref == 0); + g_assert(atomic_read(&obj->ref) == 0); } Object *object_new_with_type(Type type) @@ -410,7 +410,7 @@ Object *object_new(const char *typename) void object_delete(Object *obj) { object_unparent(obj); - g_assert(obj->ref == 1); + g_assert(atomic_read(&obj->ref) == 1); object_unref(obj); g_free(obj); } @@ -600,16 +600,15 @@ GSList *object_class_get_list(const char *implements_type, void object_ref(Object *obj) { - obj->ref++; + atomic_inc(&obj->ref); } void object_unref(Object *obj) { - g_assert(obj->ref > 0); - obj->ref--; + g_assert(atomic_read(&obj->ref) > 0); /* parent always holds a reference to its children */ - if (obj->ref == 0) { + if (atomic_return_and_sub(1, &obj->ref) == 1) { object_finalize(obj); } } -- 1.7.4.4