From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41897) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Utyop-0004mA-Eu for qemu-devel@nongnu.org; Tue, 02 Jul 2013 07:32:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Utyoo-0002vw-Db for qemu-devel@nongnu.org; Tue, 02 Jul 2013 07:32:23 -0400 Received: from cantor2.suse.de ([195.135.220.15]:42192 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UtyYo-0003YA-4P for qemu-devel@nongnu.org; Tue, 02 Jul 2013 07:15:50 -0400 Message-ID: <51D2B661.3030604@suse.de> Date: Tue, 02 Jul 2013 13:15:45 +0200 From: =?ISO-8859-1?Q?Andreas_F=E4rber?= MIME-Version: 1.0 References: <51D29F27.9040706@siemens.com> In-Reply-To: <51D29F27.9040706@siemens.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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 Cc: Paolo Bonzini , Liu Ping Fan , qemu-devel Am 02.07.2013 11:36, schrieb Jan Kiszka: > Objects can soon be referenced/dereference outside the BQL. So we need > to use atomics in object_ref/unref. >=20 > Based on patch by Liu Ping Fan. >=20 > Signed-off-by: Jan Kiszka > --- > qom/object.c | 5 ++--- > 1 files changed, 2 insertions(+), 3 deletions(-) >=20 > 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 *impleme= nts_type, > =20 > void object_ref(Object *obj) > { > - obj->ref++; > + __sync_fetch_and_add(&obj->ref, 1); How widespread are these in GCC/clang? Is there any fallback? I remember seeing some __sync_* warnings on Mac OS X around 4.2... Andreas > } > =20 > void object_unref(Object *obj) > { > g_assert(obj->ref > 0); > - obj->ref--; > =20 > /* parent always holds a reference to its children */ > - if (obj->ref =3D=3D 0) { > + if (__sync_sub_and_fetch(&obj->ref, 1) =3D=3D 0) { > object_finalize(obj); > } > } --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=F6rffer; HRB 16746 AG N=FCrnbe= rg