[gupnp] service: Convert GUPnPServiceAction to g_atomic_rc_box
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gupnp] service: Convert GUPnPServiceAction to g_atomic_rc_box
- Date: Tue, 28 May 2019 20:54:56 +0000 (UTC)
commit bc4a1a6cfed928e7175001bf017d8edf10051962
Author: Jens Georg <mail jensge org>
Date: Tue May 28 22:34:16 2019 +0200
service: Convert GUPnPServiceAction to g_atomic_rc_box
Also move the struct definition into private header to re-use in tests
libgupnp/gupnp-service-private.h | 41 +++++++++++++++++++++++++++++++
libgupnp/gupnp-service.c | 52 ++++++++++++++++------------------------
tests/gtest/test-bugs.c | 21 +---------------
3 files changed, 62 insertions(+), 52 deletions(-)
---
diff --git a/libgupnp/gupnp-service-private.h b/libgupnp/gupnp-service-private.h
new file mode 100644
index 0000000..58287c5
--- /dev/null
+++ b/libgupnp/gupnp-service-private.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2019 Jens Georg.
+ *
+ * Author: Jens Georg <mail jensge org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GUPNP_SERVICE_PRIVATE_H
+#define GUPNP_SERVICE_PRIVATE_H
+
+struct _GUPnPServiceAction {
+ GUPnPContext *context;
+
+ char *name;
+
+ SoupMessage *msg;
+ gboolean accept_gzip;
+
+ GUPnPXMLDoc *doc;
+ xmlNode *node;
+
+ GString *response_str;
+
+ guint argument_count;
+};
+
+#endif
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index db04ae6..ce25ca5 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -38,6 +38,7 @@
#include "gupnp-error.h"
#include "gupnp-acl.h"
#include "gupnp-uuid.h"
+#include "gupnp-service-private.h"
#include "http-headers.h"
#include "gena-protocol.h"
#include "xml-util.h"
@@ -95,6 +96,9 @@ notify_subscriber (gpointer key,
gpointer value,
gpointer user_data);
+GUPnPServiceAction *
+gupnp_service_action_new ();
+
GUPnPServiceAction *
gupnp_service_action_ref (GUPnPServiceAction *action);
@@ -210,49 +214,35 @@ notify_data_free (NotifyData *data)
g_slice_free (NotifyData, data);
}
-struct _GUPnPServiceAction {
- volatile gint ref_count;
-
- GUPnPContext *context;
-
- char *name;
-
- SoupMessage *msg;
- gboolean accept_gzip;
-
- GUPnPXMLDoc *doc;
- xmlNode *node;
-
- GString *response_str;
-
- guint argument_count;
-};
+GUPnPServiceAction *
+gupnp_service_action_new ()
+{
+ return g_atomic_rc_box_new0 (GUPnPServiceAction);
+}
GUPnPServiceAction *
gupnp_service_action_ref (GUPnPServiceAction *action)
{
g_return_val_if_fail (action, NULL);
- g_return_val_if_fail (action->ref_count > 0, NULL);
- g_atomic_int_inc (&action->ref_count);
+ return g_atomic_rc_box_acquire (action);
+}
- return action;
+static void
+action_dispose (GUPnPServiceAction *action)
+{
+ g_free (action->name);
+ g_object_unref (action->msg);
+ g_object_unref (action->context);
+ g_object_unref (action->doc);
}
void
gupnp_service_action_unref (GUPnPServiceAction *action)
{
g_return_if_fail (action);
- g_return_if_fail (action->ref_count > 0);
-
- if (g_atomic_int_dec_and_test (&action->ref_count)) {
- g_free (action->name);
- g_object_unref (action->msg);
- g_object_unref (action->context);
- g_object_unref (action->doc);
- g_slice_free (GUPnPServiceAction, action);
- }
+ g_atomic_rc_box_release_full (action, (GDestroyNotify) action_dispose);
}
/**
@@ -1012,9 +1002,7 @@ control_server_handler (SoupServer *server,
}
/* Create action structure */
- action = g_slice_new0 (GUPnPServiceAction);
-
- action->ref_count = 1;
+ action = gupnp_service_action_new ();
action->name = g_strdup (action_name);
action->msg = g_object_ref (msg);
action->doc = gupnp_xml_doc_new(doc);
diff --git a/tests/gtest/test-bugs.c b/tests/gtest/test-bugs.c
index 54343ef..76d35d6 100644
--- a/tests/gtest/test-bugs.c
+++ b/tests/gtest/test-bugs.c
@@ -24,26 +24,7 @@
#endif
#include <libgupnp/gupnp.h>
-
-
-struct _GUPnPServiceAction {
- volatile gint ref_count;
-
- GUPnPContext *context;
-
- char *name;
-
- SoupMessage *msg;
- gboolean accept_gzip;
-
- GUPnPXMLDoc *doc;
- xmlNode *node;
-
- GString *response_str;
-
- guint argument_count;
-};
-
+#include <libgupnp/gupnp-service-private.h>
typedef struct _TestBgo678701Service {
GUPnPServiceProxy parent_instance;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]