[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 03/13] qom: add support for weak referenced obje
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH 03/13] qom: add support for weak referenced object: aka UnownedObject |
Date: |
Wed, 28 Jan 2015 11:09:22 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
On 28/01/2015 11:03, Igor Mammedov wrote:
> it adds support for weak reference model used by glib's
> GInitiallyUnowned to QEMU's QOM model.
>
> Signed-off-by: Igor Mammedov <address@hidden>
> ---
> include/qom/object.h | 20 ++++++++++++++++++++
> qom/object.c | 20 +++++++++++++++++++-
> 2 files changed, 39 insertions(+), 1 deletion(-)
>
> diff --git a/include/qom/object.h b/include/qom/object.h
> index 89c3092..e0e4cc8 100644
> --- a/include/qom/object.h
> +++ b/include/qom/object.h
> @@ -1314,5 +1314,25 @@ int object_child_foreach(Object *obj, int (*fn)(Object
> *child, void *opaque),
> */
> Object *container_get(Object *root, const char *path);
>
> +#define TYPE_UNOWNED_OBJECT "unowned-object"
> +#define UNOWNED_OBJECT(obj) \
> + OBJECT_CHECK(UnownedObject, (obj), TYPE_UNOWNED_OBJECT)
> +#define UNOWNED_OBJECT_CLASS(klass) \
> + OBJECT_CLASS_CHECK(UnownedObjectClass, (klass), TYPE_UNOWNED_OBJECT)
> +#define UNOWNED_OBJECT_GET_CLASS \
> + OBJECT_GET_CLASS(UnownedObjectClass, (obj), TYPE_UNOWNED_OBJECT)
> +#define OBJECT_WEAK_REF (1UL << 31)
> +
> +typedef struct UnownedObjectClass
> +{
> + /*< private >*/
> + ObjectClass parent_class;
> +} UnownedObjectClass;
> +
> +typedef struct UnownedObject
> +{
> + /*< private >*/
> + Object parent_obj;
> +} UnownedObject;
>
> #endif
> diff --git a/qom/object.c b/qom/object.c
> index 1812c73..96842c7 100644
> --- a/qom/object.c
> +++ b/qom/object.c
> @@ -705,6 +705,10 @@ void object_ref(Object *obj)
> if (!obj) {
> return;
> }
> + if (atomic_fetch_and(&obj->ref, ~OBJECT_WEAK_REF) & OBJECT_WEAK_REF)
Please first do a non-atomic test, since this is unlikely to happen but
atomic_fetch_and is quite expensive (it compiles into a cmpxchg loop).
Paolo
> + {
> + return;
> + }
> atomic_inc(&obj->ref);
> }
>
> @@ -713,7 +717,7 @@ void object_unref(Object *obj)
> if (!obj) {
> return;
> }
> - g_assert(obj->ref > 0);
> + g_assert((obj->ref & ~OBJECT_WEAK_REF) > 0);
>
> /* parent always holds a reference to its children */
> if (atomic_fetch_dec(&obj->ref) == 1) {
> @@ -1709,6 +1713,12 @@ static void object_instance_init(Object *obj)
> object_property_add_str(obj, "type", qdev_get_type, NULL, NULL);
> }
>
> +
> +static void unowned_object_instance_init(Object *obj)
> +{
> + obj->ref |= OBJECT_WEAK_REF;
> +}
> +
> static void register_types(void)
> {
> static TypeInfo interface_info = {
> @@ -1724,8 +1734,16 @@ static void register_types(void)
> .abstract = true,
> };
>
> + static TypeInfo unowned_object_info = {
> + .name = TYPE_UNOWNED_OBJECT,
> + .instance_size = sizeof(UnownedObject),
> + .instance_init = unowned_object_instance_init,
> + .abstract = true,
> + };
> +
> type_interface = type_register_internal(&interface_info);
> type_register_internal(&object_info);
> + type_register_internal(&unowned_object_info);
> }
>
> type_init(register_types)
>
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), (continued)
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), Michael S. Tsirkin, 2015/01/26
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), Igor Mammedov, 2015/01/26
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), Andrew Jones, 2015/01/26
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), Michael S. Tsirkin, 2015/01/26
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), Igor Mammedov, 2015/01/27
- Re: [Qemu-devel] [PATCH v2 01/47] acpi: introduce AML composer aml_append(), Michael S. Tsirkin, 2015/01/28
- [Qemu-devel] [PATCH 00/13] convert AML API to QOM, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 02/13] make toplevel ACPI tables blob a pointer, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 04/13] acpi: make AcpiAml an OQM object, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 03/13] qom: add support for weak referenced object: aka UnownedObject, Igor Mammedov, 2015/01/28
- Re: [Qemu-devel] [PATCH 03/13] qom: add support for weak referenced object: aka UnownedObject,
Paolo Bonzini <=
- Re: [Qemu-devel] [PATCH 03/13] qom: add support for weak referenced object: aka UnownedObject, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 05/13] acpi: use TYPE_AML_OBJECT inside of AML API, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 09/13] acpi: add aml_blob() helper, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 08/13] i386: acpi: hack not yet converted tables calls to deal with table_data being a pointer, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 01/13] convert to passing AcpiAml by pointers, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 10/13] i386: acpi: add DSDT table using AML API, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 07/13] acpi: make toplevel ACPI tables blob a dedicated object, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 11/13] acpi: acpi_add_table() to common cross target file, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 12/13] acpi: prepare for API internal collection of RSDT entries, Igor Mammedov, 2015/01/28
- [Qemu-devel] [PATCH 13/13] i386: acpi: mark SSDT as RSDT entry so API would add entry to RSDT automatically, Igor Mammedov, 2015/01/28