From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu1vb-0008Qj-6e for qemu-devel@nongnu.org; Tue, 02 Jul 2013 10:51:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uu1rc-0002qw-Tz for qemu-devel@nongnu.org; Tue, 02 Jul 2013 10:47:32 -0400 Received: from mail-ye0-f175.google.com ([209.85.213.175]:37800) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uu1rc-0002qN-NN for qemu-devel@nongnu.org; Tue, 02 Jul 2013 10:47:28 -0400 Received: by mail-ye0-f175.google.com with SMTP id q8so1548294yen.20 for ; Tue, 02 Jul 2013 07:47:28 -0700 (PDT) From: Anthony Liguori In-Reply-To: <51D29F27.9040706@siemens.com> References: <51D29F27.9040706@siemens.com> Date: Tue, 02 Jul 2013 09:47:21 -0500 Message-ID: <87bo6lqarq.fsf@codemonkey.ws> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Subject: Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jan Kiszka , Paolo Bonzini Cc: Liu Ping Fan , qemu-devel Jan Kiszka writes: > 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 > --- > 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); > } > } Should we introduce something akin to kref now that referencing counting has gotten fancy? Regards, Anthony Liguori > -- > 1.7.3.4