From mboxrd@z Thu Jan 1 00:00:00 1970 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) From: Liu Ping Fan Date: Sun, 25 Nov 2012 10:02:58 +0800 Message-Id: <1353808984-22368-2-git-send-email-qemulist@gmail.com> In-Reply-To: <1353808984-22368-1-git-send-email-qemulist@gmail.com> References: <1353808984-22368-1-git-send-email-qemulist@gmail.com> Subject: [Qemu-devel] [PATCH v7 1/7] 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: Peter Maydell , gleb@redhat.com, Jan Kiszka , Marcelo Tosatti , Anthony Liguori , Stefan Hajnoczi , Paolo Bonzini 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); } } -- 1.7.4.4