[gupnp-av] xml-util: Make AVXMLDoc a rc_box
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp-av] xml-util: Make AVXMLDoc a rc_box
- Date: Sat, 3 Jul 2021 21:43:13 +0000 (UTC)
commit 7bef1c92bd48cd5009bac82f863dc67c2634329c
Author: Jens Georg <mail jensge org>
Date: Sat Jul 3 23:35:34 2021 +0200
xml-util: Make AVXMLDoc a rc_box
libgupnp-av/xml-util.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
---
diff --git a/libgupnp-av/xml-util.c b/libgupnp-av/xml-util.c
index b2f1a06..ba3b1d1 100644
--- a/libgupnp-av/xml-util.c
+++ b/libgupnp-av/xml-util.c
@@ -51,34 +51,22 @@ av_xml_doc_new (xmlDoc *doc)
g_return_val_if_fail (doc, NULL);
- ret = g_new0 (GUPnPAVXMLDoc, 1);
- ret->refcount = 1;
+ ret = g_rc_box_new0(GUPnPAVXMLDoc);
ret->doc = doc;
return ret;
}
-GUPnPAVXMLDoc *
-av_xml_doc_ref (GUPnPAVXMLDoc *doc)
+static void
+av_xml_doc_free (GUPnPAVXMLDoc *doc)
{
- g_return_val_if_fail (doc, NULL);
- g_return_val_if_fail (doc->refcount > 0, NULL);
- g_atomic_int_inc (&doc->refcount);
-
- return doc;
+ g_clear_pointer (&doc->doc, xmlFreeDoc);
}
void
av_xml_doc_unref (GUPnPAVXMLDoc *doc)
{
- g_return_if_fail (doc);
- g_return_if_fail (doc->refcount > 0);
-
- if (g_atomic_int_dec_and_test (&doc->refcount)) {
- xmlFreeDoc (doc->doc);
- doc->doc = NULL;
- g_free (doc);
- }
+ g_rc_box_release_full (doc, (GFreeFunc) av_xml_doc_free);
}
xmlNode *
@@ -570,4 +558,4 @@ av_xml_util_get_ns (xmlDocPtr doc, GUPnPXMLNamespace ns, xmlNsPtr *ns_out)
return tmp_ns;
}
-G_DEFINE_BOXED_TYPE (GUPnPAVXMLDoc, av_xml_doc, av_xml_doc_ref, av_xml_doc_unref)
+G_DEFINE_BOXED_TYPE (GUPnPAVXMLDoc, av_xml_doc, g_rc_box_acquire, av_xml_doc_unref)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]