From patchwork Tue Jul 2 09:36:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 256307 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5CE8A2C0077 for ; Tue, 2 Jul 2013 19:37:05 +1000 (EST) Received: from localhost ([::1]:55810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utx1C-0000kV-Rz for incoming@patchwork.ozlabs.org; Tue, 02 Jul 2013 05:37:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47815) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utx0w-0000kC-Jo for qemu-devel@nongnu.org; Tue, 02 Jul 2013 05:36:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Utx0u-0007dy-KF for qemu-devel@nongnu.org; Tue, 02 Jul 2013 05:36:46 -0400 Received: from goliath.siemens.de ([192.35.17.28]:19045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utx0u-0007dn-8I for qemu-devel@nongnu.org; Tue, 02 Jul 2013 05:36:44 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id r629ae78019515; Tue, 2 Jul 2013 11:36:40 +0200 Received: from mchn199C.mchp.siemens.de ([146.254.78.26]) by mail1.siemens.de (8.13.6/8.13.6) with SMTP id r629adIX002686; Tue, 2 Jul 2013 11:36:40 +0200 Message-ID: <51D29F27.9040706@siemens.com> Date: Tue, 02 Jul 2013 11:36:39 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Paolo Bonzini X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 192.35.17.28 Cc: Liu Ping Fan , qemu-devel Subject: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting 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 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 Reviewed-by: Paolo Bonzini --- 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); } }