[libsoup/carlosgc/clean-refcounted: 2/4] Use ArcBox for reference counted boxed types
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/clean-refcounted: 2/4] Use ArcBox for reference counted boxed types
- Date: Fri, 26 Mar 2021 08:51:38 +0000 (UTC)
commit b425e09b83fe915b094424c64661178ce78ce087
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed Mar 24 10:49:02 2021 +0100
Use ArcBox for reference counted boxed types
libsoup/server/soup-message-body.c | 15 +++------------
libsoup/soup-message-headers.c | 25 ++++++++++++-------------
libsoup/soup-socket-properties.c | 24 ++++++++++++------------
libsoup/soup-socket-properties.h | 3 ---
4 files changed, 27 insertions(+), 40 deletions(-)
---
diff --git a/libsoup/server/soup-message-body.c b/libsoup/server/soup-message-body.c
index b2f06587..28ef1bf3 100644
--- a/libsoup/server/soup-message-body.c
+++ b/libsoup/server/soup-message-body.c
@@ -62,7 +62,6 @@ typedef struct {
GBytes *flattened;
gboolean accumulate;
goffset base_offset;
- gatomicrefcount ref_count;
} SoupMessageBodyPrivate;
/**
@@ -78,9 +77,8 @@ soup_message_body_new (void)
{
SoupMessageBodyPrivate *priv;
- priv = g_slice_new0 (SoupMessageBodyPrivate);
+ priv = g_atomic_rc_box_new0 (SoupMessageBodyPrivate);
priv->accumulate = TRUE;
- g_atomic_ref_count_init (&priv->ref_count);
return (SoupMessageBody *)priv;
}
@@ -392,9 +390,8 @@ soup_message_body_wrote_chunk (SoupMessageBody *body, GBytes *chunk)
static SoupMessageBody *
soup_message_body_copy (SoupMessageBody *body)
{
- SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
+ g_atomic_rc_box_acquire (body);
- g_atomic_ref_count_inc (&priv->ref_count);
return body;
}
@@ -408,13 +405,7 @@ soup_message_body_copy (SoupMessageBody *body)
void
soup_message_body_free (SoupMessageBody *body)
{
- SoupMessageBodyPrivate *priv = (SoupMessageBodyPrivate *)body;
-
- if (!g_atomic_ref_count_dec (&priv->ref_count))
- return;
-
- soup_message_body_truncate (body);
- g_slice_free (SoupMessageBodyPrivate, priv);
+ g_atomic_rc_box_release_full (body, (GDestroyNotify)soup_message_body_truncate);
}
G_DEFINE_BOXED_TYPE (SoupMessageBody, soup_message_body, soup_message_body_copy, soup_message_body_free)
diff --git a/libsoup/soup-message-headers.c b/libsoup/soup-message-headers.c
index 3651ce7a..81d53b8f 100644
--- a/libsoup/soup-message-headers.c
+++ b/libsoup/soup-message-headers.c
@@ -58,8 +58,6 @@ struct _SoupMessageHeaders {
goffset content_length;
SoupExpectation expectations;
char *content_type;
-
- gatomicrefcount ref_count;
};
/**
@@ -77,24 +75,31 @@ soup_message_headers_new (SoupMessageHeadersType type)
{
SoupMessageHeaders *hdrs;
- hdrs = g_slice_new0 (SoupMessageHeaders);
+ hdrs = g_atomic_rc_box_new0 (SoupMessageHeaders);
/* FIXME: is "5" a good default? */
hdrs->array = g_array_sized_new (TRUE, FALSE, sizeof (SoupHeader), 5);
hdrs->type = type;
hdrs->encoding = -1;
- g_atomic_ref_count_init (&hdrs->ref_count);
-
return hdrs;
}
static SoupMessageHeaders *
soup_message_headers_copy (SoupMessageHeaders *hdrs)
{
- g_atomic_ref_count_inc (&hdrs->ref_count);
+ g_atomic_rc_box_acquire (hdrs);
+
return hdrs;
}
+static void
+soup_message_headers_destroy (SoupMessageHeaders *hdrs)
+{
+ soup_message_headers_clear (hdrs);
+ g_array_free (hdrs->array, TRUE);
+ g_clear_pointer (&hdrs->concat, g_hash_table_destroy);
+}
+
/**
* soup_message_headers_free:
* @hdrs: a #SoupMessageHeaders
@@ -104,13 +109,7 @@ soup_message_headers_copy (SoupMessageHeaders *hdrs)
void
soup_message_headers_free (SoupMessageHeaders *hdrs)
{
- if (!g_atomic_ref_count_dec (&hdrs->ref_count))
- return;
-
- soup_message_headers_clear (hdrs);
- g_array_free (hdrs->array, TRUE);
- g_clear_pointer (&hdrs->concat, g_hash_table_destroy);
- g_slice_free (SoupMessageHeaders, hdrs);
+ g_atomic_rc_box_release_full (hdrs, (GDestroyNotify)soup_message_headers_destroy);
}
G_DEFINE_BOXED_TYPE (SoupMessageHeaders, soup_message_headers, soup_message_headers_copy,
soup_message_headers_free)
diff --git a/libsoup/soup-socket-properties.c b/libsoup/soup-socket-properties.c
index 3eb8e52b..0b64aaa0 100644
--- a/libsoup/soup-socket-properties.c
+++ b/libsoup/soup-socket-properties.c
@@ -18,9 +18,7 @@ soup_socket_properties_new (GInetSocketAddress *local_addr,
{
SoupSocketProperties *props;
- props = g_slice_new0 (SoupSocketProperties);
-
- g_atomic_ref_count_init (&props->ref_count);
+ props = g_atomic_rc_box_new0 (SoupSocketProperties);
props->proxy_use_default = TRUE;
props->tlsdb_use_default = TRUE;
@@ -37,22 +35,24 @@ soup_socket_properties_new (GInetSocketAddress *local_addr,
SoupSocketProperties *
soup_socket_properties_ref (SoupSocketProperties *props)
{
- g_atomic_ref_count_inc (&props->ref_count);
+ g_atomic_rc_box_acquire (props);
+
return props;
}
-void
-soup_socket_properties_unref (SoupSocketProperties *props)
+static void
+soup_socket_properties_destroy (SoupSocketProperties *props)
{
- if (!g_atomic_ref_count_dec (&props->ref_count))
- return;
-
- g_clear_object (&props->proxy_resolver);
- g_clear_object (&props->local_addr);
+ g_clear_object (&props->proxy_resolver);
+ g_clear_object (&props->local_addr);
g_clear_object (&props->tlsdb);
g_clear_object (&props->tls_interaction);
+}
- g_slice_free (SoupSocketProperties, props);
+void
+soup_socket_properties_unref (SoupSocketProperties *props)
+{
+ g_atomic_rc_box_release_full (props, (GDestroyNotify)soup_socket_properties_destroy);
}
void
diff --git a/libsoup/soup-socket-properties.h b/libsoup/soup-socket-properties.h
index 82847dc7..ef2c0b73 100644
--- a/libsoup/soup-socket-properties.h
+++ b/libsoup/soup-socket-properties.h
@@ -19,9 +19,6 @@ typedef struct {
guint io_timeout;
guint idle_timeout;
-
- /*< private >*/
- gatomicrefcount ref_count;
} SoupSocketProperties;
GType soup_socket_properties_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]