[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [patch v4 02/16] qom: apply atomic on object's refcount
From: |
Liu Ping Fan |
Subject: |
[Qemu-devel] [patch v4 02/16] qom: apply atomic on object's refcount |
Date: |
Mon, 22 Oct 2012 17:23:45 +0800 |
Signed-off-by: Liu Ping Fan <address@hidden>
---
include/qemu/object.h | 3 ++-
qom/object.c | 11 +++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/qemu/object.h b/include/qemu/object.h
index cc75fee..0c02614 100644
--- a/include/qemu/object.h
+++ b/include/qemu/object.h
@@ -18,6 +18,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "qemu-queue.h"
+#include "qemu/atomic.h"
struct Visitor;
struct Error;
@@ -262,7 +263,7 @@ struct Object
/*< private >*/
ObjectClass *class;
QTAILQ_HEAD(, ObjectProperty) properties;
- uint32_t ref;
+ Atomic ref;
Object *parent;
};
diff --git a/qom/object.c b/qom/object.c
index e3e9242..34ec2a1 100644
--- a/qom/object.c
+++ b/qom/object.c
@@ -383,7 +383,7 @@ void object_finalize(void *data)
object_deinit(obj, ti);
object_property_del_all(obj);
- g_assert(obj->ref == 0);
+ g_assert(atomic_read(&obj->ref) == 0);
}
Object *object_new_with_type(Type type)
@@ -410,7 +410,7 @@ Object *object_new(const char *typename)
void object_delete(Object *obj)
{
object_unparent(obj);
- g_assert(obj->ref == 1);
+ g_assert(atomic_read(&obj->ref) == 1);
object_unref(obj);
g_free(obj);
}
@@ -600,16 +600,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--;
+ g_assert(atomic_read(&obj->ref) > 0);
/* parent always holds a reference to its children */
- if (obj->ref == 0) {
+ if (atomic_return_and_sub(1, &obj->ref) == 1) {
object_finalize(obj);
}
}
--
1.7.4.4
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, (continued)
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, Avi Kivity, 2012/10/25
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, liu ping fan, 2012/10/25
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, liu ping fan, 2012/10/25
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, Jan Kiszka, 2012/10/26
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, liu ping fan, 2012/10/29
- Re: [Qemu-devel] [patch v4 13/16] e1000: add busy flag to anti broken device state, Peter Maydell, 2012/10/29
[Qemu-devel] [patch v4 11/16] vcpu: push mmio dispatcher out of big lock, Liu Ping Fan, 2012/10/22
[Qemu-devel] [patch v4 15/16] e1000: introduce unmap() to fix unplug issue, Liu Ping Fan, 2012/10/22
[Qemu-devel] [patch v4 02/16] qom: apply atomic on object's refcount,
Liu Ping Fan <=
[Qemu-devel] [patch v4 16/16] e1000: implement MemoryRegionOps's ref&lock interface, Liu Ping Fan, 2012/10/22
Re: [Qemu-devel] [patch v4 00/16] push mmio dispatch out of big lock, Peter Maydell, 2012/10/25
Re: [Qemu-devel] [patch v4 00/16] push mmio dispatch out of big lock, Avi Kivity, 2012/10/29