@@ -389,7 +389,7 @@ struct Object
ObjectClass *class;
ObjectFree *free;
QTAILQ_HEAD(, ObjectProperty) properties;
- uint32_t ref;
+ Qref ref;
Object *parent;
};
@@ -388,15 +388,15 @@ static void object_deinit(Object *obj, TypeImpl *type)
}
}
-static void object_finalize(void *data)
+static void object_finalize(Qref *qref)
{
- Object *obj = data;
+ Object *obj = container_of(qref, Object, ref);
TypeImpl *ti = obj->class->type;
object_deinit(obj, ti);
object_property_del_all(obj);
- g_assert(obj->ref == 0);
+ g_assert(qref->count == 0);
if (obj->free) {
obj->free(obj);
}
@@ -683,17 +683,12 @@ GSList *object_class_get_list(const char *implements_type,
void object_ref(Object *obj)
{
- atomic_inc(&obj->ref);
+ qref_get(&obj->ref);
}
void object_unref(Object *obj)
{
- g_assert(obj->ref > 0);
-
- /* parent always holds a reference to its children */
- if (atomic_fetch_dec(&obj->ref) == 1) {
- object_finalize(obj);
- }
+ qref_put(&obj->ref, object_finalize);
}
void object_property_add(Object *obj, const char *name, const char *type,
Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com> --- include/qom/object.h | 2 +- qom/object.c | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-)