From patchwork Sun Nov 25 02:02:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 201504 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 9661A2C008E for ; Sun, 25 Nov 2012 13:03:57 +1100 (EST) Received: from localhost ([::1]:55920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TcRZb-0007mG-Oa for incoming@patchwork.ozlabs.org; Sat, 24 Nov 2012 21:03:55 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TcRZU-0007mA-R0 for qemu-devel@nongnu.org; Sat, 24 Nov 2012 21:03:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TcRZT-0004IT-S1 for qemu-devel@nongnu.org; Sat, 24 Nov 2012 21:03:48 -0500 Received: from mail-pb0-f45.google.com ([209.85.160.45]:58503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TcRZT-0004IM-Lm for qemu-devel@nongnu.org; Sat, 24 Nov 2012 21:03:47 -0500 Received: by mail-pb0-f45.google.com with SMTP id mc8so6901952pbc.4 for ; Sat, 24 Nov 2012 18:03:46 -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=Y2dC/AQ8I5c/FPHgmehSIKkI3ezx7aY6dyIFuDfVTqE=; b=q4HQXdfuAgvxOtvxzWyQFtaiDcY8JimJe4wf0g+rb81lMwSppxqRrW7VH6sfpn2Y7b aMuX8ESyjkWT4+ZfC2rcH2Zz5X9JZbMOng/unRXA762JL713PrcfDtfk+ILmODneQtJe NjgvYZEnbMfRj7KwInQxqThwr6cZISwG/p3AJOz+Ias2lrN0OeG6OipSCht1i6ZwPBWG t9ukrM3mUf+BnWI1Xw/N2FkwIUtQtD6DLKu/fNiX36t4opJUOXQH4nOc9iFdDr/W3L/b 5jvu1qj6Rw+SbiLsypGb7WrAJir+ibY/jwUmsJxUGy4S8Y3NXL/iHrg49U7XTIhbLUNF cUxQ== Received: by 10.66.88.130 with SMTP id bg2mr11655871pab.39.1353809026747; Sat, 24 Nov 2012 18:03:46 -0800 (PST) Received: from localhost ([222.128.159.174]) by mx.google.com with ESMTPS id m7sm6230377paz.3.2012.11.24.18.03.31 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 24 Nov 2012 18:03:45 -0800 (PST) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Sun, 25 Nov 2012 10:02:58 +0800 Message-Id: <1353808984-22368-2-git-send-email-qemulist@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1353808984-22368-1-git-send-email-qemulist@gmail.com> References: <1353808984-22368-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.160.45 Cc: Peter Maydell , gleb@redhat.com, Jan Kiszka , Marcelo Tosatti , Anthony Liguori , Stefan Hajnoczi , Paolo Bonzini Subject: [Qemu-devel] [PATCH v7 1/7] 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 --- qom/object.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index e3e9242..1a697b3 100644 --- a/qom/object.c +++ b/qom/object.c @@ -600,16 +600,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_fetch_and_sub(&obj->ref, 1) == 1) { object_finalize(obj); } }