[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting
From: |
Anthony Liguori |
Subject: |
Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting |
Date: |
Tue, 02 Jul 2013 09:47:21 -0500 |
User-agent: |
Notmuch/0.15.2+77~g661dcf8 (http://notmuchmail.org) Emacs/23.3.1 (x86_64-pc-linux-gnu) |
Jan Kiszka <address@hidden> 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 <address@hidden>
> ---
> 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
Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting,
Anthony Liguori <=
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, Paolo Bonzini, 2013/07/02
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, Anthony Liguori, 2013/07/02
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, liu ping fan, 2013/07/02
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, Andreas Färber, 2013/07/03
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, liu ping fan, 2013/07/04
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, Andreas Färber, 2013/07/04
- Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, liu ping fan, 2013/07/04
Re: [Qemu-devel] [PATCH] qom: Use atomics for object refcounting, Paolo Bonzini, 2013/07/04