Received: from eggs.gnu.org ([2001:4830:134:3::10]:45506) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulGp-0002z9-1t for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:16:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UulGo-00061B-6Y for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:16:31 -0400 Received: from mail-we0-x230.google.com ([2a00:1450:400c:c03::230]:57389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UulGn-000616-Vf for qemu-devel@nongnu.org; Thu, 04 Jul 2013 11:16:30 -0400 Received: by mail-we0-f176.google.com with SMTP id t56so1200692wes.7 for ; Thu, 04 Jul 2013 08:16:29 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 4 Jul 2013 17:13:54 +0200 Message-Id: <1372950842-32422-59-git-send-email-pbonzini@redhat.com> In-Reply-To: <1372950842-32422-1-git-send-email-pbonzini@redhat.com> References: <1372950842-32422-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 58/66] qom: Use atomics for object refcounting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Jan Kiszka , Liu Ping Fan From: Jan Kiszka Object reference counts will soon be changed outside the BQL. So we need to use atomics in object_ref/unref. Based on a patch by Liu Ping Fan. Signed-off-by: Liu Ping Fan Signed-off-by: Jan Kiszka Signed-off-by: Paolo Bonzini --- qom/object.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/qom/object.c b/qom/object.c index 803b94b..cbd7e86 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++; + atomic_inc(&obj->ref); } 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 (atomic_fetch_dec(&obj->ref) == 1) { object_finalize(obj); } } -- 1.8.1.4