From patchwork Mon Nov 5 05:38:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 197144 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 73D362C0081 for ; Mon, 5 Nov 2012 16:39:23 +1100 (EST) Received: from localhost ([::1]:35810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVFP7-0007QC-Kh for incoming@patchwork.ozlabs.org; Mon, 05 Nov 2012 00:39:21 -0500 Received: from eggs.gnu.org ([208.118.235.92]:46222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVFOv-0007IY-Nc for qemu-devel@nongnu.org; Mon, 05 Nov 2012 00:39:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TVFOu-0005YR-Ms for qemu-devel@nongnu.org; Mon, 05 Nov 2012 00:39:09 -0500 Received: from mail-oa0-f45.google.com ([209.85.219.45]:42256) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TVFOu-0005Xj-HT for qemu-devel@nongnu.org; Mon, 05 Nov 2012 00:39:08 -0500 Received: by mail-oa0-f45.google.com with SMTP id i18so4959766oag.4 for ; Sun, 04 Nov 2012 21:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=eYMp16gBFW9y/dmn5C6LZuZ+nx+UNFSUcOL1cVYfTwY=; b=zuQEmie4UVHb7Po01XpMdoHl38gy72oRNADYVYMMNduOKIo/8EtucpqH3fDXcezkhO wS9lg8H6nM6thEj3ZflnwxKt9YIJxicVGMxcr/eZyYVJU1Qakv8p4AkORlDc8tQnYkRx 4OUzlyorUBPJ2+t3/RgvOn+Ybz+73/3Ery7iCuy4jIh2pCed9cWSmz15HO3eHDDJCTHD lcMh72lmRZwl24riHU9F7UOhJf1WkquGqlQMCreALOZnqsRWH+lmVK2E/FbYef6v4nx1 BUPJgGrzxrPZn/T9JY04ThHjEV9js7lSjykNDs88dj3R+4kDTdt3VJNwDZwVKlkvWW91 ISBw== Received: by 10.182.221.7 with SMTP id qa7mr6990702obc.5.1352093948245; Sun, 04 Nov 2012 21:39:08 -0800 (PST) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPS id q1sm13191384oeh.8.2012.11.04.21.39.06 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 04 Nov 2012 21:39:07 -0800 (PST) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Mon, 5 Nov 2012 13:38:38 +0800 Message-Id: <1352093924-17598-3-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1352093924-17598-1-git-send-email-qemulist@gmail.com> References: <1352093924-17598-1-git-send-email-qemulist@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.219.45 Cc: Peter Maydell , Jan Kiszka , Marcelo Tosatti , Avi Kivity , Anthony Liguori , Stefan Hajnoczi , Paolo Bonzini Subject: [Qemu-devel] [PATCH v6 2/8] qom: apply atomic on object's refcount X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Liu Ping Fan 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); } }