qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
	Liu Ping Fan <pingfank@linux.vnet.ibm.com>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting
Date: Tue, 02 Jul 2013 11:36:01 -0500	[thread overview]
Message-ID: <8761wsc426.fsf@codemonkey.ws> (raw)
In-Reply-To: <51D2F2D5.90801@redhat.com>

Paolo Bonzini <pbonzini@redhat.com> writes:

> Il 02/07/2013 16:47, Anthony Liguori ha scritto:
>> Jan Kiszka <jan.kiszka@siemens.com> 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 <jan.kiszka@siemens.com>
>>> ---
>>>  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?
>
> I'm not a big fan of kref (it seems _too_ thin a wrapper to me, i.e. it
> doesn't really wrap enough to be useful), but I wouldn't oppose it if
> someone else does it.

I had honestly hoped Object was light enough to be used for this
purpose.  What do you think?

Regards,

Anthony Liguori

>
> Paolo

  reply	other threads:[~2013-07-02 16:36 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-02  9:36 [Qemu-devel] [PATCH] qom: Use atomics for object refcounting Jan Kiszka
2013-07-02 11:15 ` Andreas Färber
2013-07-02 11:28   ` Paolo Bonzini
2013-07-02 11:44     ` Jan Kiszka
2013-07-02 11:49       ` Paolo Bonzini
2013-07-02 11:52         ` Jan Kiszka
2013-07-02 12:00           ` Paolo Bonzini
2013-07-02 14:47 ` Anthony Liguori
2013-07-02 15:33   ` Paolo Bonzini
2013-07-02 16:36     ` Anthony Liguori [this message]
2013-07-03  1:23       ` liu ping fan
2013-07-03 16:36         ` Andreas Färber
2013-07-04  4:46           ` liu ping fan
2013-07-04  5:43             ` Andreas Färber
2013-07-04  7:21               ` liu ping fan
2013-07-04  7:59       ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8761wsc426.fsf@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=jan.kiszka@siemens.com \
    --cc=pbonzini@redhat.com \
    --cc=pingfank@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).